% 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.2in} \setlength{\textwidth}{6.875in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.1875in}  % Centers text.
\setlength{\evensidemargin}{-.1875in}

% 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{Stat312: Sample Midterm II.}
% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
% For two authors (default example)
\maketitle \thispagestyle{empty}
\begin{enumerate}

\item Consider the sample of fat content of 10 randomly selected
hot dogs: 25, 21, 22, 17, 29, 25, 16, 20, 19, 22. Suppose that
these are from a normal population. We want to test if the fat content
of hot dogs is 23.\\
(a) State the null and alternate hypotheses (5 points).\\
(b) What is your test statistic and a rejection rule at 95$\%$ level? (5 points)\\
(c) Is the fat content of hot dogs 23? Explain your result (5
points).\\
(d) Compute the probability of type I error when you do the
hypothesis test using the test statistic in (b). Explain your result (5 points).\\
(e) Define the $P$-value and compute the $P$-value for using the
test statistic in (b) (5 points).
\begin{verbatim}
>X<-c(25,21,22,17,29,25,16,20,19,22)
>sum(X)
[1] 216
> var(X)
[1] 15.6
> qnorm(c(0.025,0.05))
[1] -1.96 -1.64
> qt(0.025,c(9,10))
[1] -2.26 -2.23
> pt(c(1.0,1.1,1.2,1.3,1.4,1.5),9)
[1] 0.83 0.85 0.87 0.89 0.90 0.92
\end{verbatim}

{\em Solution.} (a) Let $\mu$ be the population mean of the fat
content in hot dogs. Then $H_0: \mu = 23$ and $H_1: \mu \neq 23$.
(b) Since the population variance is unknown, the test statistic
should be the $t$ statistic given by $T=(\bar X
-\mu)/(S/\sqrt{10})$. Note that $t_{0.025,9} = 2.26$. So we reject
$H_0$ if $|T| > 2.26$. (c) $s^2=15.6$. The $t$-value is $t=(\bar x
-23)/(s/\sqrt{10})=-1.12$. Since the value is not in the
rejection region, we do not reject $H_0$. So we may assume that
the fat content of hot dogs is 23. (d) By definition $\alpha =
P(\mbox{ reject } H_0| H_0 \mbox{ is true }) = P( |T| >
t_{0.025,9} =0.05$. You should answer this question without
computing anything. (e) The $P$-value is the smallest level of
significance at which $H_0$ would be rejected. For given
$t$-value $t=1.12$, we reject $H_0$ if $ |t| > t_{\alpha/2,9}$ at
$\alpha$ level. So $P\mbox{-value} = P(|T| >
1.12)=2P(T>1.12)=2(1-P(T \leq 1.12))=2(1-0.85)=0.3$


\item 4 out of 10 doctors knew the generic name for the
drug methadone. We want to test if fewer than half of all doctors
know the generic name for methadone.\\
(a) State the null and alternate hypotheses. Define population
parameters clearly (5 points).\\
(b) What is your test statistic? Explain your result
(10 points).\\
(c) What is the distribution of the test statistic in (b) under
the null hypothesis? Explain your result(5 points).\\
(d) Perform the hypothesis test using a significance level of 0.2
(10 points).
\begin{verbatim}
> pbinom(0:10,10,0.5)
 [1] 0.00 0.01 0.055 0.17 0.38
 [6] 0.62 0.83 0.95 0.99 1.00
[11] 1.00
\end{verbatim}

{\em Solution} (a) Let $p$ be the proportion of doctors who knew
the generic name. Then $H_0: p=0.5$ vs. $H_1: p < 0.5$. (b) Since
the sample size is too small, you can not use $Z$ statistic. Let
$X_i$ be a Bernoulli random variable defined as $X_i=0$ if the
$i$-th doctor know and $X_i=0$ if the $i$-th doctor does not know
the generic name. Note that $P(X_i=1)=p, P(X_i=0)=1-p$. The point
estimator for $p$ would be $\hat p=\sum_{i=1}^{10} X_i/10=\bar X$.
We will take $\sum_{i=1}^{10} X_i$ rather than $\bar X$ as the
test statistic because it will be much easier to figure out the
distribution of the test statistic. (c) If you answered $\bar X$
in (b), you may have some difficulty answering this question. Note
that $\sum_{i=1}^{10} X_i \sim \mbox{Binomial}(10,p)$. We went
through binomial distributions a couple of times during the
lectures. Also review STAT311. Under $H_0$, $\sum_{i=1}^{10} X_i
\sim \mbox{Binomial}(10,0.5)$. (d) We reject $H_0$ if
$\sum_{i=1}^{10} x_i$ is small. Note that $P(\sum_{i=1}^{10} X_i
\leq 3) = 0.17$ while $P(\sum_{i=1}^{10} X_i \leq 4) = 0.38$. So
we reject $H_0$ at level 0.2 if $\sum_{i=1}^{10} x_i \leq 3$.
Since we have $\sum_{i=1}^{10} x_i =4$, we do not reject $H_0$.

\item There are two coins. You threw the first coin 100 times
and observed 40 heads. When you threw the second coin 110 times,
you observed 50 heads. You want to test if the two coins give the
same number of heads.\\
(a) State the null and alternate hypotheses (5 points)?\\
(b) What is your test statistic and its distribution? (5 points)\\
(c) Do they give the same number of heads? Test it at level 0.3 (10 points).\\
(d) What is a  $68\%$ confidence interval for the difference
between the probabilities of getting heads (10 points)?
\begin{verbatim}
> pnorm(1:10/10)
 [1] 0.54 0.58 0.62 0.66 0.69
 [6] 0.73 0.76 0.79 0.82 0.84
\end{verbatim}

{\em Solution.} (a) Let $p_1$ and $p_2$ be the probabilities of
getting heads for the first and the second coins respectively.
Then $H_0: P_1 = p_2$ vs. $H_1:p_1 \neq p_2$. (b) Let $X$ be the
number of heads when you throw the first coin $n=100$ times and
$Y$ be the number of heads when you throw the second coin $m=110$
times. The point estimator for $p_1 -p_2$ is $\hat p_1 -\hat p_2
=X/n -Y/m$. Then the test statistic is $$Z=\frac{X/n
-Y/m}{\sqrt{p(1-p)(1/n + 1/m)}} \sim N(0,1),$$ where $p=p_1=p_2$.
Since $p$ is unknown, you estimate it by pooling the samples:
$\hat p =(x+y)/(m+n)$. (c) $\hat p = (40+50)/(100+110) = 0.43$
and $z=-0.60$. Since we reject $H_0$ if $|z|$ is large, the
$P$-value would be $P(|Z|> 0.6) = 2P(Z>0.6) = 2(1-P(Z \leq
0.6))=2(1-0.73)=0.54$. Since the $P$-value is larger than 0.3, we
do not reject $H_0$ at level 0.3. (d) Although $\tt{qnorm}$ values
are not given, we can estimate $z_{0.32/2}$ from the R output.
Note that $P(Z < z_{0.32/2}) = 1- P(Z > z_{0.32/2}) = 1-0.32/2 =
0.84$.S So $z_{0.32/2} =1$. A $100(1-\alpha)\%$ confidence
interval is
$$\hat p_1 - \hat p_2 \pm z_{\alpha/2}\sqrt{\hat p_1 (1-\hat
p_1)/100 + \hat p_2 (1-\hat p_2)/110}.$$ With $\hat p_1 = 40/100$
and $\hat p_2 =50/100$, we get $[-0.12, 0.01]$.

\item Bonus doggy problem: name the title of a movie where there is a dog
carrying a human body part in its mouth(1 point). {\em Solution.}
Akira Kurosawa's Yojimbo. He is a Japanese movie director. Many
of his Samurai movies had influenced Hollywood western movies.
Self study problem: Compare Kurosawa's Yojimbo (1961) and Clint
Eastwood's spaghetti western A Fistful of Dollars (1964). In
Yojimbo, there is a somewhat morbid but funny scene about a dog
carrying a human hand in its mouth at the beginning of the movie.
\end{document}
