%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Filename: template.Rnw
%   Author: Paul Johnson
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[10pt,english]{beamer}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{url}
\usepackage{graphicx}
\usepackage{babel}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\usepackage{Sweavel}
 \newenvironment{topcolumns}{\begin{columns}[t]}{\end{columns}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multicol}

% use 'handout' to produce handouts
%\documentclass[handout]{beamer}
\usepackage{wasysym}
\usepackage{pgfpages}
\newcommand{\vn}[1]{\mbox{{\it #1}}}\newcommand{\vb}{\vspace{\baselineskip}}\newcommand{\vh}{\vspace{.5\baselineskip}}\newcommand{\vf}{\vspace{\fill}}\newcommand{\splus}{\textsf{S-PLUS}}\newcommand{\R}{\textsf{R}}


\usepackage{graphicx}
\usepackage{listings}
\lstset{tabsize=2, breaklines=true,style=Rstyle}
%\usetheme{Warsaw}
% or ...

%\setbeamercovered{transparent}
% or whatever (possibly just delete it)

\usetheme{Antibes}


%Switch comment character to turn on/off \pause commands given as \pausealt
%\newcommand{\pausealt}{\par }
\newcommand{\pausealt}{\pause}


\usepackage{color}
\definecolor{gray1}{gray}{0.75}

\newlength{\figurewidth}
\figurewidth \textwidth  % This is for rectangular graphs
\newlength{\figurewidthB}
\figurewidthB .7\textwidth  % This is for square graphs


\expandafter\def\expandafter\insertshorttitle\expandafter{%
  \insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber}

%=============================================================================


\title[Regression Methods]
{R Regression Methods}

\subtitle{Interrogate R Output Objects}

\author[Johnson] {Paul E. Johnson}

\institute[University of Kansas]{Center for Research Methods and Data Analysis \\ University of Kansas}

\date[2012]{2012}

\subject{regression}

%====================================

\begin{document}


% In document Latex options:
\fvset{listparameters={\setlength{\topsep}{0em}}}

\def\Sweavesize{\scriptsize}
\def\Rcolor{\color{black}}
\def\Rbackground{\color[gray]{0.95}}

\input{plots/t-Roptions}



\begin{frame}
  \titlepage
\end{frame}



\begin{frame}
\frametitle{Outline}

\tableofcontents{}

\end{frame}

%==================================================

\section{Methods}
\begin{frame}[containsverbatim]
  \frametitle{Methods: Things To Do ``To'' a Regression Object}





\input{plots/t-glm10}

\begin{description}
  \item [pres04] Kerry,  Bush
  \item [partyid]  Factor with 7 levels, SD $\rightarrow$ SR
  \item [sex]    Male, Female
  \item [owngun] Yes, No
\end{description}
\end{frame}

\begin{frame}[containsverbatim]
  \frametitle{Just for the Record, The Data Preparation Steps Were $\ldots$}

\input{plots/t-gssdata10}
\end{frame}


\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{First, Find Out What You Got}


\input{plots/t-glm12}

\end{frame}


\begin{frame}[containsverbatim]
  \frametitle{Understanding attributes}
  \begin{itemize}
  \item If  you see \$, it means you have an S3 object
  \item That means you can just ``take'' values out of the object with
    the dollar sign operator using commands like

\input{plots/t-glm15}
  \end{itemize}
\end{frame}

\begin{frame}[containsverbatim]
  \frametitle{R Core Team Warns against \$ Access}
  \begin{itemize}
  \item A usage like this works

\input{plots/t-009}

 \item But it might not work in the future, if the internal contents
   of the glm object were to change

 \item We should instead use the "extractor method"

\input{plots/t-010}
  \item Challenge: finding/remembering the extractor functions.
  \item Especially difficult because some VERY important extractor
    functions don't show up using usual methods of searching for them
    (AIC, coefficients)
  \end{itemize}
\end{frame}


\begin{frame}[containsverbatim]
  \frametitle{Double-Check the glm Object's Class}

  \begin{itemize}
  \item Ask the object what class it is from

\input{plots/t-methods05}

  \end{itemize}
\end{frame}


\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{Ask R What Methods are declared to apply to a ``glm'' Object}

\input{plots/t-methods10}

\end{frame}



\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{Check methods for ``lm'' class}

\input{plots/t-013}

\end{frame}



%%% Commented out 2012-06-06 before brief impromptu presentation
% \begin{frame}[containsverbatim]
%   \frametitle{Do You Wonder How ``They'' Do ``That''?}
%   \begin{itemize}

%     \item At some point, you realize that the help page is not
%       detailed enough.  You may need to see the Actual Code

%     \item Darth said ``Use the Source, Luke!''

%       If you want to know ``what a function does'', the
%       best option is to download the ACTUAL SOURCE CODE and read it!
%     \end{itemize}
% \end{frame}


% \begin{frame}[containsverbatim]
%   \frametitle{Can See Some Code Within an R Session}
%   \begin{itemize}
%   \item In the ``old days'', you could easily see a function's
%       ``code'' by typing its name (i.e., omit the parentheses).

%       Ex: q used to show all of the steps in shutting down.

%     \item Today, in R 2.11, when I type q I see:

% \begin{Schunk}\begin{Soutput}
% > q
% function (save = "default", status = 0, runLast = TRUE)
% .Internal(quit(save, status, runLast))
% <environment: namespace:base>
%   \end{Soutput}
% \end{Schunk}

% \end{itemize}
% \end{frame}

% \begin{frame}[containsverbatim]
%   \frametitle{Some Functions Still Show Their Code}
%   \begin{itemize}

%    \item Some very informative examples. Try:
%       \begin{itemize}
%         \item \texttt{ > lm \#(or stats::lm)}
%         \item \texttt{ > glm \#(or stats::glm)}
%         \item \texttt{ > termplot}
%       \end{itemize}

%     \item Generic method output not so useful. Try:
%       \begin{itemize}
%       \item \texttt{ > predict}
%       \item \texttt{ > plot}
%       \end{itemize}

%     \end{itemize}
%   \end{frame}


\begin{frame}
  \frametitle{Looking Into the Class Hierarchy}
  \begin{itemize}

  \item Functions are always located inside packages.  With R, several
    packages are supplied and are automatically searched for methods.

   \item Read the source code for some of  your favorite functions.

\input{plots/t-014}

   \item For functions in packages that are loaded, typing its name
   (without telling R what package it lives in) will show its contents.
 \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Functions, Methods and Hidden Methods}
  \begin{itemize}
  \item Methods are ALSO FOUND if we ask for them explicitly
    with their namespace (and two colons)..

\input{plots/t-015}
   Result should be identical to previous code.

 \item Hidden methods: Functions that are not ``exported'' by the package writer remain hidden

 \item functions used by package author, but they don't want create
   confusion by having users access them directly

 \item You can see code for hidden methods if you use three colons.

\input{plots/t-016}
\end{itemize}

\end{frame}

% ______________________________

\section{Interrogate Models}


\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{The First Method Used is usually \texttt{summary()}}

\input{plots/t-sum20}

\end{frame}


\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{Summary Object}

  Create a Summary Object
\input{plots/t-sum30}

 My deviance is

\input{plots/t-sum40}

\end{frame}


\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{The coef Enigma}

  \begin{itemize}
  \item \texttt{coef()} is the same as \texttt{coefficients()}

  \item Note the Bizarre Truth:
    \begin{enumerate}
    \item that the ``coef'' function returns
something different when it is applied to a model object
\input{plots/t-sum45}

Than is returned from a summary object.

\input{plots/t-sum50}
\end{enumerate}
\end{itemize}
\end{frame}






\begin{frame}[containsverbatim, allowframebreaks]
  \frametitle{\texttt{anova()}}
  \begin{itemize}
    \item You can apply \texttt{anova()} to just one model
    \item That gives a ``stepwise'' series of comparisons (not very useful)

\input{plots/t-anova10}
\end{itemize}
\end{frame}

% _____________________________

\begin{frame}
  \frametitle{But anova Very Useful to Compare 2 Models}

  Here's the basic procedure:

  \begin{enumerate}
  \item Fit 1 big model, ``mod1''
  \item Exclude some variables to create a smaller model, ``mod2''
  \item Run \texttt{anova()} to compare:

      anova(mod1, mod2, test=''Chisq'')

   \item If resulting test statistic is far from 0, it means the big
     model really is better and you should keep those variables in there.
   \end{enumerate}

   Quick Reminder:

   \begin{itemize}
   \item In an OLS model, this is would be an F test for the
     hypothesis that the coefficients for omitted parameters are all
     equal to 0.
   \item In a model estimated by maximum likelihood, it is a
     likelihood ratio test with df= number of omitted parameters.
   \end{itemize}
 \end{frame}


% ______________________________

\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{But there's an anova ``Gotcha''}


\begin{Schunk}
  \begin{Soutput}
> anova(bush0, bush1, test="Chisq")
Error in anova.glmlist(c(list(object), dotargs),
  dispersion = dispersion,  :
  models were not all fitted to the same size of dataset
\end{Soutput}
\end{Schunk}

  What the Heck?
\end{frame}

% _____________________________

\begin{frame}[containsverbatim]
  \frametitle{\texttt{anova()} Gotcha, cont.}
  \begin{itemize}
    \item Explanation: Listwise Deletion of Missing Values causes this.

      Missings cause sample sizes to differ when variables change.

    \item One Solution: Fit both models on same data.
    \begin{enumerate}
      \item Fit the ``big model'' (one with most variables)

\begin{lstlisting}
mod1 <- glm(y~ x1+ x2 + x3 + (more variables), data=dat, family=binomial)
\end{lstlisting}


      \item Fit the ``smaller Model'' with the data extracted from
        the fit of the previous model (model.frame(mod1), extractor for mod1\$model) as the data frame

\begin{lstlisting}
 mod2 <- glm(y~  x3 + (some variables), data=model.frame(mod1), family=binomial)\end{lstlisting}

   \item After that, anova() will work

     \end{enumerate}
   \end{itemize}
\end{frame}

\begin{frame}[containsverbatim]
  \frametitle{Example anova()}
  \begin{itemize}


  \item Here's the big model
\input{plots/t-glm30}

 \item Here's the small model
\input{plots/t-glm31}

 \end{itemize}
 \end{frame}


%___________________________________


\begin{frame}[containsverbatim]
  \frametitle{\texttt{anova()}: The Big Reveal!}
  \begin{itemize}

  \item anova:
\input{plots/t-glmanova10}

  \item Conclusion: the big model is not statistically significantly
    better than the small model
  \item Same as: Can't reject the null hypothesis that $\beta_j$=0 for
    all omitted parameters
 \end{itemize}
\end{frame}


\begin{frame}
  \frametitle{Interesting Use of anova}
  \begin{itemize}
    \item Consider the fit for ``polviews'' in bush3 (recall
      ``extremely liberal'' is the reference category, the intercept)
    \end{itemize}


\begin{tabular}{l|ccccccc}
\hline
label:& lib. & slt. lib. & mod. & sl. con. & con. & extr. con. \tabularnewline
\hline
mle($\hat{\beta}$): & 0.41 & 1.3  & 1.8* & 2.5* & 2.6* & 3.1*\tabularnewline
\hline
se: & 0.88 & 0.83 & 0.79 & 0.83 & 0.84 & 1.2\tabularnewline
\hline
\end{tabular}

* $p \leq 0.05$

\begin{itemize}
\item I wonder: are all ``conservatives'' the same? Do we really
  need separate parameter estimates for those respondents?
\end{itemize}

\end{frame}

%______________________________

\begin{frame}[containsverbatim]
  \frametitle{Use \texttt{anova()} To Test the Recoding}

  \begin{enumerate}
    \item Make a New Variable for the New Coding
\input{plots/t-glmanova20}
\end{enumerate}

\begin{itemize}
  \item Effect is to set slight and extreme conservatives into the
    conservative category
  \end{itemize}

\end{frame}

%_________________________________

\begin{frame}[containsverbatim]
  \frametitle{Better Check newpolv}


\input{plots/t-glmanova30}

\end{frame}

%_________________________________

\begin{frame}[containsverbatim]
  \frametitle{Neat anova thing, cont.}

  \begin{enumerate}
  \item Fit a new regression model, replacing polviews with newpolv


\input{plots/t-glmanova40}
 \item Use \texttt{anova()} to test:

\input{plots/t-glmanova50}
\end{enumerate}
\begin{itemize}
\item Apparently, all conservatives really are alike :)
\item A similar test for liberals is left to the reader!
\end{itemize}
\end{frame}


%_______________________________________________


\begin{frame}[containsverbatim]
  \frametitle{\texttt{drop1} Relieves Tedium}

  \begin{itemize}
  \item \texttt{drop1()} repeats the \texttt{anova()} procedure,
    removing each variable one-at-a-time.

\input{plots/t-033}

   \item Recall ``Chisq'' $\Leftrightarrow$ L.L.R test.
   \end{itemize}
 \end{frame}



\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{Variance-Covariance Matrix of $\hat{\beta}$}
\input{plots/t-034}

These will match the ``SE'' column in the summary of bush1
\input{plots/t-035}
\end{frame}



\begin{frame}[containsverbatim]
  \frametitle{Heteroskedasticity-consistent Standard Errors?}

  Variants of the
  Huber-White ``heteroskedasticity-consistent'' (slang: robust)
  covarance matrix are available in ``car'' and ``sandwich''.

  \begin{itemize}

    \item  hccm() in car works for linear models only

    \item vcovHC in the ``sandwich'' package returns a matrix of
      estimates. One should certainly read ?vcovHC and the associated literature.

\input{plots/t-036}
\end{itemize}
\end{frame}


\begin{frame}[containsverbatim]
  \frametitle{The heteroskedasticity consistent standard errors of the $\hat{\beta}$  are:}

\input{plots/t-037}
\end{frame}



\begin{frame}[containsverbatim,allowframebreaks]
  \frametitle{Compare those:}

\begin{columns}
  \column{3cm}

The HC and ordinary standard errors are almost identical:
  \column{8cm}
\input{plots/t-038}
\includegraphics{plots/t-038}
\end{columns}

\end{frame}

\begin{frame}[containsverbatim, allowframebreaks]
  \frametitle{Multicollinearity Diagnostics}

  \begin{itemize}
    \item VIF (Variance Inflation Factors) available in ``car''
    \item rockchalk has ``mcDiagnose''
\input{plots/t-039}
\end{itemize}
\end{frame}

%___________________________________

\begin{frame}[containsverbatim]
\frametitle{plot.lm (plot.glm) produces Diagnostics}

  Run plot() on the model object for a quick diagnostic analysis.

  Example:
\input{plots/t-040}


%%<<echo=T,include=F>>=


\end{frame}

\begin{frame}
  \frametitle{Here's a Scatterplot with OLS Fit}

\includegraphics[width=8cm]{plots/t-olsabline10}
\end{frame}


\begin{frame}
  \frametitle{Output from plot(myolsmod)}

\includegraphics[width=9cm]{plots/t-diag09}

\end{frame}


\begin{frame}[plain]
  \frametitle{Output from plot.glm Difficult To Read}

\includegraphics[width=9cm]{plots/t-diag10}

\end{frame}




\begin{frame}[containsverbatim,allowframebreaks]
   \frametitle{\texttt{influence()} Function Digs up the Diagnostics}

\input{plots/t-ib10}
\end{frame}

\begin{frame}[containsverbatim,allowframebreaks]
 \frametitle{\texttt{influence.measures()} A bigger collection of influence measures}

 From influence.measures, DFBETAS for each parameter, DFFITS, covariance ratios, Cook's distances and the diagonal elements of the hat matrix.


\input{plots/t-imb10}

     Can get component columns directly with 'dfbetas', 'dffits', 'covratio' and 'cooks.distance'.
\end{frame}



\begin{frame}[containsverbatim,allowframebreaks]
 \frametitle{But if You Want dfbeta, Not dfbetas, Why Not Ask?}


\input{plots/t-047}

      I wondered what dfbetas does. You can see for yourself. Look at
      the code. Run:

\begin{Schunk}\begin{Soutput}
    >  stats:::dfbetas.lm
  \end{Soutput}
\end{Schunk}

\end{frame}


% _____________________________________________

\begin{frame}
  \frametitle{\texttt{predict()} with newdata}

  \begin{itemize}
    \item If you run this:

      \texttt{predict(bush5)}

    R calculates $X\hat{\beta}$, a ``linear predictor'' value for each row in your dataframe

  \item See ``\texttt{?predict.glm}.''

  \item We ask for predicted probabilities like so

    \texttt{predict(bush5, type="response")}

    and you still get one prediction for each line in the data.
  \end{itemize}
\end{frame}



\begin{frame}[containsverbatim]
  \frametitle{Use predict to calculate with ``for example'' values}
  \begin{itemize}
  \item Create ``example'' dataframes and get probabilities for
    hypothetical cases.

    \begin{Schunk}
    \begin{Sinput}
      mydf <- # Pretend there are some commands, for example
    \end{Sinput}
  \end{Schunk}
\item Run that new example data frame through the predict function

\input{plots/t-048}

\end{itemize}
\end{frame}



%%  Commented-out 2012-06-06 to shorten presentation

% \begin{frame}[containsverbatim]
%   \frametitle{Create the New Data Frame}

% <<predict10, echo=T,include=F>>=
% nd <- bush5$model
% colnames(nd)
% mynewdf <- expand.grid(levels(nd$partyid), levels(nd$newpolv))
% colnames(mynewdf) <- c("partyid","newpolv")
% mynewdf$sex <- levels(nd$sex)[1]
% mynewdf$owngun <- levels(nd$owngun)[1]
% mynewdf$race <- levels(nd$race)[1]
% mynewdf$wrkslf <- levels(nd$wrkslf)[1]
% mynewdf$realinc <- mean(nd$realinc)
% mynewdf$newpred <- predict(bush5, newdata=mynewdf, type="response")
% levels(mynewdf$newpolv) <- c("Ex.L","L","SL","M","C")
% @
% \footnotesize{
% \input{plots/t-predict10}
% }

% \end{frame}

% \begin{frame}[containsverbatim]
%   \frametitle{Make Table of Predicted Probabilities}
% <<predict20,include=F,echo=T>>=
% library(gdata)
% newtab <- aggregate.table(mynewdf$newpred, by1=mynewdf$partyid, by2=mynewdf$newpolv, FUN=I)
% @

% \input{plots/t-predict20}

% <<predict30, echo=F,results=tex>>=
% library(memisc)
% toLatex(newtab)
% @
% \end{frame}

% \begin{frame}
%   \frametitle{Or Perhaps You Would Like A Figure?}

% <<pred90,fig=T,include=F>>=
% prebynewpol <- unstack(mynewdf, newpred~newpolv)
% matplot(prebynewpol,type="l",xaxt="n",xlab="Political Party Identification", ylab="Pred. Prob(Bush)")
% axis(1, at=1:7, labels=c("SD","D","ID","I","IR","R","SR"))
% legend("topleft", legend=c("Extreme Liberal","Liberal","Slight Liberal","Moderate","Conservative"),col=1:5,lty=1:5)
% @

% \includegraphics[width=10cm]{plots/t-pred90}
% \end{frame}


% \begin{frame}[containsverbatim]
%   \frametitle{How Could You Make That Figure?}

%   \input{plots/t-pred90}
% \end{frame}

% %===================================================



\begin{frame}[containsverbatim]
  \frametitle{Termplot: Plotting The Linear Predictor}


\input{plots/t-termplot10}
\includegraphics[width=10cm]{plots/t-termplot10}
\end{frame}


\begin{frame}[containsverbatim]
  \frametitle{Termplot: Some of the Magic is Lost on a Logistic Model}


\input{plots/t-termplot20}
\includegraphics[width=10cm]{plots/t-termplot20}
\end{frame}



\begin{frame}[containsverbatim]
  \frametitle{Termplot: But If You Had Some Continuous Data, Watch Out!}

\input{plots/t-termplot30}
\includegraphics[width=10cm]{plots/t-termplot30}
\end{frame}




\begin{frame}[containsverbatim]
  \frametitle{\texttt{termplot()} works because $\ldots$}

  \begin{itemize}
  \item termplot doesn't make calculations, it uses the
    ``\texttt{predict}'' method associated with a model object.
  \item \texttt{predict} is a generic method, it doesn't do any work either!
  \item Actual work gets done by methods for models,
    \texttt{predict.lm} or  \texttt{predict.glm}.
  \item You can leave out the ``terms'' option, termplot will
    cycle through all of the predictors in the model.
  \end{itemize}
\end{frame}

\begin{frame}[containsverbatim]
  \frametitle {Why Termplot is Not the End of the Story}
  \begin{itemize}
  \item Termplot draws $X\hat{\beta}$, the linear predictor.
  \item Maybe we want predicted probabilities instead.
  \item Maybe we want predictions for certain case types: \texttt{ termplot} allows the predict implementation to decide which
    values of the inputs will be used.
  \item A regression expert will quickly conclude that a really
    great graph may require direct use of the \texttt{predict}
    method for the model object.
  \end{itemize}
\end{frame}




% % ===================================================
% \section{Output}

% \begin{frame}[containsverbatim]
%   \frametitle{You Will Want to Use \LaTeX{}     After You See This}

%   \begin{itemize}
%     \item How do you get regression tables out of your project?
%     \item Do you go through error-prone copying, pasting, typing,
%       tabling, etc?
%     \item What if your software could produce a finished
%       publishable table?
%     \end{itemize}
%   \end{frame}

% <<echo=F, results=hide>>=
% library(rockchalk)
% @

% \begin{frame}[containsverbatim]
%   \frametitle{}
%   \begin{itemize}
%     \item Years ago, I wrote a function ``outreg''


% <<echo=T, results=hide, include=F>>=
% library(rockchalk)
% @

% <<output10,echo=T, eval=F, include=F>>=
% outreg(bush1, tight=F, modelLabels=c("Bush Logistic"))
% @


%     \item This command:

% <<output30,echo=T,eval=T,include=F>>=
% <<output10>>
% @
% \input{plots/t-output10}
%    \item Produces the output on the next slide
%   \end{itemize}
% \end{frame}

% \begin{frame}[plain,containsverbatim]

% <<output40,echo=F,include=F,results=tex>>=
% <<output10>>
% @

% \input{plots/t-output40}
% \end{frame}




% \begin{frame}[containsverbatim]
%   \frametitle{Polish that up}

%   \begin{itemize}
%     \item you can beautify the variable labels, either by specifying
%       them in the outreg command or editing the table output.
%     \item outreg produces Latex that looks like this in the R session output.

% <<output41,echo=F,include=F>>=
% <<output10>>
% @
% \input{plots/t-output41}

% \end{itemize}
% \end{frame}


% \begin{frame}
%   \frametitle{Push Several Models Into One Wide Table}

% <<output50,echo=T, eval=F, include=F>>=
% outreg(list(bush1,bush4,bush5),  modelLabels=c("bush1","bush4","bush5"))
% @
% \input{plots/t-output50}

%   Sorry, I had to split this manually across 3 slides :(

% \end{frame}


% \begin{frame}[plain,allowframebreaks]

% <<output51,echo=F,include=F,results=tex>>=
% <<output50>>
% @

% \footnotesize{
% \input{plots/t-output51}
% }
% \end{frame}

% %__________________________________


% \begin{frame}
%   \frametitle {R Packages for Producing Regression Output}

%   \begin{itemize}
%   \item memisc: works well, further from final form than outreg

%   \item xtable: incomplete output, but latex or HTML works

%   \item apsrtable: very similar to outreg

%   \item Hmisc ``latex'' function

%   \end{itemize}
% \end{frame}


% \begin{frame}[containsverbatim,allowframebreaks]

% <<output70,echo=T,results=tex>>=
% library(xtable)
% tabout1 <- xtable(bush1)
% print(tabout1, type="latex")

% @


% \end{frame}

% \begin{frame}[containsverbatim]
%   \frametitle{If you Can't Shake the MS Word ``Habit''}

%   The best you can do is HTML output, which you can copy paste-special
%   into a document.

% <<output80,echo=T>>=
% print(xtable(summary(bush1)), type="HTML")
% @
% \end{frame}

% \begin{frame}[containsverbatim,allowframebreaks]
%   \frametitle{memisc mtable is nice for comparing models (except for
%     verbosity of parameter labels)}

% <<echo=T,eval=T>>=
%  library(memisc)
%  mtable(bush1,bush4,bush5)
% @
% \end{frame}


% \begin{frame}[containsverbatim,allowframebreaks]
%   \frametitle{memisc toLatex}

% \footnotesize{
% <<output84, echo=T,results=tex>>=
% toLatex(mtable(bush1))
% @
% }
% \end{frame}

% \begin{frame}
%   \frametitle{Relable Levels to Truncate Output}

%   \begin{itemize}
%     \item We could have to edit that output A LOT


%     \item Hack the Labels down
% <<echo=T>>=
% levels(dat$partyid) <- c("SD","D","ID","I","IR","R","SR")
% levels(dat$polviews) <- c("EL","L","SL","M","SC","C","EC")
% levels(dat$newpolv) <- c("EL","L","SL","M","C")
% levels(dat$wrkslf) <- c("Yes","No")
% @

%     \item Re-run the models

% <<echo=T>>=

% bush1 <- glm(pres04 ~ partyid + sex + owngun, data=dat, family=binomial(link=logit))

%  bush3 <- glm(pres04 ~ partyid + sex + owngun + race + wrkslf + realinc + polviews , data=dat, family=binomial(link=logit))
%  bush4 <- glm(pres04 ~ partyid +  owngun + race + polviews , data=bush3$model, family=binomial(link=logit))
% bush5 <- glm(pres04 ~ partyid + sex + owngun + race + wrkslf + realinc + newpolv , data=dat, family=binomial(link=logit))
% @
% \end{itemize}
% \end{frame}

% %___________________________

% \begin{frame}[containsverbatim,allowframebreaks,plain]

% <<output85, echo=T,include=F,results=tex>>=
% toLatex(mtable(bush1,bush4,bush5))
% @
% \footnotesize{
% \input{plots/t-output85}
% }



% \end{frame}


%===================================================
\end{document}
