0

New to R and want to use mlogit function.

However after putting my data into a data frame and run

x <- mlogit.data(mlogit, choice="PlacedN", shape="long", alt.var="RaceID")

I get duplicate 'row.names' are not allowed

I can upload my file if needed I've spent days trying to get this to work, so any help will be appreciated

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
Michael
  • 13
  • 1
  • 4
  • 1
    It would be better to have a reproducible example/file to check the problem. – akrun Oct 18 '14 at 14:18
  • so you could change the row names or try a matrix instead which allows duplicate row names (might not work since the docs say the input needs to be a data frame) – rawr Oct 18 '14 at 14:42
  • @akrun please go to the link it called mlogit thanks for any help [link](https://www.cubbyusercontent.com/pl/cubbug/_55429662ff9641e2b9923e1bc63941ec) – Michael Oct 18 '14 at 14:49
  • There's only a csv file there. Which may disappear at any moment, making this question obsolete. Please make your question reproducible by including simulated data. This is also a great tool for you to learn about your data. – Roman Luštrik Oct 19 '14 at 12:10

1 Answers1

2

You may want to put "RaceID" into the alt.levels argument instead of alt.var. From the mlogit.data help file:

alt.levels

the name of the alternatives: if null, for a wide data.frame, they are guessed from the variable names and the choice variable (both should be the same), for a long data.frame, they are guessed from the alt.var argument.

Give this a try.

library(mlogit)
m <- read.csv("mlogit.csv")
mlogd <- mlogit.data(m, choice="PlacedN", shape="long", alt.levels="RaceID")
head(mlogd)
#            RaceID PlacedN   RSP TrA JoA aDS bDS mDS aDH bDH mDH LDH  MR eMR
# 1.RaceID 20119552    TRUE  3.00  13  12   0   0   0   0   0   0   0   0 131
# 2.RaceID 20119552   FALSE  4.00  23  26  91  94  94 139 153 145 153 150 150
# 3.RaceID 20119552   FALSE  0.83  15  15  99 127  99 150 153 150 153 159 159
# 4.RaceID 20119552   FALSE 18.00  21  15   0   0   0   0   0   0   0   0 131
# 5.RaceID 20119552   FALSE 16.00  16  12  92 127  92 134 135 134 135 136 136
# 6.RaceID 20119617    TRUE  2.50  12  10   0   0   0   0   0   0   0   0 152
Community
  • 1
  • 1
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • Thanks it loaded ok but when I went to try summary(mlogit(PlacedN~TrA+JoA -1,data=x)) I get Error in `colnames<-`(`*tmp*`, value = "RaceID") : attempt to set 'colnames' on an object with less than two dimensions – Michael Oct 18 '14 at 16:38
  • @Michael - that code is completely different from what you have in your question – Rich Scriven Oct 18 '14 at 18:09
  • Please ask a new question related to that because that's a new separate task – Rich Scriven Oct 18 '14 at 18:17
  • @RichScriven The OP is pointing out a problem in your answer, namely that specifying the column name in `alt.levels` creates a column of "alternatives" that has only one value: the column name. That isn't helping get any closer to solving the problem. – sautedman Jul 19 '17 at 22:29