Rank-Ordered Logit的Mlogit - 故障排除

时间:2015-05-20 15:19:51

标签: r mlogit

我正在尝试使用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, 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4, 4, 4, 4, 4, 4, 4, 4, 4, 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无法处理此数据,是否还有其他任何建议?

1 个答案:

答案 0 :(得分:0)

letitburn,

- 确定问题是底层的问题。你现在可能已经发现Stata&#34; rologit&#34;排序数据的例程。它可以处理这些类型的不完整排名。