【问题标题】:choicemodelr: error in data structure?Choicemodelr:数据结构错误?
【发布时间】:2017-04-25 09:17:56
【问题描述】:

我希望你们中的一些人对 Sermas 和 Colias 的 R 包 ChoiceModelR 有一些经验,用于估计分层贝叶斯多项 Logit 模型。目前,我正在分析联合数据(测试数据)中的数据,为真实数据做好准备。数据文件具有所需的形式(UnitID Set Alt X_1 ... X_natts y),其中 y 是离散的。在每个选择集中,我有 3 个备选方案(备选方案:1-3)以及一个无选择选项(备选方案:4)。自变量采用效应编码 (1, 0, -1)。据我所知,该数据采用所需的格式。但是,我无法估计系数。如果我在没有人口统计变量的情况下运行模型,我会收到以下错误:

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

我非常感谢您的任何建议,并且已经感谢您花时间回答问题!

最好的, 迈克尔

【问题讨论】:

    标签: r bayesian choice


    【解决方案1】:

    您可以尝试从数据文件中排除没有选择选项的行,并将脚本修改为:

    options = list(none=TRUE, save=TRUE, keep=1)

    由于您有 3 个备选方案,对于受访者选择“无选择选项”的选择集,选择数将为“备选方案数 +1”,即 4。ChoiceModelR 将识别出“无选择选项”被选中。

    根据 p. ChoiceModelR的小插曲5,

    "none:设置为TRUE估计一个none参数,数据不包含 一行“无”(即没有选择)(默认为 FALSE)。”

    试试看是否有效。

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      相关资源
      最近更新 更多