Conditional Logit Models and Mixed Conditional Logit Models¶
Description¶
mclogit
fits conditional logit models and mixed conditional logit models to count
data and individual choice data, where the choice set may vary across choice occasions.
Conditional logit models without random effects are fitted by Fisher-scoring/IWLS. Models with random effects (mixed conditional logit models) are estimated via maximum likelihood with a simple Laplace aproximation (aka PQL).
Usage¶
mclogit(formula, data=parent.frame(), random=NULL,
subset, weights = NULL, offset=NULL, na.action = getOption("na.action"),
model = TRUE, x = FALSE, y = TRUE, contrasts=NULL,
method = NULL, estimator=c("ML","REML"),
dispersion = FALSE,
start=NULL,
control=if(length(random))
mmclogit.control(...)
else mclogit.control(...), ...)
## S4 method for signature 'mclogit'
update(object, formula., dispersion, ...)
## S4 method for signature 'mclogit'
summary(object, dispersion = NULL, correlation = FALSE,
symbolic.cor = FALSE, ...)
Arguments¶
formula
-
a model formula: a symbolic description of the model to be fitted. The left-hand side contains is expected to be a two-column matrix. The first column contains the choice counts or choice indicators (alternative is chosen=1, is not chosen=0). The second column contains unique numbers for each choice set. If individual-level data is used, choice sets correspond to the individuals, if aggregated data with choice counts are used, choice sets may e.g. correspond to covariate classes within clusters. The right-hand of the formula contains choice predictors. It should be noted that constants are deleted from the formula as are predictors that do not vary within choice sets.
data
-
an optional data frame, list or environment (or object coercible by
as.data.frame
to a data frame) containing the variables in the model. If not found indata
, the variables are taken fromenvironment(formula)
, typically the environment from whichglm
is called. random
-
an optional formula that specifies the random-effects structure or NULL.
weights
-
an optional vector of weights to be used in the fitting process. Should be
NULL
or a numeric vector. offset
-
an optional model offset. Currently only supported for models without random effects.
subset
-
an optional vector specifying a subset of observations to be used in the fitting process.
na.action
-
a function which indicates what should happen when the data contain
NA``s. The default is set by the ``na.action
setting ofoptions
, and isna.fail
if that is unset. The ‘factory-fresh’ default isna.omit
. Another possible value isNULL
, no action. Valuena.exclude
can be useful. start
-
an optional numerical vector of starting values for the conditional logit parameters.
model
-
a logical value indicating whether model frame should be included as a component of the returned value.
-
x
,y
-
logical values indicating whether the response vector and model matrix used in the fitting process should be returned as components of the returned value.
contrasts
-
an optional list. See the
contrasts.arg
ofmodel.matrix.default
. method
-
NULL
or a character string, either “PQL” or “MQL”, specifies the type of the quasilikelihood approximation to be used if a random-effects model is to be estimated. estimator
-
a character string; either “ML” or “REML”, specifies which estimator is to be used/approximated.
dispersion
-
a real number used as dispersion parameter; a character vector that specifies the method to compute the dispersion; a logical value – if
TRUE
the default method ("Afroz"
) is used, ifFALSE
, the dispersion parameter is set to 1, that is, no dispersion. For details seedispersion
. control
-
a list of parameters for the fitting process. See
mclogit.control
...
-
arguments to be passed to
mclogit.control
ormmclogit.control
object
-
an object that inherits class
"mclogit"
. When passed todispersion()
, it should be the result of a call ofmclogit()
ofmblogit()
, without random effects. formula.
-
a changes to the model formula, see
update.default
andupdate.formula
. correlation
-
logical; see
summary.lm
. symbolic.cor
-
logical; see
summary.lm
.
Value¶
mclogit
returns an object of class “mclogit”, which has almost the same structure as
an object of class “glm”.
Notes¶
Covariates that are constant within choice sets are automatically dropped from the model
formula specified by the formula
argument of mclogit
.
If the model contains random effects, these should
- either vary within choice sets (e.g. the levels of a
factor that defines the choice sets should not be nested within the levels of factor)
- or be random coefficients of covariates that vary within choice sets.
In earlier versions of the package (prior to 0.6) it will lead to a failure of the model
fitting algorithm if these conditions are not satisfied. Since version 0.6 of the
package, the function mclogit
will complain about such model a misspecification
explicitely.
See also¶
Conditional logit models are also supported by gmnl [pkg], mlogit [pkg], and survival [pkg]. survival [pkg] supports conditional logit models for binary panel data and case-control studies. mlogit [pkg] and gmnl [pkg] treat conditional logit models from an econometric perspective. Unlike the present package, they focus on the random utility interpretation of discrete choice models and support generalisations of conditional logit models, such as nested logit models, that are intended to overcome the IIA (indipendence from irrelevant alterantives) assumption. Mixed multinomial models are also supported and estimated using simulation-based techniques. Unlike the present package, mixed or random-effects extensions are mainly intended to fit repeated choices of the same individuals and not aggregated choices of many individuals facing identical alternatives.
Examples¶
data(Transport)
summary(mclogit(
cbind(resp,suburb)~distance+cost,
data=Transport
))
Iteration 1 - Deviance = 39.74973
Iteration 2 - Deviance = 10.50328
Iteration 3 - Deviance = 9.231325
Iteration 4 - Deviance = 9.227742
Iteration 5 - Deviance = 9.227742
converged
Call:
mclogit(formula = cbind(resp, suburb) ~ distance + cost, data = Transport)
Estimate Std. Error z value Pr(>|z|)
distance -1.43940 0.05318 -27.07 <2e-16 ***
cost -0.97753 0.03987 -24.52 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Null Deviance: 2734
Residual Deviance: 9.228
Number of Fisher Scoring iterations: 5
Number of observations: 1994
data(electors)
summary(mclogit(
cbind(Freq,interaction(time,class))~econ.left/class+welfare/class+auth/class,
random=~1|party.time,
data=within(electors,party.time<-interaction(party,time))))
Iteration 1 - deviance = 1054.511 - criterion = 0.1598497
Iteration 2 - deviance = 923.1626 - criterion = 0.02666473
Iteration 3 - deviance = 890.3113 - criterion = 0.006530011
Iteration 4 - deviance = 883.0567 - criterion = 0.0005723444
Iteration 5 - deviance = 881.4344 - criterion = 1.387329e-05
Iteration 6 - deviance = 881.2041 - criterion = 1.394381e-07
Iteration 7 - deviance = 881.1809 - criterion = 1.04388e-09
converged
Call:
mclogit(formula = cbind(Freq, interaction(time, class)) ~ econ.left/class +
welfare/class + auth/class, data = within(electors, party.time <-
interaction(party,
time)), random = ~1 | party.time)
Coefficents:
Estimate Std. Error z value Pr(>|z|)
econ.left -0.12603 0.18576 -0.678 0.497
welfare 2.01955 0.29136 6.932 4.16e-12 ***
auth 0.11409 0.15908 0.717 0.473
econ.left:classnew.middle -1.81703 0.09859 -18.430 < 2e-16 ***
econ.left:classold.middle -3.13862 0.15780 -19.890 < 2e-16 ***
classnew.middle:welfare -0.89578 0.06573 -13.628 < 2e-16 ***
classold.middle:welfare -1.47904 0.13451 -10.996 < 2e-16 ***
classnew.middle:auth -1.43391 0.04855 -29.535 < 2e-16 ***
classold.middle:auth 1.44109 0.05883 24.494 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Co-)Variances:
Grouping level: 1
Estimate Std.Err.
(Intercept) 3.066 0.9423
Null Deviance: 80580
Residual Deviance: 881.2
Number of Fisher Scoring iterations: 7
Number of observations: 37500