Using a formula and data, create a specification object of a multinomial logit model.
mnl.spec(f, data, choices = NULL, base.choice = 1,
varying = NULL, sep = ".")
An object of class mnl.spec
containing the following elements:
Name of the response variable.
Vector of alternatives.
Index of the base alternative within choices
.
Matrix of size number of choices x number of variables. Each value is logical determining if the variable is used in that choice equation.
Logical vector of size number of variables. It determines if that variable has the same coefficient for all alternatives.
Matrix of the same shape as variable.used
. It contains names of variables in its alternative-specific form.
Vector of variable names specified by the varying
vector that are used in the specification.
Logical vector of size number of choices determining in which equation asc is used.
Separator of variable name and alternative name in the ‘varying’ variables.
Table of frequencies for each choice in the choices
vector computed from the data.
Formula (see Details below).
Data frame containing the variables in the model. It should be in the ‘wide’ format (using the terminology of the reshape
function), i.e. there is one record for each individual and alternative-specific variables occupy single column per alternative.
Vector of names of alternatives. If it is not given, it is determined from the response column of the data frame. Values of this vector should match or be a subset of those in the response column.
Index of the base alternative within the vector choices
.
Indices of variables within data
that are alternative-specific.
Separator of variable name and alternative name in the ‘varying’ variables.
Hana Sevcikova
The formula f
is of the form response ~ x1 + x2 | y1 + y2
. Coefficients for variables in the first part of the formula (i.e. before '|'), here x1
and x2
, are forced to be the same for all alternatives. Variables in the second part of the formula (i.e. after '|'), here y1
and y2
, have different coefficients for different alternatives. Either part of the formula can be omitted. Alternative specific constants (asc) are included automatically. To exclude asc, use -1 in the first part. The equation of the base alternative is always set to 0.
summary.mnl.spec
data(heating)
spec <- mnl.spec(depvar ~ ic + oc + income, heating, varying=3:12, sep='')
summary(spec)
spec <- mnl.spec(depvar ~ oc-1 | ic, heating, varying=3:12, sep='')
summary(spec)
Run the code above in your browser using DataLab