3

私は、mlogit を介して多項ロジット分析のためにデータセットを形にするのに非常に苦労しています。私のデータセットは、以下のコードのURLから入手できます。

次のエラーが表示されます。

row.names<-.data.frame(のエラー*tmp*、値 = 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)
4

2 に答える 2

0

nnet パッケージのmultinom () 関数を試してみることをお勧めします。mlogit や mnlogit のような特別な形式は必要ありません。

library(RCurl)
library(nnet)

Data<-getURL("https://raw.githubusercontent.com/sjkiss/Survey/master/mlogit.out.csv")
Data<-read.csv(text=Data,header=T)
Data<-na.omit(Data) # Get rid of NA's
Data<-as.data.frame(Data)
# relevel the dependent variable (must be a factor)
Data$Job<-factor(Data$Job)
# Using "Online Blogger" as the reference, substitute with your choice
Data$Job<-relevel(Data$Job,ref="Online blogger")
# Run the multinomial logistic regression
# (seems like an awful lot of variables btw)
Data<-multinom(formula=Job~Accessible+Information+Responsive+Debate+Officials+Social+Trade.Offs+economic+gender+age,data=Data)
于 2015-06-15T19:16:56.073 に答える