ChoiceModelR - Hierarchical Bayes Multinomial Logit Model

匆匆过客 提交于 2019-12-10 11:41:21

问题


I hope that some of you are a bit experienced with the R package ChoiceModelR by Sermas and Colias, to estimate a Hierarchical Bayes Multinomial Logit Model. Actually, I am quite a newbie on both R and Hierarchical Bayes. However, I tried to get some estimates by using the script provided by Sermas and Colias in the help file. I have a data set in the same structure as they use (ID, choice set, alternative, independent variables, and choice variable). I have four independent variables all of them binary coded as categorical variables, none of them restricted. I have eight choice sets with three alternatives within each set as well as one no-choice-option as fourth alternative. I tried the following script:

library (ChoiceModelR)
data <- read.delim("Z:/KLU/CSR/CBC/mp3_vio.txt")   
xcoding=c(0,0,0,0)  
mcmc = list(R = 10, use = 10)  
options = list(none=FALSE, save=TRUE, keep=1)  
attlevels=c(2,2,2,2)  
c1=matrix(c(0,0,0,0),2,2)  
c2=matrix(c(0,0,0,0),2,2)  
c3=matrix(c(0,0,0,0),2,2)  
c4=matrix(c(0,0,0,0),2,2)  
constraints = list(c1, c2, c3, c4)  
out = choicemodelr(data, xcoding, mcmc = mcmc, options = options, constraints = constraints) 

and have got the following error message:

Error in 1:nalts[i] : result would be too long a vector 

In addition: There were 50 or more warnings (use warnings() to see the first 50). The mentioned warnings are of the following:

  1. In max(temp[temp[, 2] == j, 3]) : no non-missing arguments to max; returning -Inf
  2. In max(temp[temp[, 2] == j, 3]) : no non-missing arguments to max; returning -Inf

Actually, I have no idea what went wrong so far as I used the same data structure even I have more independent variables, more choice sets, and more alternatives within a choice set. I would be fantastic if anybody can shed some light into the darkness


回答1:


I know that this may not be helpful since you posted so long ago, but if it comes up again in the future, this could prove useful.

One of the most common reasons for this error (in my experience) has been that either the scenario variable or the alternative variable is not in ascending order within your data.

id    scenario    alt    x1   ...    y
1     1           1      4           1
1     1           2      1           0
1     3           1      4           2
1     3           2      5           0
2     1           4      3           1
2     1           5      1           0
2     2           1      4           2
2     2           2      3           0

This dataset will give you errors since the scenario and alternative variables must be ascending, and they must not skip any values. Just to fully reiterate what I mean, the scenario and alt variables must be reordered as follows in order to work:

id    scenario    alt    x1   ...    y
1     1           1      4           1
1     1           2      1           0
1     2           1      4           2
1     2           2      5           0
2     1           1      3           1
2     1           2      1           0
2     2           1      4           2
2     2           2      3           0

I work with ChoiceModelR quite frequently, and this is what has caused these errors for me in the past. If you have a github account, you can also post your data (or modified data) there if you end up wanting to have other users take a look.



来源:https://stackoverflow.com/questions/17522204/choicemodelr-hierarchical-bayes-multinomial-logit-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!