【发布时间】:2015-06-15 18:15:18
【问题描述】:
我正在为通过 mlogit 进行多项 logit 分析整理我的数据集而度过了一段痛苦的时光。我的数据集可从下面代码中的url 获得。
我收到以下错误:
row.names<-.data.frame(*tmp*, value = c("1.Accessible", "1.Accessible", : 不允许重复的 'row.names'
我在其他地方检查过,似乎出现了这个问题。我尝试使用 alt.levels 而不是 alt.var 参数,但这不起作用。
#Loadpackages
library(RCurl)
library(mlogit)
library(tidyr)
library(dplyr)
#URL where data is stored
dat.url<- 'https://raw.githubusercontent.com/sjkiss/Survey/master/mlogit.out.csv'
#Get data
dat<-read.csv(dat.url)
#Complete cases only as it seems mlogit cannot handle missing values or tied data which in this case you might get because of median imputation
dat<-dat[complete.cases(dat),]
#Tidy data to get it into long format
dat.out<-dat %>%
gather(Open, Rank, -c(1,9:12))
#Try to replicate code on pp.26-27 of http://cran.r- project.org/web/packages/mlogit/vignettes/mlogit.pdf
mlogit.out<-mlogit.data(dat.out, shape='long',alt.var='Open',choice='Rank', id.var='X',ranked=TRUE)
#Try this option as per a discussion on stackexchange
mlogit.out<-mlogit.data(dat.out, shape='long',alt.levels='Open',choice='Rank', id.var='X',ranked=TRUE)
【问题讨论】:
-
啊。 使用 reshape/reshape2/cast 包。当我同样花了几天时间试图将我的数据转换成 mlogit 的形式,与 reshape/reshape2/cast 争吵时,你给了我模糊的回忆。最后我发现在我的特定问题上,mlogit 的表现不如其他算法。哦,我怎么笑了。好时光,好时光。