Ordinal Logistic Regression for Ordered Categorical Dependent Variables
Use the ordinal logit regression model if your dependent variable is ordered and categorical, either in the form of integer values or character strings.
First load packages:
library("Zelig")
library("ZeligChoice")
With reference classes:
z5 <- zologit$new()
z5$zelig(as.factor(Y) ~ X1 + X2, data = mydata)
z5$setx()
z5$sim()
With the Zelig 4 compatibility wrappers:
z.out <- zelig(as.factor(Y) ~ X1 + X23,
model = "ologit", data = mydata)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out, x1 = NULL)
If Y takes discrete integer values, the as.factor() command will order automatically order the values. If Y takes on values composed of character strings, such as “strongly agree”, “agree”, and “disagree”, as.factor() will order the values in the order in which they appear in Y. You will need to replace your dependent variable with a factored variable prior to estimating the model through zelig(). See Section [factors] for more information on creating ordered factors and Example [ord.fact] below.
Load the sample data:
data(sanction)
Create an ordered dependent variable:
sanction$ncost <- factor(sanction$ncost, ordered = TRUE,
levels = c("net gain", "little effect", "modest loss", "major loss"))
Estimate the model:
z.out <- zelig(ncost ~ mil + coop, model = "ologit",
data = sanction)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
## William N. Venables, and Brian D. Ripley. 2011.
## ologit: Ordinal Logit Regression for Ordered Categorical Dependent Variables
## in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
## "Zelig: Everyone's Statistical Software," http://zeligproject.org/
Summarize estimated paramters:
summary(z.out)
## Model:
## Call:
## z5$zelig(formula = ncost ~ mil + coop, data = sanction)
##
## Coefficients:
## Value Std. Error t value
## mil -0.00131 0.732 -0.00179
## coop 1.04055 0.262 3.96607
##
## Intercepts:
## Value Std. Error t value
## net gain|little effect 1.260 0.482 2.617
## little effect|modest loss 3.936 0.698 5.636
## modest loss|major loss 5.609 0.899 6.236
##
## Residual Deviance: 153.07
## AIC: 163.07
## Next step: Use 'setx' method
Set the explanatory variables to their observed values:
x.out <- setx(z.out)
Simulate fitted values given x.out and view the results:
s.out <- sim(z.out, x = x.out)
summary(s.out)
##
## sim x :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## net gain 0.3498 0.0555 0.3464 2.49e-01 0.458
## little effect 0.4944 0.1517 0.5225 1.63e-01 0.711
## modest loss 0.0831 0.0697 0.0705 8.95e-06 0.244
## major loss 0.0727 0.1102 0.0180 6.76e-09 0.384
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 1.91 0.842 2 1 4
plot(s.out)
Graphs of Quantities of Interest for Ordered Logit
Using the sample data sanction, estimate the empirical model and returning the coefficients:
z.out <- zelig(as.factor(cost) ~ mil + coop, model = "ologit",
data = sanction)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
## William N. Venables, and Brian D. Ripley. 2011.
## ologit: Ordinal Logit Regression for Ordered Categorical Dependent Variables
## in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
## "Zelig: Everyone's Statistical Software," http://zeligproject.org/
summary(z.out)
## Model:
## Call:
## z5$zelig(formula = as.factor(cost) ~ mil + coop, data = sanction)
##
## Coefficients:
## Value Std. Error t value
## mil -0.00131 0.732 -0.00179
## coop 1.04055 0.262 3.96607
##
## Intercepts:
## Value Std. Error t value
## 1|2 1.260 0.482 2.617
## 2|3 3.936 0.698 5.636
## 3|4 5.609 0.899 6.236
##
## Residual Deviance: 153.07
## AIC: 163.07
## Next step: Use 'setx' method
Set the explanatory variables to their means, with coop set to 1 (the lowest value) in the baseline case and set to 4 (the highest value) in the alternative case:
x.low <- setx(z.out, coop = 1)
x.high <- setx(z.out, coop = 4)
Generate simulated fitted values and first differences, and view the results:
s.out2 <- sim(z.out, x = x.low, x1 = x.high)
summary(s.out2)
##
## sim x :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## 1 0.5492 0.0689 0.55423 4.05e-01 0.677
## 2 0.3568 0.0808 0.36539 1.59e-01 0.493
## 3 0.0492 0.0475 0.03584 4.67e-05 0.165
## 4 0.0448 0.0765 0.00816 1.65e-08 0.268
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 1.64 0.83 1 1 4
##
## sim x1 :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## 1 0.0607 0.0382 0.0523 1.57e-02 0.158
## 2 0.4600 0.2831 0.4043 8.12e-02 0.974
## 3 0.2319 0.1556 0.2114 3.94e-03 0.579
## 4 0.2475 0.2498 0.1570 1.11e-06 0.758
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 2.71 0.904 3 1 4
## fd
## mean sd 50% 2.5% 97.5%
## 1 -0.488 0.0841 -0.4937 -6.36e-01 -0.311
## 2 0.103 0.2473 0.0232 -2.20e-01 0.605
## 3 0.183 0.1470 0.1660 -1.46e-02 0.504
## 4 0.203 0.1929 0.1450 1.09e-06 0.582
plot(s.out2)
Graphs of Quantities of Interest for Ordered Logit
Let be the ordered categorical dependent variable for
observation that takes one of the integer values from
to where is the total number of
categories.
The stochastic component begins with an unobserved continuous variable, , which follows the standard logistic distribution with a parameter ,
to which we add an observation mechanism
where (for ) are the threshold parameters with for all and and .
The systematic component has the following form, given the
parameters and , and the explanatory
variables :
which implies:
The expected values (qi$ev) for the ordinal logit model are simulations of the predicted probabilities for each category:
given a draw of from its sampling distribution.
The predicted value (qi$pr) is drawn from the logit distribution described by , and observed as one of discrete outcomes.
The difference in each of the predicted probabilities (qi$fd) is given by
In conditional prediction models, the average expected treatment effect (att.ev) for the treatment group is
where is a binary explanatory variable defining the treatment () and control () groups, and is the number of treated observations in category .
In conditional prediction models, the average predicted treatment effect (att.pr) for the treatment group is
where is a binary explanatory variable defining the treatment () and control () groups, and is the number of treated observations in category .
The output of each Zelig command contains useful information which you may view. For example, if you run z.out <- zelig(y ~ x, model = ologit, data), then you may examine the available information in z.out by using names(z.out), see the coefficients by using z.out$coefficients, and a default summary of information through summary(z.out). Other elements available through the $ operator are listed below.
The ordinal logit model is part of the MASS package by William N. Venable and Brian D. Ripley. Advanced users may wish to refer to help(polr).
Venables WN and Ripley BD (2002). Modern Applied Statistics with S, Fourth edition. Springer, New York. ISBN 0-387-95457-0, <URL: http://www.stats.ox.ac.uk/pub/MASS4>.