我正在分析联合数据(测试数据)的数据,为真实数据做好准备。
数据文件具有所需的形式(UnitID Set Alt X_1 ... X_natts y),其中 y 是离散的。在每个选择集中,我有 3 个选项(alt:1-3)以及一个无选择选项(alt:4)。自变量采用效果编码 (1, 0, -1)。据我所知,这些数据符合所需的格式。
但是,我无法估计系数。如果我在没有人口统计变量的情况下运行模型,则会收到以下错误:
Ops.data.frame(data[ 1], ID[i]) 中的错误:
‘==’仅针对相同大小的数据帧定义
使用人口统计变量我得到以下信息:
错误:演示中的行数不等于单元数
到目前为止,我在互联网上没有找到错误解释,也不知道如何解决这个问题。我想,这是我没有看到的数据文件中的一个简单错误。我已经尝试使用不同的编码,但遇到了相同的错误。这是我使用的代码:
> 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