我希望你們中的一些人對Sermas和Colias的R包ChoiceModelR有一定的瞭解,以估計一個Hierarchical Bayes Multinomial Logit Model。目前,我正在分析聯合數據(測試數據)以準備真實數據。數據文件具有所需的形式(UnitID Set Alt X_1 ... X_natts y)是y是離散的。在每個選擇集中,我有3個選擇(alt:1-3)以及一個無選項(alt:4)。獨立變量進行效果編碼(1,0,-1)。據我所知,這些數據是所需的格式。但是,我無法估計係數。如果我運行沒有人口統計變量,我得到以下錯誤的模型:choicemodelr:數據結構錯誤?
Error in Ops.data.frame(data[, 1], ID[i]) :
‘==’ only defined for equally-sized data frames
使用人口統計變量我得到以下幾點:
Error: number of rows in demos does not equal number of units
我沒有找到在互聯網上的錯誤解釋,從而遠遠不知道如何解決這個問題。我想,這是數據文件中一個簡單的錯誤,我沒有看到。我已經嘗試使用不同的編碼,但我得到了相同的錯誤。下面是我的代碼使用方法:
> xcoding=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0)
> mcmc = list(R = 20000, use = 10000)
> options = list(none=FALSE, save=TRUE, keep=1)
> out = choicemodelr(data=robottest_bayes, xcoding, mcmc = mcmc, options = options)
> #with demographic variables
> out = choicemodelr(data=robottest_bayes, demos=robottest_bayes_demo, xcoding, mcmc = mcmc, options = options)
的數據文件如下:
> show(robottest_bayes)
# A tibble: 8,464 × 18
respid ques alt apperance_burly apperance_intelligent apperance_pink features_car features_laundry features_compute
<int> <int> <int> <int> <int> <int> <int> <int> <int>
1 1 1 1 1 0 0 1 0 0
2 1 1 2 0 1 0 0 1 0
3 1 1 3 0 0 1 0 0 1
4 1 1 4 0 0 0 0 0 0
5 1 2 1 0 1 0 0 0 0
6 1 2 2 0 0 1 0 0 0
7 1 2 3 1 0 0 0 0 0
8 1 2 4 0 0 0 0 0 0
9 1 3 1 0 0 1 0 0 0
10 1 3 2 1 0 0 0 0 0
# ... with 8,454 more rows, and 9 more variables: features_dog <int>, features_vaccuum <int>, features_splines <int>,
# brand_botpro <int>, brand_gizmobot <int>, price_10 <int>, price_11 <int>, nochoice <int>, choice <int>
> show(robottest_bayes_demo)
# A tibble: 529 × 3
respid sex age
<int> <int> <int>
1 1 0 42
2 2 0 55
3 3 0 37
4 4 0 35
5 5 1 41
6 6 1 35
7 7 0 56
8 8 0 27
9 9 1 36
10 10 1 42
# ... with 519 more rows
我真的很感激任何樣的建議,並且已經感謝你可能會在答案上花費的時間!
最好成績, 邁克爾