mlogit: Multinomial logit model

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/mlogit.R

Description

Estimation by maximum likelihood of the multinomial logit model, with alternative-specific and/or individual specific variables.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mlogit(
  formula,
  data,
  subset,
  weights,
  na.action,
  start = NULL,
  alt.subset = NULL,
  reflevel = NULL,
  nests = NULL,
  un.nest.el = FALSE,
  unscaled = FALSE,
  heterosc = FALSE,
  rpar = NULL,
  probit = FALSE,
  R = 40,
  correlation = FALSE,
  halton = NULL,
  random.nb = NULL,
  panel = FALSE,
  estimate = TRUE,
  seed = 10,
  ...
)

Arguments

formula

a symbolic description of the model to be estimated,

data

the data: an mlogit.data object or an ordinary data.frame,

subset

an optional vector specifying a subset of observations for mlogit,

weights

an optional vector of weights,

na.action

a function which indicates what should happen when the data contains NAs,

start

a vector of starting values,

alt.subset

a vector of character strings containing the subset of alternative on which the model should be estimated,

reflevel

the base alternative (the one for which the coefficients of individual-specific variables are normalized to 0),

nests

a named list of characters vectors, each names being a nest, the corresponding vector being the set of alternatives that belong to this nest,

un.nest.el

a boolean, if TRUE, the hypothesis of unique elasticity is imposed for nested logit models,

unscaled

a boolean, if TRUE, the unscaled version of the nested logit model is estimated,

heterosc

a boolean, if TRUE, the heteroscedastic logit model is estimated,

rpar

a named vector whose names are the random parameters and values the distribution : 'n' for normal, 'l' for log-normal, 't' for truncated normal, 'u' for uniform,

probit

if TRUE, a multinomial porbit model is estimated,

R

the number of function evaluation for the gaussian quadrature method used if heterosc = TRUE, the number of draws of pseudo-random numbers if rpar is not NULL,

correlation

only relevant if rpar is not NULL, if true, the correlation between random parameters is taken into account,

halton

only relevant if rpar is not NULL, if not NULL, halton sequence is used instead of pseudo-random numbers. If halton = NA, some default values are used for the prime of the sequence (actually, the primes are used in order) and for the number of elements droped. Otherwise, halton should be a list with elements prime (the primes used) and drop (the number of elements droped).

random.nb

only relevant if rpar is not NULL, a user-supplied matrix of random,

panel

only relevant if rpar is not NULL and if the data are repeated observations of the same unit ; if TRUE, the mixed-logit model is estimated using panel techniques,

estimate

a boolean indicating whether the model should be estimated or not: if not, the model.frame is returned,

seed

the seed to use for random numbers (for mixed logit and probit models),

...

further arguments passed to mlogit.data or mlogit.optim.

Details

For how to use the formula argument, see Formula().

The data argument may be an ordinary data.frame. In this case, some supplementary arguments should be provided and are passed to mlogit.data(). Note that it is not necessary to indicate the choice argument as it is deduced from the formula.

The model is estimated using the mlogit.optim(). function.

The basic multinomial logit model and three important extentions of this model may be estimated.

If heterosc=TRUE, the heteroscedastic logit model is estimated. J - 1 extra coefficients are estimated that represent the scale parameter for J - 1 alternatives, the scale parameter for the reference alternative being normalized to 1. The probabilities don't have a closed form, they are estimated using a gaussian quadrature method.

If nests is not NULL, the nested logit model is estimated.

If rpar is not NULL, the random parameter model is estimated. The probabilities are approximated using simulations with R draws and halton sequences are used if halton is not NULL. Pseudo-random numbers are drawns from a standard normal and the relevant transformations are performed to obtain numbers drawns from a normal, log-normal, censored-normal or uniform distribution. If correlation = TRUE, the correlation between the random parameters are taken into account by estimating the components of the cholesky decomposition of the covariance matrix. With G random parameters, without correlation G standard deviations are estimated, with correlation G * (G + 1) /2 coefficients are estimated.

Value

An object of class "mlogit", a list with elements:

Author(s)

Yves Croissant

References

\insertRef

MCFA:73mlogit

\insertRef

MCFA:74mlogit

\insertRef

TRAI:09mlogit

See Also

mlogit.data() to shape the data. nnet::multinom() from package nnet performs the estimation of the multinomial logit model with individual specific variables. mlogit.optim() details about the optimization function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## Cameron and Trivedi's Microeconometrics p.493 There are two
## alternative specific variables : price and catch one individual
## specific variable (income) and four fishing mode : beach, pier, boat,
## charter

data("Fishing", package = "mlogit")
Fish <- dfidx(Fishing, varying = 2:9, shape = "wide", choice = "mode")

## a pure "conditional" model
summary(mlogit(mode ~ price + catch, data = Fish))

## a pure "multinomial model"
summary(mlogit(mode ~ 0 | income, data = Fish))

## which can also be estimated using multinom (package nnet)
summary(nnet::multinom(mode ~ income, data = Fishing))

## a "mixed" model
m <- mlogit(mode ~ price + catch | income, data = Fish)
summary(m)

## same model with charter as the reference level
m <- mlogit(mode ~ price + catch | income, data = Fish, reflevel = "charter")

## same model with a subset of alternatives : charter, pier, beach
m <- mlogit(mode ~ price + catch | income, data = Fish,
            alt.subset = c("charter", "pier", "beach"))

## model on unbalanced data i.e. for some observations, some
## alternatives are missing
# a data.frame in wide format with two missing prices
Fishing2 <- Fishing
Fishing2[1, "price.pier"] <- Fishing2[3, "price.beach"] <- NA
mlogit(mode ~ price + catch | income, Fishing2, shape = "wide", varying = 2:9)

# a data.frame in long format with three missing lines
data("TravelMode", package = "AER")
Tr2 <- TravelMode[-c(2, 7, 9),]
mlogit(choice ~ wait + gcost | income + size, Tr2)

## An heteroscedastic logit model
data("TravelMode", package = "AER")
hl <- mlogit(choice ~ wait + travel + vcost, TravelMode, heterosc = TRUE)

## A nested logit model
TravelMode$avincome <- with(TravelMode, income * (mode == "air"))
TravelMode$time <- with(TravelMode, travel + wait)/60
TravelMode$timeair <- with(TravelMode, time * I(mode == "air"))
TravelMode$income <- with(TravelMode, income / 10)
# Hensher and Greene (2002), table 1 p.8-9 model 5
TravelMode$incomeother <- with(TravelMode, ifelse(mode %in% c('air', 'car'), income, 0))
nl <- mlogit(choice ~ gcost + wait + incomeother, TravelMode,
             nests = list(public = c('train', 'bus'), other = c('car','air')))
             
# same with a comon nest elasticity (model 1)
nl2 <- update(nl, un.nest.el = TRUE)

## a probit model
## Not run: 
pr <- mlogit(choice ~ wait + travel + vcost, TravelMode, probit = TRUE)

## End(Not run)

## a mixed logit model
## Not run: 
rpl <- mlogit(mode ~ price + catch | income, Fishing, varying = 2:9,
              rpar = c(price= 'n', catch = 'n'), correlation = TRUE,
              alton = NA, R = 50)
summary(rpl)
rpar(rpl)
cor.mlogit(rpl)
cov.mlogit(rpl)
rpar(rpl, "catch")
summary(rpar(rpl, "catch"))

## End(Not run)

# a ranked ordered model
data("Game", package = "mlogit")
g <- mlogit(ch ~ own | hours, Game, varying = 1:12, ranked = TRUE,
            reflevel = "PC", idnames = c("chid", "alt"))

Example output

Loading required package: dfidx

Attaching package:dfidxThe following object is masked frompackage:stats:

    filter


Call:
mlogit(formula = mode ~ price + catch, data = Fish, method = "nr")

Frequencies of alternatives:choice
  beach    boat charter    pier 
0.11337 0.35364 0.38240 0.15059 

nr method
7 iterations, 0h:0m:0s 
g'(-H)^-1g = 6.22E-06 
successive function values within tolerance limits 

Coefficients :
                      Estimate Std. Error  z-value  Pr(>|z|)    
(Intercept):boat     0.8713749  0.1140428   7.6408 2.154e-14 ***
(Intercept):charter  1.4988884  0.1329328  11.2755 < 2.2e-16 ***
(Intercept):pier     0.3070552  0.1145738   2.6800 0.0073627 ** 
price               -0.0247896  0.0017044 -14.5444 < 2.2e-16 ***
catch                0.3771689  0.1099707   3.4297 0.0006042 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -1230.8
McFadden R^2:  0.17823 
Likelihood ratio test : chisq = 533.88 (p.value = < 2.22e-16)

Call:
mlogit(formula = mode ~ 0 | income, data = Fish, method = "nr")

Frequencies of alternatives:choice
  beach    boat charter    pier 
0.11337 0.35364 0.38240 0.15059 

nr method
4 iterations, 0h:0m:0s 
g'(-H)^-1g = 8.32E-07 
gradient close to zero 

Coefficients :
                       Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept):boat     7.3892e-01  1.9673e-01  3.7560 0.0001727 ***
(Intercept):charter  1.3413e+00  1.9452e-01  6.8955 5.367e-12 ***
(Intercept):pier     8.1415e-01  2.2863e-01  3.5610 0.0003695 ***
income:boat          9.1906e-05  4.0664e-05  2.2602 0.0238116 *  
income:charter      -3.1640e-05  4.1846e-05 -0.7561 0.4495908    
income:pier         -1.4340e-04  5.3288e-05 -2.6911 0.0071223 ** 
---
Signif. codes:  0***0.001**0.01*0.05.’ 0.1 ‘ ’ 1

Log-Likelihood: -1477.2
McFadden R^2:  0.013736 
Likelihood ratio test : chisq = 41.145 (p.value = 6.0931e-09)
# weights:  12 (6 variable)
initial  value 1638.599935 
iter  10 value 1477.150646
final  value 1477.150569 
converged
Call:
nnet::multinom(formula = mode ~ income, data = Fishing)

Coefficients:
        (Intercept)        income
pier      0.8141506 -1.434028e-04
boat      0.7389178  9.190824e-05
charter   1.3412901 -3.163844e-05

Std. Errors:
         (Intercept)       income
pier    5.816490e-09 2.668383e-05
boat    3.209473e-09 2.057825e-05
charter 3.921689e-09 2.116425e-05

Residual Deviance: 2954.301 
AIC: 2966.301 

Call:
mlogit(formula = mode ~ price + catch | income, data = Fish, 
    method = "nr")

Frequencies of alternatives:choice
  beach    boat charter    pier 
0.11337 0.35364 0.38240 0.15059 

nr method
7 iterations, 0h:0m:0s 
g'(-H)^-1g = 1.37E-05 
successive function values within tolerance limits 

Coefficients :
                       Estimate  Std. Error  z-value  Pr(>|z|)    
(Intercept):boat     5.2728e-01  2.2279e-01   2.3667 0.0179485 *  
(Intercept):charter  1.6944e+00  2.2405e-01   7.5624 3.952e-14 ***
(Intercept):pier     7.7796e-01  2.2049e-01   3.5283 0.0004183 ***
price               -2.5117e-02  1.7317e-03 -14.5042 < 2.2e-16 ***
catch                3.5778e-01  1.0977e-01   3.2593 0.0011170 ** 
income:boat          8.9440e-05  5.0067e-05   1.7864 0.0740345 .  
income:charter      -3.3292e-05  5.0341e-05  -0.6613 0.5084031    
income:pier         -1.2758e-04  5.0640e-05  -2.5193 0.0117582 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -1215.1
McFadden R^2:  0.18868 
Likelihood ratio test : chisq = 565.17 (p.value = < 2.22e-16)

Call:
mlogit(formula = mode ~ price + catch | income, data = Fishing2,     shape = "wide", varying = 2:9, method = "nr")

Coefficients:
   (Intercept):boat  (Intercept):charter     (Intercept):pier  
         5.2790e-01           1.6948e+00           7.7663e-01  
              price                catch          income:boat  
        -2.5110e-02           3.5768e-01           8.9122e-05  
     income:charter          income:pier  
        -3.3611e-05          -1.2700e-04  


Call:
mlogit(formula = choice ~ wait + gcost | income + size, data = Tr2,     method = "nr")

Coefficients:
(Intercept):train    (Intercept):bus    (Intercept):car               wait  
       -2.3115942         -3.4504941         -7.8913907         -0.1013180  
            gcost       income:train         income:bus         income:car  
       -0.0197064         -0.0589804         -0.0277037         -0.0041153  
       size:train           size:bus           size:car  
        1.3289497          1.0090796          1.0392585  


Call:
mlogit(formula = mode ~ price + catch | income, data = Fishing, 
    rpar = c(price = "n", catch = "n"), R = 50, correlation = TRUE, 
    varying = 2:9, alton = NA)

Frequencies of alternatives:choice
  beach    boat charter    pier 
0.11337 0.35364 0.38240 0.15059 

bfgs method
17 iterations, 0h:0m:9s 
g'(-H)^-1g = 1.3E-07 
gradient close to zero 

Coefficients :
                       Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept):boat     3.4903e-01  2.6558e-01  1.3142 0.1887779    
(Intercept):charter  2.1865e+00  3.0504e-01  7.1680 7.612e-13 ***
(Intercept):pier     7.4647e-01  2.1246e-01  3.5135 0.0004422 ***
price               -4.4544e-02  4.9868e-03 -8.9325 < 2.2e-16 ***
catch                2.8054e-01  1.5687e-01  1.7884 0.0737120 .  
income:boat          1.0513e-04  5.8634e-05  1.7929 0.0729872 .  
income:charter      -4.0786e-05  5.9634e-05 -0.6839 0.4940114    
income:pier         -1.2163e-04  4.7312e-05 -2.5708 0.0101451 *  
chol.price:price     2.3047e-02  4.1211e-03  5.5925 2.238e-08 ***
chol.price:catch     7.5142e-01  3.6695e-01  2.0477 0.0405860 *  
chol.catch:catch     1.3290e-02  7.8229e-01  0.0170 0.9864459    
---
Signif. codes:  0***0.001**0.01*0.05.’ 0.1 ‘ ’ 1

Log-Likelihood: -1185.9
McFadden R^2:  0.20819 
Likelihood ratio test : chisq = 623.63 (p.value = < 2.22e-16)

random coefficients
      Min.     1st Qu.      Median        Mean     3rd Qu. Max.
price -Inf -0.06008954 -0.04454446 -0.04454446 -0.02899938  Inf
catch -Inf -0.22636264  0.28054193  0.28054193  0.78744649  Inf
$price
normal distribution with parameters -0.045 (mean) and 0.023 (sd)

$catch
normal distribution with parameters 0.281 (mean) and 0.752 (sd)

          price     catch
price 1.0000000 0.9998436
catch 0.9998436 1.0000000
             price      catch
price 0.0005311717 0.01731811
catch 0.0173181068 0.56480911
normal distribution with parameters 0.281 (mean) and 0.752 (sd)
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
      -Inf -0.2263626  0.2805419  0.2805419  0.7874465        Inf 

mlogit documentation built on Oct. 23, 2020, 5:29 p.m.