1

I'm trying to run a random intercept multinomial logit model

ID Resolution STATE Index_1 Index_2
6 Settled Indiana 43.3267816 49.2
8 Settled Delaware 72.6980536 48.5
9 Dismissed Delaware 72.6980536 48.5
10 Settled New York 72.0173234 48.4
11 Stay Texas 84.8092534 49.8

The outcome variable is "Resolution" and the Index_1 and Index_2 are nested within the State.

Regardless if the shape is set to "wide" or "long" when attempting to set up the data I get this error: Error in guess(varying) : failed to guess time-varying variables from their names

mlogit_data <- mlogit.data(data, shape = "wide", choice = "_Resolution", varying = 3:5, alt.levels = NULL)

Does anyone know how to fix this?

jay.sf
  • 60,139
  • 8
  • 53
  • 110
mmm coder
  • 11
  • 1

1 Answers1

0

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 
jay.sf
  • 60,139
  • 8
  • 53
  • 110