[R] mlogit error
arun
smartpink111 at yahoo.com
Sun Apr 7 16:56:59 CEST 2013
Hi,
Try this:
Mult3$mode.ids
#[1] 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1
#Levels: 1 2 3 4 5 6
I guess the key is to have equal number of alternatives.
Mult3$mode.ids<- as.numeric(as.character(Mult3$mode.ids))
res<-mlogit.data(Mult3[-25,],shape="long",choice="CHOICE",alt.var="mode.ids",indivs="set3",chid.vars="obs")
head(res,2)
# dn obs choice br mth tcomp num prom1 prom2 prom3 prom4 prom5 tprom cLOSEC
#1.1 4 1 0 1 487 0 642 0 0 0 0 0 0 0
#1.2 4 1 0 2 487 0 642 0 0 0 0 0 0 0
# cNEXIUM cPARIET cPROTIUM cZANTAC cZOTON comp1 comp2 comp3 comp4 lpat zpat
#1.1 0 0 0 0 0 0 0 0 0 0 0
#1.2 0 0 0 0 0 0 0 0 0 0 0
# doq part NurP PhP NoNon GPspec Newp
#1.1 78 3 0 0 1 No special interest Prefer tried and tested
#1.2 78 3 0 0 1 No special interest Prefer tried and tested
# Guide SHA size exp
#1.1 Often follow local guidelines/advice from PCT London 3 - 5 PARTNERS 32
#1.2 Often follow local guidelines/advice from PCT London 3 - 5 PARTNERS 32
# ALL_P sex disp form set3 set set2 tag1 mode.ids indivs CHOICE
#1.1 0.5295166 1 0 0 1 1 1 4 1 1 FALSE
#1.2 0.5295166 1 0 0 1 1 1 4 2 1 FALSE
A.K.
----- Original Message -----
From: "Leask, Graham" <g.leask at aston.ac.uk>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Sunday, April 7, 2013 10:39 AM
Subject: [R] mlogit error
Dear List
I am trying to fit a multinomial model using the mlogit package. Attempting to load
the data into mlogit presents the following error.
MLOG<-mlogit.data(Mult3,shape="long",choice="CHOICE",alt.var="mode.ids",indivs = "set3",chid.var = "obs")
Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.1", "1.2", "1.3", :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '10.1', '10.2', '10.3', '10.4', '10.5', '10.6', '100.1', '100.2', '100.3', '100.4', '100.5', '100.6', '1000.1', '1000.2', '1000.3', '1000.4', '1000.5', '1000.6', '1001.1', '1001.2', '1001.3', '1001.4', '1001.5', '1001.6', '1002.1', '1002.2', '1002.3', '1002.4', '1002.5', '1002.6', '1003.1', '1003.2', '1003.3', '1003.4', '1003.5', '1003.6', '1004.1', '1004.2', '1004.3', '1004.4', '1004.5', '1004.6', '1005.1', '1005.2', '1005.3', '1005.4', '1005.5', '1005.6', '1006.1', '1006.2', '1006.3', '1006.4', '1006.5', '1006.6', '1007.1', '1007.2', '1007.3', '1007.4', '1007.5', '1007.6', '1008.1', '1008.2', '1008.3', '1008.4', '1008.5', '1008.6', '1009.1', '1009.2', '1009.3', '1009.4', '1009.5', '1009.6', '101.1', '101.2', '101.3', '101.4', '101.5', '101.6', '1010.1', '1010.2', '1010.3', '1010.4', '1010.5', '1010.6', '1011.1', '1011.2', '1011.3', '1011.4', '1011.5', '1011.6',
'1012.1', '1012.2', '1012.3!
', '1012.4' [... truncated]
>
The code that I am running is as follows
Mult3$mode.ids<-as.factor(Mult3$br)
Mult3$indivs<-factor(Mult3$set3)
Mult3$CHOICE<-factor(Mult3$choice,labels=c("no","yes"))
MLOG<-mlogit.data(Mult3,shape="long",choice="CHOICE",alt.var="mode.ids",indivs = "set3",chid.var = "obs")
My data is structured as follows
dput(head(Mult3,25))
structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 5L), choice = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L,
0L), br = c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L), mth = c(487,
487, 487, 487, 487, 487, 488, 488, 488, 488, 488, 488, 488, 488,
488, 488, 488, 488, 489, 489, 489, 489, 489, 489, 489), tcomp = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), num = c(642, 642, 642, 642, 642, 642, 642, 642, 642,
642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642,
642, 642, 642), prom1 = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0), prom2 = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), prom3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0), prom4 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), prom5 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), tprom = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0), cLOSEC = c(0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0), cNEXIUM = c(0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1,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 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), PhP = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), NoNon = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), GPspec = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Special interest GP",
"No special interest"), class = "factor"), Newp = structure(c(4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Always among first to try new product",
"Like to try new regimens when available", "Wait to be confortable how the product works",
"Prefer tried and tested", "Reluctant to try new products"), class = "factor"),
Guide = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("Always follow local guidelines/advice from PCT",
"Often follow local guidelines/advice from PCT", "Sometimes follow local guidelines/advice from PCT",
"Rarely follow local guidelines/advice from PCT", "Prefer to make my own decision regardless of advice"
), class = "factor"), SHA = structure(c(9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L), .Label = c("North East", "North West",
"Yorkshire & Humber", "West Midlands", "East Midlands", "East of England",
"South West", "South Central", "London", "South East Coast",
"Scotland", "Wales"), class = "factor"), size = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("SINGLE HANDED",
"2 PARTNERS", "3 - 5 PARTNERS", "6 - 9 PARTNERS", "10 PLUS PARTNERS"
), class = "factor"), exp = c(32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32), ALL_P = c(0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642, 0.529516577720642,
0.529516577720642, 0.529516577720642), sex = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("0", "1"), class = "factor"),
disp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = c("0", "1"), class = "factor"), form = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor"),
set3 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1), set = c(1, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5), set2 = c(1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4,
4, 4, 4, 4, 5), tag1 = c(4L, 4L, 4L, 4L, 4L, 0L, 4L, 4L,
0L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 4L, 4L, 0L, 4L, 4L,
4L, 4L), mode.ids = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L,
5L, 6L, 1L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor"),
indivs = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "23", "25", "26", "27", "28", "29", "30", "31",
"32", "33", "34", "35", "36", "37", "38", "40", "41", "42",
"43", "44", "45", "47", "48", "49", "50", "51", "52", "53",
"54", "55", "56", "57", "58", "59", "60", "61", "62", "63",
"64", "65", "66", "67", "68", "69", "70", "71", "72", "73",
"74", "75", "76", "77", "78", "79", "80", "82", "83", "84",
"85", "86", "87", "88", "89", "90", "91", "92", "93"), class = "factor"),
CHOICE = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L,
1L), .Label = c("no", "yes"), class = "factor")), .Names = c("dn",
"obs", "choice", "br", "mth", "tcomp", "num", "prom1", "prom2",
"prom3", "prom4", "prom5", "tprom", "cLOSEC", "cNEXIUM", "cPARIET",
"cPROTIUM", "cZANTAC", "cZOTON", "comp1", "comp2", "comp3", "comp4",
"lpat", "zpat", "doq", "part", "NurP", "PhP", "NoNon", "GPspec",
"Newp", "Guide", "SHA", "size", "exp", "ALL_P", "sex", "disp",
"form", "set3", "set", "set2", "tag1", "mode.ids", "indivs",
"CHOICE"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25"), class = "data.frame")
I have noticed several previous posts regarding this error but no resolution has been posted to my knowledge.
Any help in resolving this would be appreciated.
Best wishes
Graham
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list