\documentclass[mathserif]{beamer} % Get Computer Modern math font.
\usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice!
\setbeamertemplate{navigation symbols}{} % Supress navigation symbols
\usetheme{Berlin} % Diplays sections on top
\usepackage[english]{babel}
\setbeamertemplate{footline}[frame number] 

\mode<presentation>
% \mode<handout>{\setbeamercolor{background canvas}{bg=black!5}}



\title{Within Cases}
\subtitle
{The Humble $t$-test} % (optional)
\date{} % To suppress date


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

\begin{frame}
\frametitle{Overview}
\tableofcontents
\end{frame}

\section{The Issue}


\begin{frame}{Independent Observations}%{Subtitles are optional.}
  % - A title should summarize the slide in an understandable fashion
  %   for anyone how does not follow everything on the slide itself.

  \begin{itemize}
    \item Most statistical models assume independent observations.
    \item Sometimes the assumption of independence is unreasonable.
    \item For example, times series and within cases designs.
  \end{itemize}
\end{frame}


\begin{frame}{Within Cases}

  \begin{itemize}
    \item A case contributes a value of the response variable for every value of a categorical explanatory variable.
    \item As opposed to explanatory variables that are \emph{Between Cases}: Explanatory variables partition the sample.
    \item It is natural to expect data from the same case to be correlated, \emph{not} independent.
    \item For example, the same subject appears in several treatment conditions
    \item Hearing study: How does pitch affect our ability to hear faint sounds? Subjects are presented with tones at a variety of different pitch and volume levels (in a random order). They press a key when they think they hear something.
     \item A study can have both within and between cases factors.
  \end{itemize}
\end{frame}


\begin{frame}{You may hear terms like}

  \begin{itemize}

    \item \textbf{Longitudinal}: The same variables are measured repeatedly over time. Usually lots of variables, including categorical ones, and large samples. If there's an experimental treatment, it�s usually once at the beginning, like a surgery. Basically it�s \emph{tracking} what happens over time.

    \item \textbf{Repeated measures}: Usually, same subjects experience two or more experimental treatments.  Usually quantitative explanatory variables and small samples.

  \end{itemize}
\end{frame}

\section{Univariate}

\begin{frame}{Student's Sleep Study (\emph{Biometrika}, 1908)}
{First Published Example of a $t$-test}

  \begin{itemize}
    \item Patients take two sleeping medicines several days apart.
    \item Half get $A$ first, half get $B$ first.
    \item Reported hours of sleep are recorded.
    \item It's natural to subtract, and test whether the mean \emph{difference} equals zero.
    \item That's what Gossett did.
    \item But some might do an independent $t$-test with $n_1=n_2$.
    \item Is it harmful?
  \end{itemize}
\end{frame}


\begin{frame}{Conclusions from an earlier discussion}
  \begin{itemize}
        \item When covariance is positive, matched $t$-test has better power
        \item Each case serves as its own control.
        \item A huge number of unknown influences are removed by subtraction. 
        \item This makes the analysis more precise.
  \end{itemize}
\end{frame}

\section{Multivariate}

\begin{frame}{Hotelling's $t^2$}{Multivariate Matched $t$-test}

  \begin{itemize}
  \item $\mathbf{X}_1, \ldots, \mathbf{X}_n \stackrel{i.i.d.}{\sim} 
  N_k(\boldsymbol{\mu},\boldsymbol{\Sigma})$
  \item $\overline{\mathbf{X}}_n = \frac{1}{n} \sum_{i=1}^n \mathbf{X}_i$ and 
  $\mathbf{S} = \frac{1}{n-1} 
  \sum_{i=1}^n \left(\mathbf{X}_i-\overline{\mathbf{X}}_n\right)
               \left(\mathbf{X}_i-\overline{\mathbf{X}}_n\right)^\prime$
  \item $t^2 = n\left(\overline{\mathbf{X}}_n - \boldsymbol{\mu}\right)^\prime
        \mathbf{S}^{-1}
                \left(\overline{\mathbf{X}}_n - \boldsymbol{\mu}\right)
        \sim T^2(k,n-1)$ 
  \item That is, $\frac{n-k}{k(n-1)}t^2 \sim F(k,n-k)$
  \item When $k=1$, reduces to the familiar $t^2=F(1,n-1)$
  \item Test $H_0: \boldsymbol{\mu} = \boldsymbol{\mu}_0$
  \end{itemize}
\end{frame}

\begin{frame}{Test \emph{Collections} of Contrasts}
             {$H_0: \mathbf{L}\boldsymbol{\mu} = \mathbf{h}$, 
             where $ \mathbf{L}$ is $r \times k$}
  \begin{itemize}
  \item $t^2 = n\left(\overline{\mathbf{X}}_n - \boldsymbol{\mu}\right)^\prime
        \mathbf{S}^{-1}
                \left(\overline{\mathbf{X}}_n - \boldsymbol{\mu}\right)
        \sim T^2(k,n-1)$, \\ so if $H_0$ is true
        \item $t^2 = n\left(\mathbf{L}\overline{\mathbf{X}}_n - 
        \mathbf{h}\right)^\prime
        \left(\mathbf{LSL}^\prime\right)^{-1}
                      \left(\mathbf{L}\overline{\mathbf{X}}_n - 
        \mathbf{h}\right)
        \sim T^2(r,n-1)$
        \item Could also calculate contrast variables, like differences.
            \begin{itemize}
                \item Expected value of the contrast is the contrast of expected values.
                \item Just test (simultaneously) whether the means of the contrast variables are zero, using the first formula.
            \end{itemize}
        \item For 2 or more within-cases factors, use contrasts to test for main effects, interactions.
  \end{itemize}
\end{frame}

\begin{frame}{Compare Wald-like tests}
Recall
  \begin{itemize}
  \item If $\mathbf{Y}_n = \sqrt{n}(\mathbf{T}_n-\boldsymbol{\theta}) \stackrel{d}{\rightarrow}
\mathbf{Y} \sim N_k(\mathbf{0},\boldsymbol{\Sigma})$, then
\begin{eqnarray*}
    W_n & = & n (\mathbf{LT}_n-\mathbf{h})^\prime
        \left(  \mathbf{L}\widehat{\boldsymbol{\Sigma}}_n\mathbf{L}^\prime
        \right)^{-1}
        (\mathbf{LT}_n-\mathbf{h}) \stackrel{d}{\rightarrow} W \sim \chi^2(r) \\
    t^2 & = & n\left(\mathbf{L}\overline{\mathbf{X}}_n - 
        \mathbf{h}\right)^\prime
        \left(\mathbf{LSL}^\prime\right)^{-1}
                      \left(\mathbf{L}\overline{\mathbf{X}}_n - 
        \mathbf{h}\right)
        \sim T^2(r,n-1) 
\end{eqnarray*}
        \item And $F = \frac{n-r}{r(n-1)}t^2 \sim F(r,n-r) \Rightarrow t^2 = 
        \frac{n-1}{n-r}\,rF \stackrel{d}{\rightarrow} Y \sim \chi^2(r) $
        \item So the Hotelling $t$-squared test is robust with respect to normality.
  \end{itemize}
\end{frame}

\end{document}

