As a preliminary note, here's a very relevant answer for you that might interest you if you want to compute multinomial mixed logit models.
Anyway, you probably made typos when specifying the parameters. In addition you need to use the sep=
parameter which refers to by which character suffixes are appended to the names, the default is "."
but you have "_"
; this is needed so the internally called reshape
can guess the names correctly (see also ?reshape
).
mlogit_data <- mlogit::mlogit.data(dat,
choice="Resolution",
shape="wide",
varying=4:5, ## refers to the Index_* columns
sep='_')
mlogit_data
# ID Resolution STATE alt Index chid idx
# 1 6 FALSE Indiana 1 43.32678 1 1:1
# 2 6 FALSE Indiana 2 49.20000 1 1:2
# 3 8 FALSE Delaware 1 72.69805 2 2:1
# 4 8 FALSE Delaware 2 48.50000 2 2:2
# 5 9 FALSE Delaware 1 72.69805 3 3:1
# 6 9 FALSE Delaware 2 48.50000 3 3:2
# 7 10 FALSE New York 1 72.01732 4 4:1
# 8 10 FALSE New York 2 48.40000 4 4:2
# 9 11 FALSE Texas 1 84.80925 5 5:1
# 10 11 FALSE Texas 2 49.80000 5 5:2
#
# ~~~ indexes ~~~~
# chid alt
# 1 1 1
# 2 1 2
# 3 2 1
# 4 2 2
# 5 3 1
# 6 3 2
# 7 4 1
# 8 4 2
# 9 5 1
# 10 5 2
# indexes: 1, 2
However, for some reason, they deprecated the mlogit::mlogit.data
function and call for dfidx::dfidx
to be used instead.
dfidx::dfidx(dat, idx=c('ID', 'STATE'))
# Resolution Index_1 Index_2 idx
# 1 Settled 43.32678 49.2 6:iana
# 2 Settled 72.69805 48.5 8:ware
# 3 Dismissed 72.69805 48.5 9:ware
# 4 Settled 72.01732 48.4 10:York
# 5 Stay 84.80925 49.8 11:exas
#
# ~~~ indexes ~~~~
# ID STATE
# 1 6 Indiana
# 2 8 Delaware
# 3 9 Delaware
# 4 10 New York
# 5 11 Texas
# indexes: 1, 2