I am having a murderous time getting my data set in shape for a multinomial logit analysis via mlogit. My data set is available from the url in the code below.
I'm getting the following error:
Error in
row.names<-.data.frame
(*tmp*
, value = c("1.Accessible", "1.Accessible", : duplicate 'row.names' are not allowed
I've checked elsewhere and this problem seems to come up. I've tried playing with the alt.levels
as opposed to the alt.var
argument, and that doesn't work.
#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)