data("TravelMode")
## 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
if(require("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)
}
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(AER)
Loading required package: car
Loading required package: lmtest
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AER/TravelMode.Rd_%03d_medium.png", width=480, height=480)
> ### Name: TravelMode
> ### Title: Travel Mode Choice Data
> ### Aliases: TravelMode
> ### Keywords: datasets
>
> ### ** Examples
>
> data("TravelMode")
>
> ## overall proportions for chosen mode
> with(TravelMode, prop.table(table(mode[choice == "yes"])))
air train bus car
0.2761905 0.3000000 0.1428571 0.2809524
>
> ## travel vs. waiting time for different travel modes
> library("lattice")
> xyplot(travel ~ wait | mode, data = TravelMode)
>
> ## Greene (2003), Table 21.11, conditional logit model
> if(require("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)
+ }
Loading required package: mlogit
Loading required package: Formula
Loading required package: maxLik
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
Call:
mlogit(formula = choice ~ gcost + wait + incair, data = TravelMode,
reflevel = "car", shape = "long", alt.var = "mode", method = "nr",
print.level = 0)
Frequencies of alternatives:
car air train bus
0.28095 0.27619 0.30000 0.14286
nr method
5 iterations, 0h:0m:0s
g'(-H)^-1g = 0.000234
successive function values within tolerance limits
Coefficients :
Estimate Std. Error t-value Pr(>|t|)
air:(intercept) 5.207433 0.779055 6.6843 2.320e-11 ***
train:(intercept) 3.869036 0.443127 8.7312 < 2.2e-16 ***
bus:(intercept) 3.163190 0.450266 7.0252 2.138e-12 ***
gcost -0.015501 0.004408 -3.5167 0.000437 ***
wait -0.096125 0.010440 -9.2075 < 2.2e-16 ***
incair 0.013287 0.010262 1.2947 0.195414
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Log-Likelihood: -199.13
McFadden R^2: 0.29825
Likelihood ratio test : chisq = 169.26 (p.value = < 2.22e-16)
>
>
>
>
>
> dev.off()
null device
1
>