if(!requireNamespace("lattice") ||
!requireNamespace("mlogit")) {
if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) {
stop("not all packages required for the example are installed")
} else q() }
data("TravelMode", package = "AER")
## overall proportions for chosen mode
with(TravelMode, prop.table(table(mode[choice == "yes"])))
## travel vs. waiting time for different travel modes
library("lattice")
xyplot(travel ~ wait | mode, data = TravelMode)
## Greene (2003), Table 21.11, conditional logit model
library("mlogit")
TravelMode$incair <- with(TravelMode, income * (mode == "air"))
tm_cl <- mlogit(choice ~ gcost + wait + incair, data = TravelMode,
shape = "long", alt.var = "mode", reflevel = "car")
summary(tm_cl)
Run the code above in your browser using DataLab