% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/multinomialreg.R
\name{mlogit}
\alias{mlogit}
\alias{predict}
\title{Multinomial Regression Based on phreg}
\usage{
mlogit(formula, data, offset = NULL, weights = NULL, fix.X = FALSE, ...)
}
\arguments{
\item{formula}{Formula with the outcome (similar to \code{coxph}). The outcome must be a factor.}

\item{data}{Data frame containing the variables.}

\item{offset}{Offsets for the partial likelihood.}

\item{weights}{Weights for the score equations.}

\item{fix.X}{Logical; if \code{TRUE}, forces the same coefficients for all categories (except intercepts).}

\item{...}{Additional arguments passed to lower-level functions.}
}
\value{
An object of class \code{"mlogit"} (extending \code{"phreg"}) containing:
\item{coef}{Matrix of estimated coefficients (rows correspond to categories, columns to covariates).}
\item{var}{Robust variance-covariance matrix.}
\item{iid}{Influence functions for the coefficients.}
\item{nlev}{Number of levels in the outcome.}
\item{px}{Number of covariates.}
}
\description{
Fits a multinomial regression model for a categorical outcome with \eqn{K} levels:
\deqn{ P_i = \frac{ \exp( X^\top \beta_i ) }{ \sum_{j=1}^K \exp( X^\top \beta_j ) } }
for \eqn{i=1, \dots, K}, where \eqn{\beta_1 = 0} (baseline category).
}
\details{
This ensures that \eqn{\sum_j P_j = 1}. The model is fitted using the \code{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 \code{relevel}).

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

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

Can also fit a cumulative odds model as a special case of \code{interval_logitsurv_discrete}.
}
\examples{
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)
}
\author{
Thomas Scheike
}
