mlogit.data in R - error in 'row.names<-.data.frame`(`*tmp*`, value = c(" -



mlogit.data in R - error in 'row.names<-.data.frame`(`*tmp*`, value = c(" -

i trying setup info mlogit-package in r, somehow seem run trouble.

my data-frame called choice2, , looks this:

id choice_id mode.ids selection weightloss adveffect inj tab infreq_1 infreq_3 cost 1 x1 0 3.5 0 1 0 1 0 550 1 x1 b 0 10.0 1 0 1 0 1 90 1 x1 c 1 0.0 0 0 0 0 0 0 1 x10 0 6.0 0 1 0 0 1 50 1 x10 b 0 3.5 1 0 1 1 0 165 1 x10 c 1 0.0 0 0 0 0 0 0 1 x11 0 2.0 1 1 0 0 1 165 1 x11 b 1 3.5 0 0 1 1 0 90 1 x11 c 0 0.0 0 0 0 0 0 0 1 x12 0 10.0 1 1 0 0 1 550

i setup info mlogit-package in r running next command:

require(mlogit) clogit <- mlogit.data(choice2, selection = "choice", shape = c("long"), id.var = "id", alt.var = "mode.ids", varying = 5:11, chid.var = "choice_id", )

however, results in next error-message:

error in `row.names<-.data.frame`(`*tmp*`, value = c("x1.a", "x1.b", "x1.c", : duplicate 'row.names' not allowed in addition: warning message: non-unique values when setting 'row.names': ‘x1.a’, ‘x1.b’, ‘x1.c’, ‘x10.a’, ‘x10.b’, ‘x10.c’, ‘x11.a’, ‘x11.b’, ‘x11.c’, ‘x12.a’, ‘x12.b’, ‘x12.c’, ‘x13.a’, ‘x13.b’, ‘x13.c’, ‘x2.a’, ‘x2.b’, ‘x2.c’, ‘x3.a’, ‘x3.b’, ‘x3.c’, ‘x4.a’, ‘x4.b’, ‘x4.c’, ‘x5.a’, ‘x5.b’, ‘x5.c’, ‘x6.a’, ‘x6.b’, ‘x6.c’, ‘x7.a’, ‘x7.b’, ‘x7.c’, ‘x8.a’, ‘x8.b’, ‘x8.c’, ‘x9.a’, ‘x9.b’, ‘x9.c’

choice2 can desciribed following:

> str(choice2) 'data.frame': 7722 obs. of 11 variables: $ id : int 1 1 1 1 1 1 1 1 1 1 ... $ choice_id : factor w/ 13 levels "x1","x10","x11",..: 1 1 1 2 2 2 3 3 3 4 ... $ mode.ids : factor w/ 3 levels "a","b","c": 1 2 3 1 2 3 1 2 3 1 ... $ selection : factor w/ 2 levels "0","1": 1 1 2 1 1 2 1 2 1 1 ... $ weightloss: num 3.5 10 0 6 3.5 0 2 3.5 0 10 ... $ adveffect : int 0 1 0 0 1 0 1 0 0 1 ... $ inj : int 1 0 0 1 0 0 1 0 0 1 ... $ tab : int 0 1 0 0 1 0 0 1 0 0 ... $ infreq_1 : int 1 0 0 0 1 0 0 1 0 0 ... $ infreq_3 : int 0 1 0 1 0 0 1 0 0 1 ... $ cost : int 550 90 0 50 165 0 165 90 0 550 ...

can tell me might doing wrong here? have sought help-documentation of mlogit, , sought similar topics here on stackowerflow without succes :)

all best, henrik

it appears choice_id variable indexes selection occasion each respondent. however, not chid variable (technically component of attribute) in mlogit.data object represents. chid variable in mlogit.data object represents selection occasions across whole dataset. if respondents 1 , 2 presented 13 selection tasks each, chid variable 1:26, rather rep(1:13,2). that's why you're getting non-unique row names error, because mlogit.data generates row names interaction between chid variable , alternative variable.

but don't need worry chid variable, because mlogit.data take care of you. take out chid.var argument in phone call mlogit.data, , won't receive error.

> require(mlogit) > choice2 = data.frame(id = rep(1:2, each = 9), + choice_id = rep(rep(1:3, each = 3), times = 2), + mode.ids = rep(letters[1:3], times = 6), + selection = rep(c(0,0,1), times = 6), + inj = runif(18) > 0.5) > > # causes error because chid.var specified > mlogit.data(choice2, + selection = 'choice', + shape = 'long', + id.var = 'id', + alt.var = 'mode.ids', + varying = 5, + chid.var = 'choice_id') error in `row.names<-.data.frame`(`*tmp*`, value = c("1.a", "1.b", "1.c", : duplicate 'row.names' not allowed in addition: warning message: non-unique values when setting 'row.names': ‘1.a’, ‘1.b’, ‘1.c’, ‘2.a’, ‘2.b’, ‘2.c’, ‘3.a’, ‘3.b’, ‘3.c’ > > # not cause error because chid.var not specified > mlogit.data(choice2, + selection = 'choice', + shape = 'long', + id.var = 'id', + alt.var = 'mode.ids', + varying = 5) id choice_id mode.ids selection inj 1.a 1 1 false true 1.b 1 1 b false true 1.c 1 1 c true false 2.a 1 2 false false 2.b 1 2 b false true 2.c 1 2 c true false 3.a 1 3 false false 3.b 1 3 b false false 3.c 1 3 c true true 4.a 2 1 false true 4.b 2 1 b false false 4.c 2 1 c true false 5.a 2 2 false false 5.b 2 2 b false true 5.c 2 2 c true false 6.a 2 3 false true 6.b 2 3 b false false 6.c 2 3 c true true

r mlogit

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -