
\documentclass[handout]{beamer}
%Nov 2008

\usetheme[secheader]{Boadilla}
\usepackage{amsmath}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphics}
%\SweaveOpts{echo=FALSE}
%\usepackage{dpscolor}
%\usepackage{psfrag}
\usepackage{chicago}
\usepackage{times}
\usepackage{epsfig}
% \usepackage{C:/Programme/R/R-2.7.0/share/texmf/Sweave}    % path might need to be modified
% \usepackage{/Library/Frameworks/R.framework/Resources/share/texmf/Sweave}
\usepackage[utf8]{inputenc}			% for displaying 'signif codes' right

\newcommand{\tcb}{\color{blue}}
\newcommand{\tcg}{\color{green}}
\newcommand{\tcr}{\color{red}}
\newcommand{\tco}{\color{orange}}
\newcommand{\tcm}{\color{magenta}}
\newcommand{\ftheta}{\mbox{\boldmath $\theta$}}
\newcommand{\fbe}{\mbox{\boldmath $\beta$}}
\newcommand{\fga}{\mbox{\boldmath $\gamma$}} 
\newcommand{\feps}{\mbox{\boldmath $\epsilon$}} 
\newcommand{\feta}{\mbox{\boldmath $\eta$}}
\newcommand{\fnu}{\mbox{\boldmath $\nu$}}
\newcommand{\frho}{\mbox{\boldmath $\rho$}}
\newcommand{\fm}{\mbox{\bf m}}
\newcommand{\fx}{{\bf x}} 
\newcommand{\fu}{{\bf u}} 

\def\TCop{\textcopyright}
\setbeamertemplate{footline}
{
\begin{beamercolorbox}[wd=\textwidth,ht=2ex,dp=1.5ex,leftskip=.5em,rig htskip=.5em]{author in foot}%
\color{gray}{\hspace{0.1cm} % \TCop \ \insertshortauthor \hspace{0.2mm} TU Munich 
\hfill \insertframenumber{} / \inserttotalframenumber \hspace{0.2cm}}
% \insertframenumber%
\end{beamercolorbox}
}
% \setbeamertemplate{footline}[page number]


\begin{document}
\setkeys{Gin}{width=.6\textwidth}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title[Statistical Hypothesis Testing]
 {\bf Statistical Hypothesis Testing \\Parametric Tests I: Concept of the T-Test}
\author[D. Schmidl]{ \\ \vspace{0.5cm} 
\vspace{0.5cm}
Daniel Schmidl\\
\vspace{0.5cm}
\scriptsize{Workshop on Statistical Concepts and Methods}\\
\scriptsize{Munich, October 14, 2009}\\
}
\date{}

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

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

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

\section{Introduction to Statistical Hypothesis Testing}

%%%
\begin{frame}[fragile]
\frametitle{\bf Parametric Statistical Hypothesis Testing}

   We want to \alert{test} whether a \alert{hypothesis} about parameter values or distributions holds \alert{in a given population}:
   
\vspace{1cm}

For random variables $X_1, \ldots, X_n \sim F(\cdot, \theta)$

\vspace{ 0.5 cm}

we test the hypotheses

{\tcr 
\begin{table}
\begin{tabular}{ccc}
$H_0: \ \theta \in \mathcal{H}_0$ & versus & $H_1: \ \theta \not \in \mathcal{H}_0$
\end{tabular}
\end{table}
}

at a certain \alert{significance level $\alpha$}.

\vspace{1cm}

{\tcb Goal:}
\alert{Reject} the \alert{null hypothesis $H_0$!}


\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf Parametric Statistical Hypothesis Testing}

{\tcb What is $\alpha$?}

\vspace{0.3 cm}

Not possible to control the \alert{type I error}, $$\theta \in \mathcal{H}_0 \text{, but } H_0 \text{ is rejected,}$$ and the \alert{type II error},  $$\theta \not \in \mathcal{H}_0 \text{, but } H_0 \text{ is not rejected,}$$ at the same time.

\vspace{1cm}

% By 
Thus we set
$$\alert{\alpha := \sup_{\theta \in \mathcal{H}_0} P_\theta (H_0 \text{ is rejected})}$$
% we at least control the probability for a \alert{type I error}.

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{One Sample T-Test}

%%%
\begin{frame}[fragile]
\frametitle{\bf One Sample T-Test}

Based on the sample mean we want to test, if the \alert{expected mean} of a sample is \alert{smaller, equal, or bigger than a given value $\mu_0$}.

\vspace{.5 cm}
 
For i.i.d.\ random variables $$X_1, \ldots, X_n \sim \mathcal{N} (\mu, \sigma^2)$$ it can be easily shown that the arithmetic mean $$\bar X = \frac{1}{n} \sum_{i=1}^n X_i$$ is also normally distributed with $\text{mean } \mu \text{ and standard deviation } \frac{\sigma}{\sqrt{n}}.$

\vspace{.5 cm}

Therefore $$\alert{Z := \sqrt{n} \frac{\bar X - \mu}{\sigma} \sim \mathcal{N} (0,1).}$$

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test Statistic}

Since we generally do not know $\sigma$ we have to estimate it by  $$S = \sqrt{\frac{\sum_{i=1}^n (X_i - \bar X)^2}{n-1}}.$$

This yields % the \alert{t-test statistic} 
$$\alert{T' = \sqrt{n} \frac{\bar X - \mu}{S}\sim t_{n-1},}$$

where \alert{$t_{n-1}$} denotes the \alert{student's t-distribution} with $n-1$ degrees of freedom.

% \vspace{1 cm}

% $\rightarrow$ If \alert{T} is \alert{too big (or small)}, we can \alert{reject} the null hypothesis \alert{$H_0$}!

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test Statistic}

\begin{figure}[htb]			
		\begin{center}
   	  		% \includegraphics[width=0.5 \textwidth]{tdist0.pdf} 
   		\end{center} 
\end{figure}

\vspace{-0.5cm}

{\tcb Note:} For \alert{non-normally i.i.d.\ $X_1,\ldots, X_n$ with $n>30$} the central limit theorem yields that $\bar X$ is approximately normally distributed and the \alert{t-test still works}.

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf Test Procedure}

For the i.i.d.\ sample $\alert{x_1, \ldots, x_n}$ with a \alert{true mean of $\mu$} and an \alert{assumed mean $\mu_0$}

\vspace{.5cm}

\begin{enumerate}
\item fix a significance level $\alpha$ (e.g.\ $\alpha=0.1, \alpha=0.05, \ldots$)
\item choose (one of the following) null hypotheses
\begin{table}
\begin{tabular}{|c|c|c|}
$H_0: \ \mu \leq \mu_0$ & $H_0: \ \mu = \mu_0$ & $H_0: \ \mu \geq \mu_0$ \\
$H_1: \ \mu > \mu_0$ & $H_1: \ \mu \neq \mu_0$ & $H_1: \ \mu < \mu_0$
\end{tabular}
\end{table}
\item compute the test statistic $T = \sqrt{n} \frac{\bar x - \mu_0}{s}$\\
{\color{gray} $\left( \bar x=\frac{1}{n} \sum_{i=1}^n x_i \text{ and } s= \sqrt{\frac{\sum_{i=1}^n (x_i - \bar x)^2}{n-1}} \right)$}
\item reject the null hypothesis, iff
\begin{table}
\begin{tabular}{|c|c|c|}
$T > t_{n-1,1-\alpha}$ & $T > t_{n-1,1-\alpha/2}$ & $T < t_{n-1,\alpha}$ \\
& or & \\
& $T < t_{n-1,\alpha/2}$ &
\end{tabular}
\end{table}
\color{gray}{where  $t_{n-1,a}$ is the $a$-quantile of the t-distribution with $(n-1)$ degrees of freedom.}
\end{enumerate}

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test Statistic}

\begin{figure}[htb]			
		\begin{center}
   	  		% \includegraphics[width=0.5 \textwidth]{tdist.pdf} 
   		\end{center} 
\end{figure}

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf P-value}

{\tcb What is the p-value good for?}

\vspace{1cm}

We can also use the \alert{p-value} $$\alert{p = \inf_{\alpha} \{ H_0 \text{ is still rejected } \mid x_1, \ldots, x_n \},}$$
in order to decide, whether $H_0$ can be rejected:

$$\alert{\text{Reject } H_0 \text{ iff } p < \alpha.}$$

{\tcb Note:} 
\begin{itemize}
\item The p-value is \alert{not} the probability that the null hypothesis is true
\item The p-value is also \alert{not} the probability of falsely rejecting the null hypothesis
\end{itemize}

\end{frame}


%%%
\begin{frame}[fragile]
\frametitle{\bf Example}

We want to test at the \alert{$\alpha = 0.05$ level}, if the cholesterol level in a group of $n=10$ people is \alert{significantly higher than 119 mg/dL}, i.e.\ we test

{\tcr 
\begin{table}
\begin{tabular}{ccc}
$H_0: \ \mu \leq 119.5$ & versus & $H_1: \ \mu > 119.5.$
\end{tabular}
\end{table}
}


Data: 118.9 122.0 118.0 127.5 122.6 118.1 123.2 124.2 123.5 120.1

\vspace{.5 cm}

The test statistic has the value 
$$\alert{T} =  \sqrt{n} \frac{\bar x - \mu_0}{s} = \sqrt{10} \frac{121.81 - 119.5}{3.04} \alert{ = 2.41}$$
and we can \alert{reject $H_0$}, since $t_{9,0.95} = 1.83 < T$. The p-value computes to $p=0.01978$.
\vspace{0.3 cm}

This means that the group has a significantly lower cholosterol level than 119.5 mg/mL at the $5 \%$ $\alpha$-level (even at the $2 \%$ $\alpha$-level).

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test in R}

{\tiny
\begin{Schunk}
\begin{Sinput}
> d <- c(118.86, 122.02, 118.04, 127.52, 122.59, 118.10, 123.20, 124.18, 123.55, 120.11)
> t.test(d, mu=119.5,alternative="greater")
\end{Sinput}
\begin{Soutput}
	One Sample t-test

data:  d
t = 2.4053, df = 9, p-value = 0.01978
alternative hypothesis: true mean is greater than 119.5 
95 percent confidence interval:
 120.0509      Inf 
sample estimates:
mean of x 
 121.8156 
\end{Soutput}
\end{Schunk}
}

%> test <- t.test(return1[type == 4], alternative = "two.sided", 
%+     mu = mu0, paired = FALSE, conf.level = 0.95)

\vspace{-1cm} 

\begin{figure}[htb]			
		\begin{center}
   	  		% \includegraphics[width=0.45 \textwidth]{ex1plot.pdf} 
   		\end{center} 
\end{figure}
\end{frame}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Two Sample T-Test}
\subsection{Paired Sample T-Test}


%%%
\begin{frame}[fragile]
\frametitle{\bf Paired Sample T-Test}

{\tcb Generally:} The \alert{two sample t-test} tests,  if the \alert{means} in two different populations are \alert{equal}.

\vspace{1 cm}

For a paired sample $x_1, \ldots, x_n$ and $y_1, \ldots, y_n$ (coming e.g.\ from a repeated measurement) we define 
$$\alert{d_i :=  x_i - y_i.}$$

The new i.i.d.\ sample $d_1, \ldots, d_n$ can then be tested as in the one sample case by setting e.g.\ $\mu_0 = 0$.
 
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{T-Test for two Independent Samples}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test for two Independent Samples}

For independent random variables $$\alert{X_1, \ldots, X_n \stackrel{i.i.d.}{\sim} \mathcal{N} (\mu_x, \sigma_x^2)} \text{ and } \alert{Y_1, \ldots, Y_m \stackrel{i.i.d.}{\sim} \mathcal{N} (\mu_y, \sigma_y^2)}, $$

we first have to test for variance homogeneity using the so-called $F$-test.

\vspace{.4 cm}


\begin{tabular}{l l}
{\tcb Case 1:}& \begin{minipage}[t]{0.85 \textwidth} 
\vspace{-0.33cm}
{\tcb $\sigma_x^2 = \sigma_y^2 := \sigma^2$}

An estimator for $\sigma^2$ is given by 
$$S_p^2 := \frac{1}{n+m-2} \left(  \sum_{i=1}^n (X_i - \bar X)^2 +  \sum_{j=1}^m (Y_j - \bar Y)^2  \right),$$
which yields the test statistic
$$\alert{T_1 = \frac{(\bar X - \mu_x) - (\bar Y - \mu_y)}{S_p \sqrt{\frac{1}{n} + \frac{1}{m}}}\sim t_{n+m-2} := t_{df_1}}$$
\end{minipage}
\end{tabular}

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf T-Test for two Independent Samples}

\begin{tabular}{l l}
{\tcb Case 2:}& \begin{minipage}[t]{0.85 \textwidth} 
\vspace{-0.33cm}
{\tcb$\sigma_x^2 \neq \sigma_y^2$}

Here
$$S^2_{inh} := \frac{S_x^2}{n} + \frac{S_y^2}{m}$$
is an estimator for $var(\bar X - \bar Y) = \frac{\sigma_x^2}{n} + \frac{\sigma_y^2}{m}$ and yields the test statistic
$$\alert{T_2= \frac{\bar X - \bar Y }{S_{inh}}\sim t_{df_2}}$$
with $df_2$ being the next biggest integer to 
$$\frac{\left( S_x^2/n+S_y^2/m \right)^2}{S_x^4 / n^2 (n-1) + S_y^4 / m^2 (m-1)}$$
\end{minipage}
\end{tabular}

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf Test Procedure}

For the independent i.i.d.\ samples $\alert{x_1, \ldots, x_n}$ and  $\alert{y_1, \ldots, y_m}$ with respective \alert{means $\mu_x$} and \alert{$\mu_y$} and test value $\alert{\mu_0}$ proceed in {\tcb case $i$} ($i \in \{1,2\}$) as follows:

\vspace{.5cm}

\begin{enumerate}
\item fix a significance level $\alpha$ (e.g.\ $\alpha=0.1, \alpha=0.05, \ldots$)
\item choose (one of the following) null hypotheses
\begin{table}
\begin{tabular}{|c|c|c|}
$H_0: \ \mu_x - \mu_y \leq \mu_0$ & $H_0: \ \mu_x - \mu_y = \mu_0$ & $H_0: \ \mu_x - \mu_y \geq \mu_0$ \\
$H_1: \ \mu_x - \mu_y > \mu_0$ & $H_1: \ \mu_x - \mu_y \neq \mu_0$ & $H_1: \ \mu_x - \mu_y < \mu_0$
\end{tabular}
\end{table}
\item compute the test statistic $T_{\tcb i}$
\item reject the null hypothesis, iff
\begin{table}
\begin{tabular}{|c|c|c|}
$T_{\tcb i} > t_{df_{\tcb i},1-\alpha}$ & $T_{\tcb i} > t_{df_{\tcb i},1-\alpha/2}$ & $T_{\tcb i} < t_{df_{\tcb i},\alpha}$ \\
& or & \\
& $T_{\tcb i} < t_{df_{\tcb i},\alpha/2}$ &
\end{tabular}
\end{table}

\end{enumerate}

\end{frame}

%%%
\begin{frame}[fragile]
\frametitle{\bf Example}

We want to test at the \alert{$\alpha = 0.05$ level}, if the colesterol level is \alert{equal in} a group of  \alert{$n=10$ male and $m=11$ female} probands, i.e.\ we test

{\tcr 
\begin{table}
\begin{tabular}{ccc}
$H_0: \ \mu_{male} - \mu_{female} = 0$ & versus & $H_1: \ \mu_{male} - \mu_{female} \neq 0$.
\end{tabular}
\end{table}
}

{\tiny
\begin{Schunk}
\begin{Sinput}
> m <- c(118.86, 122.02, 118.04, 127.52, 122.59, 118.10, 123.20, 124.18, 123.55, 120.11)
> f <- c(125.86, 125.23, 121.55, 123.94, 126.71, 127.01, 122.05, 124.67, 120.76, 125.00, 129.22)
> t.test(m,f)
\end{Sinput}
\begin{Soutput}

	Welch Two Sample t-test

data:  m and f 
t = -2.3673, df = 17.639, p-value = 0.02958
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 -5.5004492 -0.3238517 
sample estimates:
mean of x mean of y 
 121.8156  124.7277 
\end{Soutput}
\end{Schunk}
}

The test yields a difference in means between the male and female group!
\end{frame}



%%%
\begin{frame}[fragile]
\begin{center}
{\tcb \Huge  Questions?}
\end{center}
\end{frame}

%%%%
%\begin{frame}

%\begin{figure}[htb]			
%		\begin{center}
%   	  		\includegraphics[width=0.45 \textwidth]{ex1plot.pdf} 
%   		\end{center} 
%\end{figure}
%\end{frame}

\end{document}

