ChoiceModelR-分层贝叶斯多项式Lo​​git模型 [英] ChoiceModelR - Hierarchical Bayes Multinomial Logit Model

查看:206
本文介绍了ChoiceModelR-分层贝叶斯多项式Lo​​git模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你们中的一些人对Sermas和Colias的R包ChoiceModelR有一定的经验,以估计Hierarchical Bayes多项式Lo​​git模型.实际上,我在R和Hierarchical Bayes上都是新手.但是,我试图通过使用Sermas和Colias在帮助文件中提供的脚本来获得一些估计.我有一个与它们使用的结构相同的数据集(ID,选择集,替代项,自变量和选择变量).我有四个独立变量,所有这些变量均以二进制代码编码为分类变量,没有一个受到限制.我有八个选择集,每个集合中有三个选择,还有一个没有选择的选择作为第四选择.我尝试了以下脚本:

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) 

并收到以下错误消息:

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

此外:有50个或更多警告(使用warnings()查看前50个).提到的警告如下:

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
  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

推荐答案

我知道自从您发布很久以来,这可能无济于事,但是如果将来再次出现,这可能会有用.

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

此数据集将给您带来错误,因为场景和替代变量必须升序,并且它们不能跳过任何值.为了完全重申我的意思,必须按如下顺序重新排列场景和alt变量才能起作用:

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

我经常与ChoiceModelR一起工作,而这正是过去造成我这些错误的原因.如果您有github帐户,如果最终想让其他用户查看一下,也可以在其中发布数据(或修改后的数据).

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.

这篇关于ChoiceModelR-分层贝叶斯多项式Lo​​git模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆