## from Greene's Econometric Analysis p. 731
data("ModeChoice",package="Ecdat")
ModeChoice <- mlogit.data(ModeChoice,choice="mode",shape="long",
alt.levels=c("air","train","bus","car"))
## Create a variable of income only for the air mode
ModeChoice$avinc <- (ModeChoice$alt=='air')*ModeChoice$hinc
## Estimate the model on all alternatives, with car as the base level
## like in Greene's book.
x <- mlogit(mode~ttme+gc+avinc,ModeChoice,reflevel="car")
## Estimate the same model for ground modes only (the variable avinc
## must be dropped because it is 0 for every observation
g <- mlogit(mode~ttme+gc,ModeChoice,reflevel="car",
alt.subset=c("car","bus","train"))
## Compute the test
hmftest(x,g)
Run the code above in your browser using DataLab