Description Usage Arguments Details Value Author(s) Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mFormula(object)
## S3 method for class 'formula'
mFormula(object)
is.mFormula(object)
## S3 method for class 'mFormula'
model.frame(
formula,
data,
...,
lhs = NULL,
rhs = NULL,
alt.subset = NULL,
reflevel = NULL
)
## S3 method for class 'mFormula'
model.matrix(object, data, ...)
|
object |
for the |
formula |
a |
data |
a |
... |
further arguments. |
lhs |
see |
rhs |
see |
alt.subset |
a vector of subset of alternatives one want to select, |
reflevel |
the alternative selected to be the reference alternative, |
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 may be specified by
including + 0
or - 1
in the second right-hand side 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.
an object of class mFormula
.
Yves Croissant
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.