% This is a simple LaTex sample document that gives a submission format
%   for IEEE PAMI-TC conference submissions.  Use at your own risk.

% Make two column format for LaTex 2e.
\documentclass[11pt,twocolumn]{article} %,twocolumn
%\usepackage[dvips]{graphicx,graphics}
%\usepackage{times,amsmath,amsfonts}

% Use following instead for LaTex 2.09 (may need some other mods as well).
% \documentstyle[times,twocolumn]{article}

% Set dimensions of columns, gap between columns, and paragraph indent
\setlength{\textheight}{9.6in} \setlength{\textwidth}{6.9in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.2in}  % Centers text.
\setlength{\evensidemargin}{-.2in}

% Add the period after section numbers.  Adjust spacing.
\newcommand{\Section}[1]{\vspace{-8pt}\section{\hskip -1em.~~#1}\vspace{-3pt}}
\newcommand{\SubSection}[1]{\vspace{-3pt}\subsection{\hskip -1em.~~#1}
        \vspace{-3pt}}
\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}
\newcommand {\diff}[1] {\frac{\partial}{\partial #1}}
\newcommand{\jacob}[3]{\frac{\partial^2 #3}{\partial #1 \partial #2}}
\newcommand{\der}[2]{\frac{\partial #2}{\partial #1}}
\begin{document}

% Don't want date printed
%\date{January 23, 2003}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 312: Lecture 17\\
Two sample $t$ test}

% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
\date{November 9, 2004}
% For two authors (default example)
\maketitle \thispagestyle{empty}
\begin{enumerate}
\item Let $X_1,\cdots,X_n$ and $Y_1,\cdots,Y_m$ be two independent
samples from normal distributions with the same population variance,
i.e. $$X_i \sim N(\mu_X, \sigma^2) \mbox{ and } Y_j \sim
N(\mu_Y,\sigma^2).$$ The pooled estimator of $\sigma$ is
$$S_p^2 = \frac{(n-1)S_X^2 + (m-1)S_Y^2}{n+m-2}.$$

The test statistic for testing
$$H_0: \mu_X = \mu_Y \mbox{ vs. } H_1: \mu_X \neq \mu_Y$$
$$T=\frac{\bar X - \bar Y -(\mu_X -\mu_Y)}{S_p\sqrt{1/n + 1/m}} \sim t_{n+m-2}.$$
Reject $H_0$ if $|T| > t_{\alpha/2,n+m-2}$.


{\em Example.} A study was conducted to compare the weights of cats
and dogs. Weights of cats: 20, 21, 35, 13, 21, 10. Weights of dogs:
31, 10, 20, 40. Assume normality and equal variance for both cats
and dogs. Is there any difference between the weights of cats and
dogs?
\begin{verbatim}
> x<-c(20,21,35,13,21,10)
> y<-c(31,10,20,40)
> Sp<-sqrt((5*var(x)+3*var(y))/8)
[1] 10.52824
> t=(mean(x)-mean(y))/(Sp*sqrt(1/5+1/3))
> t
[1] -0.6827026
> qt(0.05,8)
[1] -1.859548
\end{verbatim}

\item Checking the equality of variance. This topic will be
discussed later in detail.
\begin{verbatim}
> var(x)
[1] 75.2
> var(y)
[1] 170.25
> var.test(x,y)

        F test to compare two variances

... p-value = 0.3975
alternative hypothesis: true ratio of variances
is not equal to 1 95 percent confidence interval:
 0.02967475 3.42920369
sample estimates: ratio of variances
         0.4417034
\end{verbatim}

%If you use R, it is very easy to do two sample hypothesis testing.
%\begin{verbatim}
%>t.test(x,y,alternative="two.sided",
%var.equal=TRUE,conf.level=0.9)
%        Two Sample t-test
%data:x and y t = -0.7725, df = 8, p-value = 0.462 alternative
%hypothesis: true difference in means is not equal to 0 90 percent
%confidence interval:
% -17.88739   7.38739


\end{verbatim}

\item The Welch-Satterthwaite $t$ test is
an alternative to the two sample t-test with equal variance, and is
used when the assumption that the two populations have equal
variances seems unreasonable. The problem with this method is that
it is asymptotically a t distribution.

\begin{verbatim}
>t.test(x,y,alternative="two.sided",
conf.level=0.9)
       Welch Two Sample t-test
data:x and y t = -0.7073,df = 4.778
 p-value = 0.5124 alternative
hypothesis: true difference in means
is not equal to 0 90 percent
confidence interval:
 -20.361647   9.861647
\end{verbatim}

%{\em Example 2.} A cat named Tom catches average 3 mice per day with
%the sample standard deviation of 1 for 10 days. A cat named Jerry
%catches average 4 mice per day with the sample standard deviation of
%1.2 for 8 days. Which cat do you think mice would
%hate the most at level 0.05?\\

\end{enumerate}
{\em Review problems.} Compute a CI for $\mu_X - \mu_Y$ in the
previous Example. Example 9.7


\end{document}
