R: Model formula for logit models

mFormula {mlogit} | R Documentation

## Model formula for logit models

### Description

Two kinds of variables are used in logit models: alternative specific and individual specific variables. `mFormula` provides a relevant class to deal with this specificity and suitable methods to extract the elements of the model.

### Usage

    mFormula(object)
    ## S3 method for class 'formula'
    mFormula(object)
    is.mFormula(object)
    ## S3 method for class 'mFormula'
    model.matrix(object, data, ...)
    ## S3 method for class 'mFormula'
    model.frame(formula, data, ..., lhs = NULL, rhs = NULL)

### Arguments

`object` | for the `mFormula` function, a formula, for the `update` and `model.matrix` methods, a `mFormula` object,
`formula` | a `mFormula` object,
`data` | a `data.frame`,

`lhs` | see `Formula`
`rhs` | see `Formula`
`...` | further arguments.

### Details

Let `J` being the number of alternatives. The formula may include alternative-specific and individual specific variables. For the latter, `J-1` coefficients are estimated for each variable. For the former, only one (generic) coefficient or `J` different coefficient may be estimated.

A `mFormula` is a formula for which the right hand side may contain three parts: the first one contains the alternative specific variables with generic coefficient, i.e. a unique coefficient for all the alternatives ; the second one contains the individual specific variables for which one coefficient is estimated for all the alternatives except one of them ; the third one contains the alternative specific variables with alternative specific coefficients. The different parts are separeted by a “`|`” sign. If a standard formula is writen, it is assumed that there are only alternative specific variables with generic coefficients.

The intercept is necessarely alternative specific (a generic intercept is not identified because only utility differences are relevant). Therefore, it deals with the second part of the formula. As it is usual in `R`, the default behaviour is to include an intercept. A model without an intercept (which is hardly meaningfull) may be specified by includint `+0` or `-1` in the second rhs part of the formula. `+0` or `-1` in the first and in the third part of the formula are simply ignored.

Specific methods are provided to build correctly the model matrix and to update the formula. The `mFormula` function is not intended to be use directly. While using the `mlogit` function, the first argument is automaticaly coerced to a `mFormula` object.

### Value

an object of class `mFormula`.

### Author(s)

Yves Croissant

### Examples

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

    # a formula with to alternative specific variables (price and catch) and
    # an intercept
    f1 <- mFormula(mode ~ price + catch)
    head(model.matrix(f1, Fish), 2)

    # same, with an individual specific variable (income)
    f2 <- mFormula(mode ~ price + catch | income)
    head(model.matrix(f2, Fish), 2)

    # same, without an intercept
    f3 <- mFormula(mode ~ price + catch | income + 0)
    head(model.matrix(f3, Fish), 2)

    # same as f2, but now, coefficients of catch are alternative specific
    f4 <- mFormula(mode ~ price | income | catch)
    head(model.matrix(f4, Fish), 2)

[Package mlogit version 0.3-0 Index]