2

I need to run a rank-ordered logit where some individuals ranked a maximum number of alternatives, and some ranked fewer than that maximum.

mlogit::mlogit.data doesn't like when the input data has differing numbers of ranks per individual.

Here's a small example, using data from the mlogit package.

In the original data, all individuals rank 6 alternatives, but this example modifies that by setting a random number of each individual's ranks to NA, then to 6, the maximum possible rank.

set.seed(62617)
data("Game2", package = "mlogit")
library(dplyr)
library(mlogit)

df1 <- Game2 %>% group_by(chid) %>% 
  mutate(ch = ifelse(ch > sample(2:6, size = 1), NA, ch))

dat <-  df1 %>% mutate(ch = replace(ch, is.na(ch), 6)) %>% as.data.frame()

G <- mlogit.data(dat, shape = "long", 
                 choice = "ch", 
                 alt.var = "platform", 
                 ranked = TRUE)

summary(mlogit(ch ~ own | hours + age, G, reflevel = "PC"))

This results in the following error:

Error in if (abs(x - oldx) < ftol) { : 
  missing value where TRUE/FALSE needed

How should I be coding unranked alternatives to make the model work?

MDe
  • 2,478
  • 3
  • 22
  • 27

0 Answers0