mnlogit: Fast estimation of multinomial logit models

Description Usage Arguments Value Note Author(s) References Examples

View source: R/mnlogit.R

Description

Time and memory efficient estimation of multinomial logit models using maximum likelihood method and targeted at large scale multiclass classification problems in econometrics and machine learning. Numerical optimization is performed by the Newton-Raphson method using an optimized, parallel C++ library to achieve fast computation of Hessian matrices. The user interface closely related to the CRAN package mlogit.

Usage

1
2
3
4
5
6
7
mnlogit(formula, data, choiceVar, maxiter = 50, ftol = 1e-6,
        gtol = 1e-6, weights = NULL, ncores = 1, na.rm = TRUE, 
        print.level = 0, linDepTol = 1e-6, ...)
## S3 method for class 'mnlogit'
predict(object, newdata = NULL, probability = FALSE, ...)
## S3 method for class 'mnlogit'
coef(object, as.list = FALSE, ...)

Arguments

formula

formula object or string specifying the model to be estimated (see Note).

data

A data.frame object with data organized in the 'long' format (see Note).

choiceVar

A string naming the column in 'data' which has the list of choices.

maxiter

An integer indicating maximum number of Newton's iterations,

ftol

A real number indicating tolerance on the difference of two subsequent loglikelihood values.

gtol

A real number indicating tolerance on norm of the gradient.

weights

Optional vector of (positive) frequency weights, one for each observation.

ncores

An integer indicating number of processors allowed for Hessian calculations.

na.rm

a logical variable which indicates whether rows of the data frame containing NAs will be removed.

print.level

An integer which controls the amount of information to be printed during execution.

linDepTol

Tolerance for detecting linear dependence between columns in input data. Dependent columns are removed from the estimation.

...

Currently unused.

object

A fitted mnlogit object.

newdata

A data.frame object to used for prediction.

probability

If TRUE predict output the probability matrix, otherwise the chocice with the highest probability for each observation is returned.

as.list

Returns estimated model coefficients grouped by variable type.

Value

An object of class mnlogit, with elements:

coeff

the named vector of coefficients.

probabilities

the probability matrix: (i,j) entry denotes the probability of the jth choice being choosen in the ith observation.

residuals

the named vector of residuals which is the probability of not choosing the alternative which was chosen.

logLik

the value of the log-likelihood function at exit.

df

the number of parameters in the model.

gradient

the gradient of the log-likelihood function at exit.

hessian

the Hessian of the log-likelihood function at exit.

AIC

the AIC value of the fitted model.

formula

the formula specifying the model.

data

the data.frame used in model estimation.

choices

the vector of alternatives.

freq

the frequencies of alternatives.

model.size

Information about number of parameters in model.

est.stat

Newton Raphson stats.

freq

the frequency of each choice in input data.

call

the mnlogit function call that user made,

Note

1. The data must be in the 'long' format. This means that for each observation there must be as many rows as there are alternatives (which should be grouped together).

2. The formula should be specified in the format: responseVar ~ choice specific variables with generic coefficients | individual specific variables | choice specific variables with choice specific coefficients. These are the 3 available variable types.

3. Any type of variables may be omitted. To omit use "1" as a placeholder.

4. An alternative specific intercept is included by default in the estimation. To omit it, use a '-1' or '0' anywhere in the formula.

Author(s)

Wang Zhiyu, Asad Hasan

References

Croissant, Yves. Estimation of multinomial logit models in R: The mlogit Packages. http://cran.r-project.org/web/packages/mlogit/index.html

Train, K. (2004) Discrete Choice Methods with Simulation, Cambridge University Press.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  library(mnlogit)

  data(Fish, package = "mnlogit")

  fm <- formula(mode ~ price | income | catch)
  result <- mnlogit(fm, Fish, "alt", ncores = 2)
  predict(result)

 ## Not run: 

  print(result)
  print(result$est.stats)
  print(result$model.size)
  summary(result)
  
  # Formula examples (see also Note)
  fm <- formula(mode ~ 1 | income) # Only type-2 with intercept
  fm <- formula(mode ~ price - 1) # Only type-1, no intercept
  fm <- formula(mode ~ 1 | 1 | catch) # Only type-3, including intercept 

  
## End(Not run)

floswald/mnlogit documentation built on Dec. 24, 2019, 7:04 p.m.