mlogit: Multinomial Logistic Regression

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/functions_mlogit.R

Description

Solves a multinomial logistic problem using Newton-Raphson method

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
mlogit(
  Y,
  X,
  beta = NULL,
  add.intercept = FALSE,
  betaOnly = FALSE,
  tol.zero = 1e-08,
  verbose = T,
  suppressFittedWarning = FALSE,
  maxNR.print.level = 0,
  iterlim = 150,
  checkY = TRUE
)

Arguments

Y

A matrix of the outcomes, with K columns for the K groups. Row sums of the matrix should be equal to one, but entries do not have to be 0/1 (but they should be positive). i.e. this is a matrix of hard or soft assignments to K categories. The first column is used as the reference category.

X

matrix of covariates for regression. Should have the same number of rows (observations) as Y. Coefficients for all parameters in X are computed for K-1 groups. The coefficients corresponding to the first column of Y are assumed to be zero.

beta

starting values for the optimziation. Should be given as a matrix of column vectors, each vector a different starting value. If null, defaults to zeros.

add.intercept

a logical indicator of whether an intercept column should be added to X

betaOnly

logical indicator of whether only the parameter estimates beta should be returned. Otherwise, beta is returned along with fitted objects. See Output.

tol.zero

the tolerance threshold for considering a fitted value as equal to zero. Used for warning about fitted values of 0/1. Is NOT part of the optimization control parameters.

verbose

logical indicator that controls whether text indicating progress is output to display

suppressFittedWarning

indicator of whether or not warnings about fitted values of 1 are returned

maxNR.print.level

numeric value giving the level of output produced by maxNR. see ?maxNR for details. Defaults to 0.

iterlim

iteration limit for maxNR. Defaults to 150.

checkY

indicator for whether Y should be checked to be a valid assignment matrix. Set to FALSE if using decimal values in Y.

Details

The optimization is done using the maxNR function from the maxLik package. The log-likehood function, along with its gradient and hessian, are implemented as C++ functions (via the RcppArmadillo package).

Value

A list containing the following:

beta

a p x K matrix of parameter estimates corresponding to the K columns of Y and p covariates in X

fitted01

indicator of whether fitted values of 1 were present.

fitted

the fitted probabilities

res.best

the best result from the maxNR fit

status

small data frame summarizing the status of the fits

res. all

a list containing the results from all maxNR fits

Author(s)

Joshua Keller

See Also

predkmeans

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
n <- 2000
X <- cbind(1,
           matrix(rnorm(2*n), nrow=n, ncol=2),
           rbinom(n, size=1, prob=0.3))
beta <- cbind(rep(0, 4),
              c(0.5, 1, 0, -1),
              c(0, 2, 2, 0))
probs <- exp(X %*% beta)
probs <- probs/rowSums(probs)
Y <- t(apply(probs, 1, function(p) rmultinom(1, 1, p)))
mfit <- mlogit(Y=Y, X=X, betaOnly=TRUE)
mfit

predkmeans documentation built on Jan. 11, 2020, 9:29 a.m.