% \documentclass[serif]{beamer} % Serif for Computer Modern math font. \documentclass[serif, handout]{beamer} % Handout to ignore pause statements \hypersetup{colorlinks,linkcolor=,urlcolor=red} \usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice! \setbeamertemplate{navigation symbols}{} % Suppress navigation symbols % \usetheme{AnnArbor} % Yellow and Blue: School colours \usetheme{Frankfurt} % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides % \usetheme{Berlin} % Displays sections on top % \usetheme{Berkeley} \usepackage[english]{babel} \usepackage{amsmath} % for binom % \usepackage{graphicx} % To include pdf files! % \definecolor{links}{HTML}{2A1B81} % \definecolor{links}{red} \setbeamertemplate{footline}[frame number] \mode \title{Within-cases analysis of binary responses\footnote{ This slide show is an open-source document. See last slide for copyright information.}} \subtitle{STA442/2101 Fall 2017} \date{} % To suppress date \begin{document} \begin{frame} \titlepage \end{frame} \begin{frame} \frametitle{The idea} %\framesubtitle{} \begin{itemize} \item There are several binary responses for each case. \pause \item Like was the person employed right after graduation, 6 months after, one year after \ldots Yes or No \pause \item Or did the consumer purchase at least one computer in 2016, 2017, 2018 \ldots \pause \item Binary choices in laboratory studies can be repeated measures. \pause \item Model: Logistic regression with a random shock for case, pushing all the log odds values for that case up and down by the same amount. \pause \item Random shock is added to the regression equation for the log odds. \pause \item Usually the random shock is normal --- what else? % \item Often described as a random intercept model. \end{itemize} \end{frame} \begin{frame} \frametitle{A random intercept model} \framesubtitle{For $i = 1, \ldots, n$ and $j = 1, \ldots, m$} \begin{itemize} \item $B_1, \ldots, B_n \stackrel{i.i.d.}{\sim} N(0,\sigma^2)$ \pause \item Conditionally on $B_i=b_i$ for $i = 1, \ldots, n$\pause, binary responses $y_{ij}$ are independent with \pause \begin{displaymath} \log\left(\frac{\pi_{ij}}{1-\pi_{ij}} \right) = (\beta_0 + b_{i}) + \beta_1 x_{ij1} + \ldots + \beta_{p-1} x_{ij,p-1} \end{displaymath} \pause where $\pi_{ij} = P\{y_{ij} = 1\}$. \pause \end{itemize} \vspace{3mm} Some of the $x_{ij}$ could be dummy variables for time period or treatment, different for $j = 1, \ldots, m$ within case $i$. \end{frame} \begin{frame} %\frametitle{Hand written likelihood} %\framesubtitle{} \begin{center} \includegraphics[width=4in]{Likelihood} \end{center} \end{frame} \begin{frame} \frametitle{Oops!} %\framesubtitle{} {\LARGE That last line was wrong. Write it on the board. } % End size \end{frame} \begin{frame} \frametitle{Maximum likelihood} \framesubtitle{Numerical, of course} \pause \begin{itemize} \item In principle, this is mostly straightforward. \pause \item It's all classical likelihood stuff. \pause \item We just have a random intercept in this class. \pause \item But the model can be extended to \begin{displaymath} \mathbf{w} = \mathbf{X} \boldsymbol{\beta} + \mathbf{Zb} \end{displaymath} \pause \item Where $\mathbf{w}$ is a vector of log odds. \pause \item That's what the \texttt{glmer} function in the \texttt{lme4} package does. \end{itemize} \end{frame} \begin{frame} \frametitle{There are problems} \pause %\framesubtitle{} \begin{itemize} \item Nobody can do the integral. \pause \item It's really brutal for multivariate normal $\mathbf{b}$ and complicated designs. \pause \item The approximate solutions are imperfect. \pause \item There are numerical issues\pause, even in our simple case. \pause \item For the general case, it's easy to specify models whose parameters are not identifiable. \pause \item This does not apply to us, but there is massive confusion in the user community. \end{itemize} \end{frame} \begin{frame} \frametitle{The \texttt{glmer} function in the \texttt{lme4} package} \pause %\framesubtitle{} \begin{itemize} \item Syntax is like \texttt{lmer} for linear models. \pause \item And like \texttt{glm} for generalized linear models with fixed effects. \pause \item We are going to keep it simple. \pause \item Just add \texttt{+(1|Subject)} for the random shock (intercept). \pause \item Use effect coding (\texttt{contr.sum}) if there are interactions between factors. \pause \item \texttt{Anova(model,type='III')} from the \texttt{car} package to test each effect controlling for all others. \pause \item For follow-up tests, \pause fit a no-intercept model on a combination variable \pause and test contrasts on the categories of the combination variable \pause using the \texttt{linearHypothesis} function from the \texttt{car package}. \end{itemize} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Copyright Information} This slide show was prepared by \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner}, Department of Statistics, University of Toronto. It is licensed under a \href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US} {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website: \href{http://www.utstat.toronto.edu/~brunner/oldclass/appliedf17} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/appliedf17}} \end{frame} \end{document}