% \documentclass[serif]{beamer} % Serif for Computer Modern math font.
\documentclass[serif, handout]{beamer} % Handout mode 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{Berlin} % Displays sections on top
\usetheme{Frankfurt}  % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides
%\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<presentation>

\title{Random Vectors\footnote{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{Background Reading: Renscher and Schaalje's \emph{Linear models in statistics}}
       \begin{itemize}
            \item Chapter 3 on Random Vectors and Matrices
            \item Chapter 4 on the Multivariate Normal Distribution
       \end{itemize}
\end{frame}

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

\section{Definitions and Basic Results}

\begin{frame}
\frametitle{Random Vectors and Matrices}
%\framesubtitle{} 
A \emph{random matrix} is just a matrix of random variables. Their joint probability distribution is the distribution of the random matrix. Random matrices with just one column (say, $p \times 1$) may be called \emph{random vectors}.
\end{frame}

\begin{frame}
\frametitle{Expected Value}
%\framesubtitle{} 

The expected value of a matrix is defined as the matrix of expected values. \pause Denoting the $p \times c$ random matrix $\mathbf{X}$ by $[X_{i,j}]$, \pause 
\begin{displaymath}
    E(\mathbf{X}) = [E(X_{i,j})].
\end{displaymath}
\end{frame}

\begin{frame}
\frametitle{Immediately we have natural properties like} \pause
%\framesubtitle{} 
\begin{eqnarray}
    E(\mathbf{X}+\mathbf{Y})  \pause
                             &=& E([X_{i,j}]+[Y_{i,j}]) \nonumber \\ \pause 
                             &=& [E(X_{i,j}+Y_{i,j})] \nonumber \\ \pause 
                             &=& [E(X_{i,j})+E(Y_{i,j})] \nonumber \\ \pause 
                             &=& [E(X_{i,j})]+[E(Y_{i,j})] \nonumber \\ \pause 
                             &=& E(\mathbf{X})+E(\mathbf{Y}). \nonumber 
\end{eqnarray}
\end{frame}

\begin{frame}
\frametitle{Moving a constant through the expected value sign} \pause
Let $\mathbf{A} = [a_{i,j}]$ be an $r \times p$ matrix of constants, while $\mathbf{X}$ is still a $p \times c$ random matrix. \pause  Then 
\begin{eqnarray}
    E(\mathbf{AX})  \pause 
        &=& E\left(\left[\sum_{k=1}^p a_{i,k}X_{k,j}\right]\right) \nonumber \\ \pause 
        &=& \left[E\left(\sum_{k=1}^p a_{i,k}X_{k,j}\right)\right] \nonumber \\ \pause 
        &=& \left[\sum_{k=1}^p a_{i,k}E(X_{k,j})\right] \nonumber \\ \pause 
        &=& \mathbf{A}E(\mathbf{X}). \nonumber \pause 
\end{eqnarray}

Similar calculations yield $E(\mathbf{AXB}) = \mathbf{A}E(\mathbf{X})\mathbf{B}$.
\end{frame}

\begin{frame}
\frametitle{Variance-Covariance Matrices} \pause 
Let $\mathbf{X}$ be a $p \times 1$ random vector with $E(\mathbf{X}) = \boldsymbol{\mu}$. \pause  The \emph{variance-covariance matrix} of $\mathbf{X}$  \pause (sometimes just called the \emph{covariance matrix})\pause, denoted by $cov(\mathbf{X})$, is defined as \pause 
\begin{displaymath}
    cov(\mathbf{X}) = E\left\{ (\mathbf{X}-\boldsymbol{\mu})
                             (\mathbf{X}-\boldsymbol{\mu})^\top\right\}.
\end{displaymath}
\end{frame}


\begin{frame}
\frametitle{$cov(\mathbf{X}) = E\left\{ (\mathbf{X}-\boldsymbol{\mu})
                             (\mathbf{X}-\boldsymbol{\mu})^\top\right\}$} \pause
{\scriptsize
\begin{eqnarray}
   cov(\mathbf{X}) &=& E\left\{
        \left( \begin{array}{c}
        X_1-\mu_1 \\  X_2-\mu_2 \\ X_3-\mu_3
        \end{array} \right)
        \left( \begin{array}{c c c}
        X_1-\mu_1 &  X_2-\mu_2 & X_3-\mu_3
        \end{array} \right) \right\} \nonumber \\ \pause
  &=& E\left\{
        \left( \begin{array}{l l l}
        (X_1-\mu_1)^2 &  (X_1-\mu_1)(X_2-\mu_2) & (X_1-\mu_1)(X_3-\mu_3) \\
        (X_2-\mu_2)(X_1-\mu_1) &  (X_2-\mu_2)^2 & (X_2-\mu_2)(X_3-\mu_3) \\
        (X_3-\mu_3)(X_1-\mu_1) &  (X_3-\mu_3)(X_2-\mu_2) & (X_3-\mu_3)^2 \\
        \end{array} \right) \right\} \nonumber \\
         \nonumber \\ \pause
  &=& 
    \left( \begin{array}{l l l}
    E\{(X_1-\mu_1)^2\} &  E\{(X_1-\mu_1)(X_2-\mu_2)\} & E\{(X_1-\mu_1)(X_3-\mu_3)\} \\
    E\{(X_2-\mu_2)(X_1-\mu_1)\} &  E\{(X_2-\mu_2)^2\} & E\{(X_2-\mu_2)(X_3-\mu_3)\} \\
    E\{(X_3-\mu_3)(X_1-\mu_1)\} &  E\{(X_3-\mu_3)(X_2-\mu_2)\} & E\{(X_3-\mu_3)^2\} \\
        \end{array} \right)  \nonumber \\
         \nonumber \\ \pause
  &=& 
    \left( \begin{array}{l l l}
    Var(X_1) &  Cov(X_1,X_2) & Cov(X_1,X_3) \\
    Cov(X_1,X_2) &  Var(X_2) & Cov(X_2,X_3) \\
    Cov(X_1,X_3) &  Cov(X_2,X_3) & Var(X_3) \\
        \end{array} \right) . \nonumber \\
         \nonumber 
\end{eqnarray} 
\pause 
So, the covariance matrix $cov(\mathbf{X})$ is a $p \times p$ symmetric matrix with variances on the main diagonal and covariances on the off-diagonals. 
} %V End size
\end{frame}


\begin{frame}
\frametitle{Matrix of covariances between two random vectors}
Let $\mathbf{X}$ be a $p \times 1$ random vector with $E(\mathbf{X}) = \boldsymbol{\mu}_x$ and let $\mathbf{Y}$ be a $q \times 1$ random vector with $E(\mathbf{Y}) = \boldsymbol{\mu}_y$. The $p \times q$ matrix of covariances between the elements of $\mathbf{X}$ and the elements of $\mathbf{Y}$ is
\begin{displaymath}
    cov(\mathbf{X,Y}) = E\left\{ (\mathbf{X}-\boldsymbol{\mu}_x)
                             (\mathbf{Y}-\boldsymbol{\mu}_y)^\top\right\}.
\end{displaymath}
\end{frame}


\begin{frame}
\frametitle{Adding a constant has no effect}
\framesubtitle{On variances and covariances} \pause
  \begin{itemize}
    \item $ cov(\mathbf{X} + \mathbf{a}) = cov(\mathbf{X})$ \pause
    \item $cov(\mathbf{X} + \mathbf{a},\mathbf{Y} + \mathbf{b})
        = cov(\mathbf{X},\mathbf{Y})$ \pause
  \end{itemize}

\vspace{10mm}

These results are clear from the definitions: \pause
  \begin{itemize}
    \item $cov(\mathbf{X}) = E\left\{ (\mathbf{X}-\boldsymbol{\mu})
                             (\mathbf{X}-\boldsymbol{\mu})^\top\right\}$ \pause
    \item $cov(\mathbf{X,Y}) = E\left\{ (\mathbf{X}-\boldsymbol{\mu}_x)
                             (\mathbf{Y}-\boldsymbol{\mu}_y)^\top\right\}$
  \end{itemize} \pause

\vspace{10mm}

Sometimes it is useful to let $\mathbf{a} = -\boldsymbol{\mu}_x$ and 
                                 $\mathbf{b} = -\boldsymbol{\mu}_y$.
\end{frame}

\begin{frame}
\frametitle{Analogous to $Var(a\,X) = a^2\,Var(X)$} \pause
Let $\mathbf{X}$ be a $p \times 1$ random vector with $E(\mathbf{X}) = \boldsymbol{\mu}$ and $cov(\mathbf{X}) = \boldsymbol{\Sigma}$\pause, while $\mathbf{A} = [a_{i,j}]$ is an $r \times p$ matrix of constants. \pause Then
\begin{eqnarray*} \label{vax}
    cov(\mathbf{AX})  \pause
    &=& 
    E\left\{ (\mathbf{AX}-\mathbf{A}\boldsymbol{\mu})
             (\mathbf{AX}-\mathbf{A}\boldsymbol{\mu})^\top \right\}  \\ \pause
    &=& 
    E\left\{ \mathbf{A}(\mathbf{X}-\boldsymbol{\mu})
             \left(\mathbf{A}(\mathbf{X}-\boldsymbol{\mu})\right)^\top 
             \right\}  \\ \pause
    &=& 
    E\left\{ \mathbf{A}(\mathbf{X}-\boldsymbol{\mu})
             (\mathbf{X}-\boldsymbol{\mu})^\top \mathbf{A}^\top
             \right\} \nonumber \\ \pause
    &=&      \mathbf{A}E\{(\mathbf{X}-\boldsymbol{\mu})
             (\mathbf{X}-\boldsymbol{\mu})^\top\} \mathbf{A}^\top
              \\ \pause
    &=&      \mathbf{A}cov(\mathbf{X}) \mathbf{A}^\top \nonumber \\ \pause
    &=&      \mathbf{A}\boldsymbol{\Sigma}\mathbf{A}^\top 
\end{eqnarray*}
\end{frame}

\section{Multivariate Normal}

\begin{frame}
\frametitle{The Multivariate Normal Distribution}
The $p \times 1$ random vector $\mathbf{X}$ is said to have a \emph{multivariate normal distribution}, and we write $\mathbf{X} \sim N(\boldsymbol{\mu},\boldsymbol{\Sigma})$, if $\mathbf{X}$ has (joint) density

\begin{displaymath}
f(\mathbf{x}) = \frac{1}{|\boldsymbol{\Sigma}|^{\frac{1}{2}} (2 \pi)^{\frac{p}{2}}} 
                \exp\left[ -\frac{1}{2} (\mathbf{x}-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right],
\end{displaymath}
where $\boldsymbol{\mu}$ is $p \times 1$ and $\boldsymbol{\Sigma}$ is $p \times p$ symmetric and positive definite.
\end{frame}


\begin{frame}
\frametitle{$\boldsymbol{\Sigma}$ positive definite}
  \begin{itemize}
    \item Positive definite means that for any non-zero $p \times 1$ vector $\mathbf{a}$, we have $\mathbf{a}^\top \boldsymbol{\Sigma} \mathbf{a} > 0$. \pause
    \item Since the one-dimensional random variable $Y=\sum_{i=1}^p a_i X_i$ may be written as $Y=\mathbf{a}^\top \mathbf{X}$ \pause and $Var(Y)=cov(\mathbf{a}^\top \mathbf{X})=\mathbf{a}^\top \boldsymbol{\Sigma} \mathbf{a}$\pause, it is natural to require that $\boldsymbol{\Sigma}$ be positive definite.  \pause
    \item All it means is that every non-zero linear combination of $\mathbf{X}$ values has a positive variance. \pause
    \item And recall $\boldsymbol{\Sigma}$ positive definite is equivalent to $\boldsymbol{\Sigma}^{-1}$ positive definite.
  \end{itemize}
\end{frame}

\begin{frame}
\frametitle{Analogies}
\framesubtitle{(Multivariate normal reduces to the univariate normal when $p=1$)} \pause
\begin{itemize}
    \item Univariate Normal
        \begin{itemize}
            \item $f(x) =  \frac{1}{\sigma \sqrt{2\pi}} 
                  \exp \left\{-\frac{1}{2}\frac{(x-\mu)^2}{\sigma^2}\right\}$
            \item $E(X)=\mu, Var(X) = \sigma^2$ 
            \item $\frac{(X-\mu)^2}{\sigma^2} \sim \chi^2 (1)$
        \end{itemize} \pause

\vspace{3mm}

    \item Multivariate Normal
        \begin{itemize}
            \item $f(\mathbf{x}) = 
            \frac{1}{|\boldsymbol{\Sigma}|^{\frac{1}{2}} (2 \pi)^{\frac{p}{2}}} 
                \exp\left\{ -\frac{1}{2} (\mathbf{x}-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right\}$
            \item $E(\mathbf{X})= \boldsymbol{\mu}$, $cov(\mathbf{X}) = \boldsymbol{\Sigma}$
            \item $(\mathbf{X}-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{X}-\boldsymbol{\mu}) \sim \chi^2 (p)$
        \end{itemize}
\end{itemize}
\end{frame} 


\begin{frame}
\frametitle{More properties of the multivariate normal} \pause
% 
  \begin{itemize}
    \item If $\mathbf{c}$ is a vector of constants, \pause $\mathbf{X}+\mathbf{c} \sim
             N(\mathbf{c}+\boldsymbol{\mu},\boldsymbol{\Sigma})$ \pause   
    \item If $\mathbf{A}$ is a matrix of constants, \pause $\mathbf{AX} \sim
             N(\mathbf{A}\boldsymbol{\mu},\mathbf{A}\boldsymbol{\Sigma}\mathbf{A}^\top)$ \pause
    \item Linear combinations of multivariate normals are multivariate normal. \pause
    \item All the marginals (dimension less than $p$) of $\mathbf{X}$ are (multivariate) normal\pause, but it is possible in theory to have a collection of univariate normals whose joint distribution is not multivariate normal. \pause
    \item For the multivariate normal, zero covariance implies independence. \pause The multivariate normal is the only continuous distribution with this property. 
  \end{itemize}
\end{frame}


\begin{frame}
\frametitle{An easy example}
\framesubtitle{If you do it the easy way} \pause
Let $\mathbf{X}= (X_1,X_2,X_3)^\top$ be multivariate normal with \pause
    \begin{displaymath}
    \boldsymbol{\mu} = 
    \left( \begin{array}{c} 1 \\ 0 \\ 6
    \end{array} \right) \mbox{ and }
    \boldsymbol{\Sigma} =
     \left( \begin{array}{c c c}
                 2 & 1 & 0 \\
                 1 & 4 & 0 \\
                 0 & 0 & 2
    \end{array} \right) .
    \end{displaymath} \pause
Let $Y_1=X_1+X_2$ and $Y_2=X_2+X_3$. Find the joint distribution of $Y_1$ and $Y_2$.
% Just for fun, check it with sage:
%mu = vector(QQ,[1,0,6]).column() # QQ is the rational field
%Sigma = matrix(QQ,[[2,1,0],[1,4,0],[0,0,2]])
%A = matrix(QQ,[[1,1,0],[0,1,1]])
%mu2 = A*mu; show(mu2)
%Sigma2 = A*Sigma*A.transpose(); show(Sigma2)
\end{frame}

\begin{frame}
\frametitle{In matrix terms} \pause
$Y_1=X_1+X_2$ and $Y_2=X_2+X_3$ means $\mathbf{Y} = \mathbf{AX}$ \pause

\vspace{10mm}

\begin{displaymath}
      \left( \begin{array}{c} Y_1 \\ Y_2
      \end{array} \right)
    = \left( \begin{array}{c c c}
                 1 & 1 & 0 \\
                 0 & 1 & 1 
      \end{array} \right)
      \left( \begin{array}{c} X_1 \\ X_2 \\ X_3
      \end{array} \right)
\end{displaymath} \pause

\vspace{10mm}

$\mathbf{Y} = \mathbf{AX} \sim
             N(\mathbf{A}\boldsymbol{\mu},\mathbf{A}\boldsymbol{\Sigma}\mathbf{A}^\top)$
\end{frame}

\begin{frame}[fragile]
\frametitle{You could do it by hand, but} \pause
%\framesubtitle{} 
\begin{verbatim}
> mu = cbind(c(1,0,6))
> Sigma = rbind( c(2,1,0),
+                c(1,4,0),
+                c(0,0,2) )
> A = rbind( c(1,1,0),
+            c(0,1,1) ); A
> A %*% mu              # E(Y)
     [,1]
[1,]    1
[2,]    6
> A %*% Sigma %*% t(A)  # cov(Y)
     [,1] [,2]
[1,]    8    5
[2,]    5    6
\end{verbatim} 
\end{frame}


\begin{frame}
\frametitle{A couple of things to prove}
  \begin{itemize}
    \item $(\mathbf{X}-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{X}-\boldsymbol{\mu}) \sim \chi^2 (p)$

\vspace{10mm}

    \item $\overline{X}$ and $S^2$ independent under normal random sampling.
  \end{itemize}
\end{frame}


\begin{frame}
\frametitle{Recall the square root matrix} \pause
Covariance matrix $\boldsymbol{\Sigma}$ is real and symmetric matrix, so we have the spectral decomposition \pause


\begin{eqnarray*}
    \boldsymbol{\Sigma} & = & \mathbf{P}\boldsymbol{\Lambda}\mathbf{P}^\top \\ \pause
     & = &  \mathbf{P}\boldsymbol{\Lambda}^{1/2}\boldsymbol{\Lambda}^{1/2}           
            \mathbf{P}^\top \\ \pause
     & = &  \mathbf{P}\boldsymbol{\Lambda}^{1/2} \, \mathbf{I} \,
            \boldsymbol{\Lambda}^{1/2} \mathbf{P}^\top \\ \pause
     & = &  \mathbf{P}\boldsymbol{\Lambda}^{1/2} \mathbf{P}^\top~~\mathbf{P}
            \boldsymbol{\Lambda}^{1/2} \mathbf{P}^\top \\ \pause
     & = &  ~~~\boldsymbol{\Sigma}^{1/2}~~~~~~~\boldsymbol{\Sigma}^{1/2}
\end{eqnarray*}  \pause

\vspace{10mm}

So $\boldsymbol{\Sigma}^{1/2} = \mathbf{P}\boldsymbol{\Lambda}^{1/2} \mathbf{P}^\top$
\end{frame}

\begin{frame}
\frametitle{Square root of an inverse}
\framesubtitle{Positive definite $\Rightarrow$ Positive eigenvalues $\Rightarrow$ Inverse exists} \pause
     $\mathbf{P}\boldsymbol{\Lambda}^{-1/2}\mathbf{P}^\top ~\cdot~
       \mathbf{P}\boldsymbol{\Lambda}^{-1/2}\mathbf{P}^\top
       = \mathbf{P}\boldsymbol{\Lambda}^{-1} \mathbf{P}^\top
       = \boldsymbol{\Sigma}^{-1}$,  \pause

\vspace{5mm}

so

\vspace{5mm}

    $\left(\boldsymbol{\Sigma}^{-1} \right)^{1/2}
    = \mathbf{P}\boldsymbol{\Lambda}^{-1/2} \mathbf{P}^\top$. \pause

\vspace{10mm}


It's easy to show
  \begin{itemize}
    \item $\left(\boldsymbol{\Sigma}^{-1} \right)^{1/2}$ is the inverse of  
    $\boldsymbol{\Sigma}^{1/2}$
    \item Justifying the notation $\boldsymbol{\Sigma}^{-1/2}$
  \end{itemize}
\end{frame}

\begin{frame}
\frametitle{Now we can show $(\mathbf{X}-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{X}-\boldsymbol{\mu}) \sim \chi^2 (p)$} 
\framesubtitle{Where $\mathbf{X} \sim N(\boldsymbol{\mu},\boldsymbol{\Sigma})$}
\pause

\begin{eqnarray*}
    \mathbf{Y} = \mathbf{X}-\boldsymbol{\mu} 
    & \sim & N\left(\mathbf{0},\ \boldsymbol{\Sigma}\right) \\ \pause
    \mathbf{Z} = \boldsymbol{\Sigma}^{-\frac{1}{2}} \mathbf{Y} 
    & \sim &  N\left(\mathbf{0},
     \boldsymbol{\Sigma}^{-\frac{1}{2}} \boldsymbol{\Sigma} 
     \boldsymbol{\Sigma}^{-\frac{1}{2}} \right) \\ \pause
    & = & N\left(\mathbf{0},
     \boldsymbol{\Sigma}^{-\frac{1}{2}} 
     \boldsymbol{\Sigma}^{\frac{1}{2}} ~ \boldsymbol{\Sigma}^{\frac{1}{2}}
     \boldsymbol{\Sigma}^{-\frac{1}{2}} \right) \\ \pause
    & = & N\left(\mathbf{0}, \mathbf{I}\right) \pause
\end{eqnarray*} 

So $\mathbf{Z}$ is a vector of $p$ independent standard normals\pause, and 
\begin{displaymath}
    \mathbf{Y}^\top \boldsymbol{\Sigma}^{-1} \mathbf{Y}  \pause
    = \mathbf{Z}^\top \mathbf{Z} \pause = \sum_{j=1}^p Z_i^2 \pause
    \sim \chi^2(p) \pause   ~~~~~~~~~~ \blacksquare
\end{displaymath}
\end{frame}



\begin{frame}
\frametitle{$\overline{X}$ and $S^2$ independent }
Let $X_1, \ldots, X_n \stackrel{i.i.d.}{\sim} N(\mu,\sigma^2)$.  \pause
\begin{displaymath}
\begin{array}{lcl}
\mathbf{X} = \left( 
             \begin{array}{c}
               X_1 \\ \vdots \\ X_n
             \end{array}
             \right) \sim   N\left(\mu\mathbf{1},\sigma^2\mathbf{I} \right) 
&~~~~& \pause
\mathbf{Y} = \left( 
             \begin{array}{c}
               X_1-\overline{X} \\ \vdots \\  X_{n-1}-\overline{X} \\\\ \overline{X}
             \end{array}
             \right) \pause
           = \mathbf{AX}
\end{array}
\end{displaymath}
\end{frame}

\begin{frame}
\frametitle{$\mathbf{Y} = \mathbf{AX}$}
\framesubtitle{In more detail} 
\begin{displaymath}
%     \mathbf{AX} = 
    \left(
    \begin{array}{rrcrr}
    1-\frac{1}{n} &  -\frac{1}{n} &   \cdots   &  -\frac{1}{n} &  -\frac{1}{n} \\
                  &               &            &               &               \\
     -\frac{1}{n} & 1-\frac{1}{n} & \cdots     & -\frac{1}{n}  &  -\frac{1}{n} \\
        \vdots\,  &    \vdots\,   & \vdots\,   &     \vdots\,  &    \vdots\,   \\
     -\frac{1}{n} &  -\frac{1}{n} &  \cdots    &1-\frac{1}{n}  & -\frac{1}{n}  \\
                  &               &            &               &               \\
      \frac{1}{n} &   \frac{1}{n} &  \cdots    &   \frac{1}{n} & \frac{1}{n}   \\
    \end{array}
    \right)
             \left( 
             \begin{array}{c}
               X_1 \\ \\ X_2 \\ \vdots  \\ X_{n-1} \\ \\ X_n
             \end{array}
             \right)
     =       \left( 
             \begin{array}{c}
               X_1-\overline{X} \\ \\  X_2-\overline{X} \\
               \vdots \\  X_{n-1}-\overline{X} \\\\ \overline{X}
             \end{array}
             \right)
\end{displaymath} 
\end{frame}


\begin{frame}
\frametitle{The argument}
\begin{displaymath}
\mathbf{Y} = \mathbf{AX} = \left( 
             \begin{array}{c}
               X_1-\overline{X} \\ \vdots \\  X_{n-1}-\overline{X} \\\\ \overline{X}
             \end{array}
             \right)
            = \left( 
             \begin{array}{c}
        \\\\ \mathbf{Y}_2 \\\\ \hline \\ \overline{X}
             \end{array}
             \right)
\end{displaymath} \pause
  \begin{itemize}
    \item $\mathbf{Y}$ is multivariate normal. \pause
    \item $Cov\left(\overline{X},(X_j-\overline{X})\right)=0$ (Exercise) \pause
    \item So $\overline{X}$ and $\mathbf{Y}_2$ are independent. \pause
    \item So $\overline{X}$ and $S^2 = g(\mathbf{Y}_2)$ are independent. ~~$\blacksquare$
  \end{itemize}
\end{frame}

\begin{frame}
\frametitle{Leads to the $t$ distribution} \pause
%\framesubtitle{} 
If
  \begin{itemize}
    \item $Z \sim N(0,1)$ and \pause
    \item $Y \sim \chi^2(\nu)$ and  \pause
    \item $Z$ and $Y$ are independent, then \pause
  \end{itemize}
\begin{displaymath}
    T = \frac{Z}{\sqrt{Y/\nu}} \pause \sim t(\nu)
\end{displaymath}
\end{frame}

\begin{frame}
\frametitle{Random sample from a normal distribution} \pause
Let $X_1, \ldots, X_n \stackrel{i.i.d.}{\sim} N(\mu,\sigma^2)$. \pause Then
  \begin{itemize}
    \item $\frac{\sqrt{n}(\overline{X}-\mu)}{\sigma} \pause 
          = \frac{(\overline{X}-\mu)}{\sigma/\sqrt{n}} \pause \sim N(0,1)$ \pause and
    \item $\frac{(n-1)S^2}{\sigma^2} \pause \sim \chi^2(n-1)$ \pause and 
    \item These quantities are independent\pause, so \pause
\begin{eqnarray*}
    T & = & \frac{\sqrt{n}(\overline{X}-\mu)/\sigma}
                {\sqrt{\frac{(n-1)S^2}{\sigma^2}/(n-1)}} \\ \pause
      &&\\
      & = & \frac{\sqrt{n}(\overline{X}-\mu)}{S} \pause \sim t(n-1) 
\end{eqnarray*}
  \end{itemize}
\end{frame}



% Last in section
\begin{frame} 
\frametitle{Multivariate normal likelihood}
\framesubtitle{For reference}  \pause
{\footnotesize
\begin{eqnarray*}
    L(\boldsymbol{\mu,\Sigma}) &=& 
    \prod_{i=1}^n \frac{1}{|\boldsymbol{\Sigma}|^{\frac{1}{2}} (2 \pi)^{\frac{p}{2}}} 
                \exp\left\{ -\frac{1}{2} (\mathbf{x}_i-\boldsymbol{\mu})^\top
                 \boldsymbol{\Sigma}^{-1}(\mathbf{x}_i-\boldsymbol{\mu})\right\} \\ \pause
&&\\
                               &=&
    |\boldsymbol{\Sigma}|^{-n/2} (2\pi)^{-np/2} 
    \exp -\frac{n}{2}\left\{ tr(\boldsymbol{\widehat{\Sigma}\Sigma}^{-1}) +
    (\overline{\mathbf{x}}-\boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} 
    (\overline{\mathbf{x}}-\boldsymbol{\mu}) \right\}\pause,
\end{eqnarray*} }

where $\boldsymbol{\widehat{\Sigma}} = 
\frac{1}{n}\sum_{i=1}^n (\mathbf{x}_i-\overline{\mathbf{x}}) 
                        (\mathbf{x}_i-\overline{\mathbf{x}})^\top $ 
is the sample variance-covariance matrix.
\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}

L(\boldsymbol{\mu,\Sigma}) = |\boldsymbol{\Sigma}|^{-n/2} (2\pi)^{-np/2} 
    \exp -\frac{n}{2}\left\{ tr(\boldsymbol{\widehat{\Sigma}\Sigma}^{-1}) +
    (\overline{\mathbf{x}}-\boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} 
    (\overline{\mathbf{x}}-\boldsymbol{\mu}) \right\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{}
%\framesubtitle{} 
  \begin{itemize}
    \item 
    \item 
    \item 
  \end{itemize}
\end{frame}

{\LARGE
\begin{displaymath}
    
\end{displaymath} }




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
