# NOT RUN {
## Game2 is a data.frame in long format for which the response is a
## ranking variable (see example in package mlogit, function mlogit.data)
## --- 1. baseline case (equivalent to mlogit package)
## load data
data("Game2", package = "mlogit")
head(Game2, 13)
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch",
alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 2. handle missing values
## introduce NAs
Game2$ch[Game2$ch != 1] <- NA
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch", alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 3. handle varying choice sets
## drop choice options
Game2 <- Game2[-c(7:8),]
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch", alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 4. run models
summary(mlogit::mlogit(ch ~ own | -1 + hours + age, G, reflevel = "PC"))
summary(mlogit::mlogit(ch ~ 0 | -1 + age | own, G))
summary(mlogit::mlogit(ch ~ 0 | -1 + age, G))
# }
Run the code above in your browser using DataLab