Learn R Programming

mets (version 1.3.11)

mlogit: Multinomial Regression Based on phreg

Description

Fits a multinomial regression model for a categorical outcome with \(K\) levels: $$ P_i = \frac{ \exp( X^\top \beta_i ) }{ \sum_{j=1}^K \exp( X^\top \beta_j ) } $$ for \(i=1, \dots, K\), where \(\beta_1 = 0\) (baseline category).

Usage

mlogit(formula, data, offset = NULL, weights = NULL, fix.X = FALSE, ...)

Value

An object of class "mlogit" (extending "phreg") containing:

coef

Matrix of estimated coefficients (rows correspond to categories, columns to covariates).

var

Robust variance-covariance matrix.

iid

Influence functions for the coefficients.

nlev

Number of levels in the outcome.

px

Number of covariates.

Arguments

formula

Formula with the outcome (similar to coxph). The outcome must be a factor.

data

Data frame containing the variables.

offset

Offsets for the partial likelihood.

weights

Weights for the score equations.

fix.X

Logical; if TRUE, forces the same coefficients for all categories (except intercepts).

...

Additional arguments passed to lower-level functions.

Author

Thomas Scheike

Details

This ensures that \(\sum_j P_j = 1\). The model is fitted using the phreg function by expanding the data into a long format with strata for each category.

The coefficients represent the log-Relative-Risk (log-RR) relative to the baseline group (the first level of the factor, which can be reset using relevel).

Standard errors are computed based on the sandwich form: $$ D U^{-1} \left( \sum U_i^2 \right) D U^{-1} $$ where \(U\) is the score vector and \(D\) is the derivative matrix.

Influence functions (possibly robust) can be obtained via the iid() function. The response variable should be a factor.

Can also fit a cumulative odds model as a special case of interval_logitsurv_discrete.

Examples

Run this code
data(bmt)
bmt$id <- sample(200,408,replace=TRUE)
dfactor(bmt) <- cause1f~cause
drelevel(bmt,ref=3) <- cause3f~cause
dlevels(bmt)

mreg <- mlogit(cause1f~+1+cluster(id),bmt)
summary(mreg)
head(iid(mreg))
dim(iid(mreg))

mreg <- mlogit(cause1f~tcell+platelet,bmt)
summary(mreg)
head(iid(mreg))
dim(iid(mreg))

mreg3 <- mlogit(cause3f~tcell+platelet,bmt)
summary(mreg3)

## inverse information standard errors 
lava::estimate(coef=mreg3$coef,vcov=mreg3$II)

## predictions based on seen response or not 
## all probabilities
head(predict(mreg,response=FALSE))
head(predict(mreg))
## using newdata 
newdata <- data.frame(tcell=c(1,1,1),platelet=c(0,1,1),cause1f=c("2","2","0"))
## only probability of seen response 
predict(mreg,newdata)
## without response
predict(mreg,newdata,response=FALSE)
## given indexx of P(Y=j)
predict(mreg,newdata,Y=c(1,2,3))
##  reponse not given 
newdata <- data.frame(tcell=c(1,1,1),platelet=c(0,1,1))
predict(mreg,newdata)

Run the code above in your browser using DataLab