Built using Zelig version r packageVersion("Zelig")
knitr::opts_knit$set( stop_on_error = 2L ) knitr::opts_chunk$set( fig.height = 11, fig.width = 7 )
Multinomial Logistic Regression for Dependent Variables with Unordered Categorical Values with mlogit
in ZeligChoice.
Use the multinomial logit distribution to model unordered categorical variables. The dependent variable may be in the format of either character strings or integer values. See Multinomial Bayesian Logistic Regression for a Bayesian version of this model.
First load packages:
library(zeligverse)
z.out <- zelig(as.factor(Y) ~ X1 + X23, model = "mlogit", data = mydata) x.out <- setx(z.out) s.out <- sim(z.out, x = x.out, x1 = NULL)
where Y above is supposed to be a factor variable with levels apples,bananas,oranges. By default, oranges is the last level and omitted. (You cannot specify a different base level at this time.) For $J$ equations, there must be $J + 1$ levels.
rm(list=ls(pattern="\\.out")) set.seed(1234)
Load the sample data:
data(mexico)
Estimate the empirical model:
z.out1 <- zelig(as.factor(vote88) ~ pristr + othcok + othsocok, model = "mlogit", data = mexico, cite = FALSE)
Summarize estimated paramters:
summary(z.out1)
Set the explanatory variables to their default values, with $pristr$ (for the strength of the PRI) equal to 1 (weak) in the baseline values, and equal to 3 (strong) in the alternative values:
x.weak <- setx(z.out1, pristr = 1) x.strong <- setx(z.out1, pristr = 3)
Generate simulated predicted probabilities qi$ev
and differences in the predicted probabilities qi$fd
:
s.out.mlogit <- sim(z.out1, x = x.strong, x1 = x.weak) summary(s.out.mlogit)
plot(s.out.mlogit)
Let $Y_i$ be the unordered categorical dependent variable that takes one of the values from 1 to $J$, where $J$ is the total number of categories.
$$ Y_i \; \sim \; \textrm{Multinomial}(y_{i} \mid \pi_{ij}), $$
where $\pi_{ij}=\Pr(Y_i=j)$ for $j=1,\dots,J$.
$$ \pi_{ij}\; = \; \frac{\exp(x_{i}\beta_{j})}{\sum^{J}{k = 1} \exp(x{i}\beta_{k})}, $$
where $x_i$ is the vector of explanatory variables for observation $i$, and $\beta_j$ is the vector of coefficients for category $j$.
$$ E(Y) \; = \; \pi_{ij}\; = \; \frac{\exp(x_{i}\beta_{j})}{\sum^{J}{k = 1} \exp(x{i}\beta_{k})}. $$
The predicted value (qi$pr) is a draw from the multinomial distribution defined by the predicted probabilities.
The first difference in predicted probabilities (qi$fd), for each category is given by:
$$ \textrm{FD}_j = \Pr(Y=j \mid x_1) - \Pr(Y=j \mid x) \quad {\rm for} \quad j=1,\dots,J. $$
$$ \frac{1}{n_j}\sum_{i:t_i=1}^{n_j} \left{ Y_i(t_i=1) - E[Y_i(t_i=0)] \right}, $$
where $t_{i}$ is a binary explanatory variable defining the treatment ($t_{i}=1$) and control ($t_{i}=0$) groups, and $n_j$ is the number of treated observations in category $j$.
$$ \frac{1}{n_j}\sum_{i:t_i=1}^{n_j} \left{ Y_i(t_i=1) - \widehat{Y_i(t_i=0)} \right}, $$
where $t_{i}$ is a binary explanatory variable defining the treatment ($t_{i}=1$) and control ($t_{i}=0$) groups, and $n_j$ is the number of treated observations in category $j$.
The Zelig object stores fields containing everything needed to rerun the Zelig output, and all the results and simulations as they are generated. In addition to the summary commands demonstrated above, some simply utility functions (known as getters) provide easy access to the raw fields most commonly of use for further investigation.
If the zelig()
call output object is z.out
, then coef(z.out)
returns
the estimated coefficients, vcov(z.out)
returns the estimated covariance
matrix, and predict(z.out)
provides predicted values for all observations
in the dataset from the analysis.
The multinomial logit function is part of the VGAM package by Thomas
Yee. In addition, advanced users may wish to refer to help(vglm)
in the VGAM package
z5 <- zmlogit$new() z5$references()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.