\SweaveOpts{results=hide, prefix.string=vigpics/ologit}
\include{zinput}
%\VignetteIndexEntry{Ordinal Logistic Regression  for Ordered Categorical Dependent Variables}
%\VignetteDepends{Zelig, MASS}
%\VignetteKeyWords{model, logistic,regression,ordinal, ordered,categorical}
%\VignettePackage{Zelig}
\begin{document}
\nobibliography*
<<beforepkgs, echo=FALSE>>=
 before=search()
@

<<loadLibrary, echo=F,results=hide>>=
pkg <- search()
if(!length(grep("package:Zelig",pkg)))
library(Zelig)
@

\section{{\tt ologit}: Ordinal Logistic Regression for Ordered
Categorical Dependent Variables}\label{ologit}

Use the ordinal logit regression model if your dependent variable is
ordered and categorical, either in the form of integer values or character strings.  

\subsubsection{Syntax}

\begin{verbatim}
> z.out <- zelig(as.factor(Y) ~ X1 + X2, model = "ologit", data = mydata)
> x.out <- setx(z.out)
> s.out <- sim(z.out, x = x.out)
\end{verbatim}
If {\tt Y} takes discrete integer values, the {\tt as.factor()}
command will order automatically order the values.  If {\tt Y} takes
on values composed of character strings, such as ``strongly agree'',
``agree'', and ``disagree'', {\tt as.factor()} will order the values
in the order in which they appear in {\tt Y}.  You will need to
replace your dependent variable with a factored variable prior to
estimating the model through {\tt zelig()}.  See Section \ref{factors}
for more information on creating ordered factors and Example
\ref{ord.fact} below.

\subsubsection{Example}

\begin{enumerate}

\item {Creating An Ordered Dependent Variable} \label{ord.fact}

Load the sample data:  
<<Example.data>>=
 data(sanction)
@ 
Create an ordered dependent variable: 
<<Example.factor>>=
 sanction$ncost <- factor(sanction$ncost, ordered = TRUE,
                          levels = c("net gain", "little effect", 
                          "modest loss", "major loss"))
@ 
Estimate the model:
<<Example.zelig>>=
 z.out <- zelig(ncost ~ mil + coop, model = "ologit", data = sanction)
@ 
Set the explanatory variables to their observed values:  
<<Example.setx>>=
 x.out <- setx(z.out, fn = NULL)
@ 
Simulate fitted values given {\tt x.out} and view the results:
<<Example.sim>>=
 s.out <- sim(z.out, x = x.out)
@
<<Example.summary>>= 
 summary(s.out)
@ 

\item {First Differences}

Using the sample data \texttt{sanction}, estimate the empirical model and returning the coefficients:
<<FirstDifferences.zelig>>=
 z.out <- zelig(as.factor(cost) ~ mil + coop, model = "ologit", 
                 data = sanction)
@ 
<<FirstDifferences.summary>>=
summary(z.out)
@ 
Set the explanatory variables to their means, with {\tt mil} set
to 0 (no military action in addition to sanctions) in the baseline
case and set to 1 (military action in addition to sanctions) in the
alternative case:
<<FirstDifferences.setx>>=
 x.low <- setx(z.out, mil = 0)
 x.high <- setx(z.out, mil = 1)
@ 
Generate simulated fitted values and first differences, and view the results:
<<FirstDifferences.sim>>=
 s.out <- sim(z.out, x = x.low, x1 = x.high)
 summary(s.out)
@ 
\end{enumerate}

\subsubsection{Model}

Let $Y_i$ be the ordered categorical dependent variable for
observation $i$ that takes one of the integer values from $1$ to $J$
where $J$ is the total number of categories.
  
\begin{itemize}
\item The \emph{stochastic component} begins with an unobserved continuous
  variable, $Y^*_i$, which follows the standard logistic distribution
  with a parameter $\mu_i$,
  \begin{equation*}
    Y_i^* \; \sim \; \textrm{Logit}(y_i^* \mid \mu_i),  
  \end{equation*}
  to which we add an observation mechanism
  \begin{equation*}
    Y_i \; = \; j \quad {\rm if} \quad \tau_{j-1} \le Y_i^* \le \tau_j
    \quad {\rm for} \quad j=1,\dots,J.
  \end{equation*}
  where $\tau_l$ (for $l=0,\dots,J$) are the threshold parameters with
  $\tau_l < \tau_m$ for all $l<m$ and $\tau_0=-\infty$ and
  $\tau_J=\infty$.
  
\item The \emph{systematic component} has the following form, given
  the parameters $\tau_j$ and $\beta$, and the explanatory variables $x_i$: 
  \begin{equation*}
    \Pr(Y \le j) \; = \; \Pr(Y^* \le \tau_j) \; = \frac{\exp(\tau_j -
      x_i \beta)}{1+\exp(\tau_j -x_i \beta)},
  \end{equation*}
  which implies:
  \begin{equation*}
    \pi_{j}  \; = \; \frac{\exp(\tau_j - x_i \beta)}{1 + \exp(\tau_j -
      x_i \beta)} - \frac{\exp(\tau_{j-1} - x_i \beta)}{1 +
      \exp(\tau_{j-1} - x_i \beta)}.
  \end{equation*}
\end{itemize}

\subsubsection{Quantities of Interest} 

\begin{itemize}
\item The expected values ({\tt qi\$ev}) for the ordinal logit model
  are simulations of the predicted probabilities for each category: 
\begin{equation*}
E(Y = j) \; = \; \pi_{j} \; = \; \frac{\exp(\tau_j - x_i \beta)}
{1 + \exp(\tau_j - x_i \beta)} - \frac{\exp(\tau_{j-1} - x_i \beta)}{1 +
 \exp(\tau_{j-1} - x_i \beta)},
\end{equation*}
given a draw of $\beta$ from its sampling distribution.  

\item The predicted value ({\tt qi\$pr}) is drawn from the logit
  distribution described by $\mu_i$, and observed as one of $J$
  discrete outcomes.  

\item The difference in each of the predicted probabilities ({\tt
    qi\$fd}) is given by
  \begin{equation*}
    \Pr(Y=j \mid x_1) \;-\; \Pr(Y=j \mid x) \quad {\rm for} \quad
    j=1,\dots,J.
  \end{equation*}

\item In conditional prediction models, the average expected treatment
  effect ({\tt att.ev}) for the treatment group is 
    \begin{equation*} \frac{1}{n_j}\sum_{i:t_i=1}^{n_j} \left\{ Y_i(t_i=1) -
      E[Y_i(t_i=0)] \right\},
    \end{equation*} 
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$.

\item In conditional prediction models, the average predicted treatment
  effect ({\tt att.pr}) for the treatment group is 
    \begin{equation*} \frac{1}{n_j}\sum_{i:t_i=1}^{n_j} \left\{ Y_i(t_i=1) -
      \widehat{Y_i(t_i=0)} \right\},
    \end{equation*} 
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$.

\end{itemize}

\subsubsection{Output Values}

The output of each Zelig command contains useful information which you
may view.  For example, if you run \texttt{z.out <- zelig(y \~\,
  x, model = "ologit", data)}, then you may examine the available
information in \texttt{z.out} by using \texttt{names(z.out)},
see the {\tt coefficients} by using {\tt z.out\$coefficients}, and
a default summary of information through \texttt{summary(z.out)}.
Other elements available through the {\tt \$} operator are listed
below.

\begin{itemize}
\item From the {\tt zelig()} output object {\tt z.out}, you may
  extract:
   \begin{itemize}
   \item {\tt coefficients}: parameter estimates for the explanatory
     variables.
   \item {\tt zeta}: a vector containing the estimated class
     boundaries $\tau_j$.
   \item {\tt deviance}: the residual deviance.
   \item {\tt fitted.values}: the $n \times J$ matrix of in-sample
     fitted values.
   \item {\tt df.residual}: the residual degrees of freedom.
   \item {\tt edf}: the effective degrees of freedom.  
   \item {\tt Hessian}: the Hessian matrix.
   \item {\tt zelig.data}: the input data frame if {\tt save.data = TRUE}.  
   \end{itemize}

\item From {\tt summary(z.out)}, you may extract: 
   \begin{itemize}
   \item {\tt coefficients}: the parameter estimates with their
     associated standard errors, and $t$-statistics.
   \end{itemize}
   
 \item From the {\tt sim()} output object {\tt s.out}, you may extract
   quantities of interest arranged as arrays.  Available quantities
   are:

   \begin{itemize}
   \item {\tt qi\$ev}: the simulated expected probabilities for the
     specified values of {\tt x}, indexed by simulation $\times$
     quantity $\times$ {\tt x}-observation (for more than one {\tt
       x}-observation).
   \item {\tt qi\$pr}: the simulated predicted values drawn from the
     distribution defined by the expected probabilities, indexed by
     simulation $\times$ {\tt x}-observation.
   \item {\tt qi\$fd}: the simulated first difference in the predicted
     probabilities for the values specified in {\tt x} and {\tt x1},
     indexed by simulation $\times$ quantity $\times$ {\tt
       x}-observation (for more than one {\tt x}-observation).
   \item {\tt qi\$att.ev}: the simulated average expected treatment
     effect for the treated from conditional prediction models.  
   \item {\tt qi\$att.pr}: the simulated average predicted treatment
     effect for the treated from conditional prediction models.  
   \end{itemize}
\end{itemize}

\subsection* {How to Cite} 

\input{cites/ologit}
\input{citeZelig}

\subsection* {See also}
The ordinal logit model is part of the MASS package by William N. Venable and Brian D. Ripley \citep{VenRip02}. Advanced users may wish to refer to \texttt{help(polr)} as well as \cite{McCNel89}. Sample data are from \cite{Martin92}.

\bibliographystyle{asa}
\bibliography{gk,gkpubs}
<<afterpkgs, echo=FALSE>>=
 after<-search()
 torm<-setdiff(after,before)
 for (pkg in torm)
 detach(pos=match(pkg,search()))
@
 \end{document}


%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 




