# 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,
start=NULL,
control=mclogit.control(...), ...)
```

## 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 in`data`

, the variables are taken from`environment(formula)`

, typically the environment from which`glm`

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 of`options`

, and is`na.fail`

if that is unset. The ‘factory-fresh’ default is`na.omit`

. Another possible value is`NULL`

, no action. Value`na.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`

of`model.matrix.default`

.`control`

a list of parameters for the fitting process. See

`mclogit.control`

`...`

arguments to be passed to

`mclogit.control`

## 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.

## 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))))
```

```
Fitting plain conditional logit to obtain starting values
Iteration 1 - Deviance = 7377.939
Iteration 2 - Deviance = 4589.544
Iteration 3 - Deviance = 4293.485
Iteration 4 - Deviance = 4277.887
Iteration 5 - Deviance = 4277.808
Iteration 6 - Deviance = 4277.808
converged
Fitting random effects/random coefficients model
Iteration 1 - Deviance = 1876.788
Iteration 2 - Deviance = 1212.004
Iteration 3 - Deviance = 1009.8
Iteration 4 - Deviance = 958.7431
Iteration 5 - Deviance = 949.4332
Iteration 6 - Deviance = 948.1453
Iteration 7 - Deviance = 947.9013
Iteration 8 - Deviance = 947.8442
Iteration 9 - Deviance = 947.8329
Iteration 10 - Deviance = 947.8308
Iteration 11 - Deviance = 947.8305
Iteration 12 - Deviance = 947.8304
Iteration 13 - Deviance = 947.8304
Iteration 14 - Deviance = 947.8304
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.17223 0.13800 -1.248 0.212
welfare 2.05402 0.21441 9.580 <2e-16 ***
auth 0.08170 0.11820 0.691 0.489
econ.left:classnew.middle -1.66937 0.08804 -18.961 <2e-16 ***
econ.left:classold.middle -2.97243 0.14941 -19.894 <2e-16 ***
classnew.middle:welfare -0.98925 0.06088 -16.248 <2e-16 ***
classold.middle:welfare -1.61549 0.12869 -12.553 <2e-16 ***
classnew.middle:auth -1.39210 0.04679 -29.752 <2e-16 ***
classold.middle:auth 1.45677 0.05817 25.044 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Co-)Variances:
Grouping level: party.time
Estimate Std. Error
(Intercept) (Intercept)
(Intercept) 1.6343 0.1484
Null Deviance: 80580
Residual Deviance: 947.8
Number of Fisher Scoring iterations: 14
Number of observations: 37500
```