我在关卡方面遇到了一些问题...运行以下命令:
library(mlogit)
panel.datasm = data.frame(
cbind(
round(runif(100, min=1, max=6)),
rep(1:20,each=5), runif(100, min=0, max=1),
runif(100, min=0, max=6),
runif(100, min=2, max=6) ,
runif(100, min=0, max=1),
runif(100, min=0, max=6),
runif(100, min=2, max=6) ))
names(panel.datasm) = c("choice", "id", "data_1991","data_1992",
"data_1993", "data2_1991", "data2_1992","data2_1993")
logit.data <- mlogit.data(panel.datasm, id = "id", choice = "choice",
varying= 3:5, shape = "wide", sep = "_")
不断收到错误Error in Ops.factor(data[[choice]], alt) : level sets of factors are different
我也尝试过手动分配级别:
panel.datasm$id= factor(
panel.datasm$id,
levels = sort(as.character(unique(panel.datasm$id))) )
我已经尝试了很多事情,但无法弄清楚出了什么问题。为了比较,请看:
data("Electricity", package = "mlogit")
head(Electricity)
Electr <- mlogit.data(Electricity, id = "id", choice = "choice",
varying = 3:26, shape = "wide", sep = "")
据我所知,这与我的数据格式相同。这里发生了什么?我已经走到了尽头。