Learn R Programming

mlogit (version 0.1-2)

logitform: Model formula for logit models

Description

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

Usage

logitform(object)
## S3 method for class 'formula':
logitform(object)
## S3 method for class 'list':
logitform(object)
is.logitform(object)
## S3 method for class 'logitform':
model.matrix(object, data, ...)
## S3 method for class 'logitform':
model.frame(formula, data, ...)
## S3 method for class 'logitform':
terms(x, ...)
## S3 method for class 'logitform':
update(object,new, ...)

Arguments

object, x
for the logitform function, a formula or a list, for the update and model.matrix methods, a logitform object,
new
the new formula for the update method,
formula
a logitform object,
data
a data.frame,
...
further arguments.

Value

  • an object of class logitform.

Details

a logitform is a formula for which the right hand side may contain two parts: the first one contains the alternative specific variables and the second one the individual specific variables. The two parts are separeted by a ``|'' sign. If a standard formula is writen, it is assumed that there are no individual specific variables. Specific methods are provided to build correctly the model matrix and to update the formula. The logitform function is not intended to be use directly. While using the mlogit function, the first argument is automaticaly coerced to a logitform object.

Examples

Run this code
v <-logitform(y~x1+x2|z1+z2)
update(v,.~.+x3-x1|.+z3-z1)
update(v,.~.-x1-x2|.)
update(v,.~.|.-z1-z2)
v <-logitform(y~x1+x2)
update(v,.~.-x1+x3)
update(v,.~.|z1+z2)

data("Fishing",package="Ecdat")
colnames(Fishing)[4:11] <- c("pr.beach","pr.pier","pr.boat","pr.charter",
                             "ca.beach","ca.pier","ca.boat","ca.charter")
Fish <- mlogit.data(Fishing,varying=c(4:11),shape="wide",choice="mode")
f <- logitform(mode~pr+ca|income)
X <- model.matrix(f,data=Fish)
X[1:6,]

Run the code above in your browser using DataLab