Multinomial logit is a discrete choice model for modeling the association between covariates and the likelihood of observing a particular categorical outcome. Coefficients are reported in log-odds. One set of coefficients is presented for each outcome category except one. The excluded category is a reference category; all coefficients represent log-odds of the given category being selected versus the reference category. These examples assume y_mult
is a categorical variable taking at least 3 (mutually exclusive) values.
Stata uses mlogit
for multinomial models. The rrr
option presents results in relative risk ratios.
mlogit y_mult x z
mlogit y_mult x z, rrr
If you want to change the reference category, the simplest method is to add the base()
argument. If you wanted the reference category to be the value 2
of y_mult
, you could use this:
mlogit y_mult x z, base(2)
The most commonly used multinomial regression function in R is multinom
in the nnet
package. y_mult
here should be a factor.
example_mlogit <- multinom(y_mult ~ x + z,
data = example_data)
summary(example_mlogit)
broom::tidy(example_mlogit, conf.int=TRUE)
summary()
produces summary output with standard errors. You can also use broom::tidy()
to get a data frame of coefficients, standard errors, and p-values–and confidence intervals when using conf.int=TRUE
.
To get relative risk ratios, exponentiate the coefficients:
exp(coef(example_mlogit))
Note you can change the reference category of a factor using relevel()
. If your variable is y_mult
in example_data
and you want the reference category to be 2
you could use this before rerunning the model:
example_data$y_mult <- relevel(example_data$y_mult,
ref = "2")
Forthcoming
Specifying a linear hypothesis from a multinom()
object is slightly more complicated than for other models. In the hypothesis argument, you must specify the variable as outcome_level:predictor_var
. The example below is a test that the coefficient for the effect of x
likelihood of seeing category 2
is the same as the coefficient for x
on category 3
.
car::linearHypothesis(example_mult, "2:x = 3:x")
In the next example, we test whether both those coefficients are equal to zero.
car::linearHypothesis(example_mult,
c("2:x = 0", "3:x = 0")
Note the number in front is the outcome level (that is, the equation).
If you wanted to run a linear hypothesis testing whether two levels of a factor variable predictor (x_cat
) had equal estimated coefficients, and your model has four outcomes (three equations), you would use this:
example_mult <- multinom(y_mult ~ x_cat)
# See here, x_cat is split into dummies by R
car::linearHypothesis(example_mult,
c("2:x_cat1 = 2:x_cat2",
"3:x_cat1 = 3:x_cat2",
"4:x_cat1 = 4:x_cat2")
Stata has a postestimation routine for running IIA tests:
mlogtest, iia
R does not have a convenient function for running IIA tests on multinom()
models–there’s plenty for mlogit()
but it is substantially harder to use. IIA tests are generally considered unreliable tests, however, so this isn’t a real problem.
Forthcoming.
The easiest way to plot multinomial output is to use ggeffects. The code below plots the probability of observing each outcome in a range of x
from -1 to 1 with z
held at 0.
library(ggeffects)
library(dplyr)
example_mlogit %>%
ggpredict(terms = c("x [-1:1]"),
condition = c(z = 0)) %>%
plot()