0

我正在尝试使用 mlogit 包对我的数据运行排序 logit。我让参与者从 24 个选项中选出他们的前三名,然后按偏好顺序对它们进行排名。当我尝试使用 mlogit.data 命令准备数据进行分析时,我不断收到以下错误:

Error in rep(k, Z) : invalid 'times' argument

我想知道这个错误是否与排名关系有关。在 24 个备选方案中,参与者仅排名第 3,其余为空白。从那以后,我用 4s 替换了空白。我的数据如下所示:

head(t)

id ch.1 ch.2 ch.3 ch.4 ch.5 ch.6 ch.7 ch.8 ch.9 ch.10 ch.11 ch.12 ch.13
1    4    4    4    4    4    4    4    4    4     4     4     4     2
2    4    4    4    4    4    2    4    4    4     4     4     3     4
3    4    4    4    4    4    4    4    4    4     4     2     4     4
4    4    4    4    4    4    4    4    1    4     4     4     4     2
5    4    4    4    4    1    4    4    4    4     4     4     4     3
6    3    4    4    4    4    4    4    4    2     4     4     4     4
ch.14 ch.15 ch.16 ch.17 ch.18 ch.19 ch.20 ch.21 ch.22 ch.23 ch.24 
4    4     4     4     1     4     4     4     4     3     4      
4    4     4     4     4     4     4     1     4     4     4      
4    4     4     4     4     4     4     3     4     1     4      
4    4     3     4     4     4     4     4     4     4     4      
4    4     4     4     4     4     4     4     4     2     4      
4    4     4     4     4     4     4     4     4     1     4      
gender condition
0      0
1      0
0      1
1      1 
0      0
1      1

可重现示例的代码:

ch.1 <- c(4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4)
ch.2 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4)
ch.3 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4)
ch.4 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 3, 4, 2)
ch.5 <- c(4, 4, 4, 4, 1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, 4, 4, 
4, 4, 4, 4)
ch.18 <- c(1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 2, 
1, 4, 4, 4)
ch.19 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 
4, 4, 4, 4)
ch.20 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 
4, 1, 4, 4)
ch.21 <- c(4, 1, 3, 4, 4, 4, 4, 1, 4, 4, 1, 2, 3, 4, 4, 1, 4, 1, 4, 4, 
4, 4, 3, 4)
ch.22 <- c(4, 4, 4, 4, 4, 4, 4, 2, 1, 2, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4)
ch.23 <- c(3, 4, 1, 4, 2, 1, 2, 4, 4, 1, 4, 4, 2, 3, 3, 3, 1, 4, 4, 1, 
4, 2, 2, 1)
ch.24 <- c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4)
gender <- sample(c(0,1), 24, replace=T)
condition <- sample(c(0,1), 24, replace=T)
t <- cbind(ch.1, ch.2, ch.3, ch.4, ch.5, ch.6, ch.7, ch.8, ch.9, ch.10, 
ch.11, ch.12, ch.13, ch.14, ch.15, ch.16, ch.17, ch.18, ch.19, ch.20,
ch.21, ch.22, ch.23, ch.24, gender, condition)
t <- as.data.frame(t)
G <- mlogit.data(t, shape="wide", choice="ch", varying=1:24, ranked=TRUE)

Error in rep(k, Z) : invalid 'times' argument

感谢您提供的任何见解,如果 mlogit 无法处理此数据,是否有人有任何其他建议?

4

1 回答 1

0

让它烧,

- 很确定问题是底部的关系。您现在可能已经发现了 Stata 用于排序数据的“rologit”例程。它可以处理这些类型的不完整排名。

于 2016-02-14T06:29:22.173 回答