\documentclass[twocolumn]{article} 

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}
\usepackage{fancyvrb}
\usepackage{relsize}

\usepackage{amsmath}

\begin{document}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: {\bf Work only on this sheet} (on both sides, if needed); do not
turn in any supplementary sheets of paper. There is actually plenty of room
for your answers, as long as you organize yourself BEFORE starting writing.
In order to get full credit, SHOW YOUR WORK.

{\bf 1.} (10)  Look at the rogue network router example in Sec. 2.11.1
(p.18) of the current PLN.  The sample mean for the wireless data was
11.520.  From this find an approximate 95\% confidence interval for the
corresponding population mean.  Write your answer as a numerical
expression, e.g. $8 \pm 1.68$.

{\bf 2.} (15) On p.8 of our current PLN, the mean wait $\mu$ for a bus is
estimated via simulation.  An approximate 95\% confidence interval for
$\mu$ is printed out.  Write R code that prints out the standard error
of $\overline{W}$.

{\bf 3.} (15) Write an R function with prototype

\begin{Verbatim}[fontsize=\relsize{-2}]
propci <- function(x,alpha)
\end{Verbatim}

that will compute and print out a confidence interval of approximate
level $100(1-\alpha)\%$ for a population proportion p for a certain
trait.  Here {\bf x} is a vector of 1s and 0s, 1 meaning the trait is
present and 0 meaning not.

% {\bf x.}  Suppose I have a coin that I wish to test for fairness.  I
% will test the hypothesis $H_0: p = 0.5$ against the one-side alternate
% $H_A: p > 0.5$, where p is the probability of heads for this coin.  (Say
% I am somehow sure that p is not below 0.5, or that I am only concerned
% that the coin might be more heavily weighted towards heads.)  I will
% toss the coin four times, and will reject $H_0$ if $X \geq 3$, where X
% is the number of heads I get.

% In both problems below, write your answer as a numerical expression,
% e.g. $3.2+ \sqrt{19/8}$.
% 
% \begin{itemize}
% 
% \item [(a)] () Find the {\it exact} value of $\alpha$, the significance
% level for this test.
% 
% \item [(b)] () Suppose it turns out that X = 4.  What would be the
% p-value?
% 
% \end{itemize}

% {\bf 4.} Consider the lottery example.  Suppose in the past, each
% year 200 tickets were sold, but there is a rumor that this year $c >
% 200$.  Say you plan to buy a ticket, but you will not ask your friends
% what numbers are on their tickets.  Let X be the number on your ticket.
% You will test the hypothesis $H_0: c = 200$ vs. $H_A: c > 200$.
% (Suppose you are sure that c is not less than 200.) {\it Your test will
% be based on that single observation, X, and it will be an exact test,
% taking on this form:}  Reject $H_0$ if $X > r$ (note that this says $>$
% not $\geq$).
% 
% \begin{itemize}
% 
% \item [(a)] (10) What value of r should you use in order to get a
% significance level, i.e. $\alpha$, of 0.10?
% 
% \item [(b)] (10) Suppose you observe X = 197.  What will be the p-value?
% 
% \end{itemize}

{\bf 4.} Suppose $fX(t) = ct^{-2}$, for $c < t < \infty$.  We wish to test
$H_0: c = 1$ vs. $H_A: c > 1$, {\it using just a single observation X}.
We will use a significance level $\alpha$ of 0.10.

\begin{itemize}

\item [(a)] (10) In order to achieve $\alpha = 0.10$, our rule should be
to reject $H_0$ if X \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

\item [(b)] (10) If in actuality c = 5, what is the probability that we
make the right decision, i.e. that we reject $H_0$?

\end{itemize}

{\bf 5.} (10) Consider the lottery example.  Suppose someone asks
whether our estimator $\widehat{c}$ is biased.  Which answer is correct?
(i) Yes, it's biased upward; (ii) yes, it's biased downward; (iii) no,
it is not biased; (iv) it is sometimes biased upward, sometimes downward
and sometimes unbiased; (v) the term ``bias'' does not make sense in
this context; (vi) none of the above.  (Note:  Our $s^2$ is biased
downward as an estimator of $\sigma^2$.)

{\bf 6.} (15) Candidates X, Y and Z are vying for election.  Let $p_1$,
$p_2$ and $p_3$ denote the fractions (proportions!) of people planning
to vote for them.  We poll n people at random, yielding estimates
$\widehat{p_1}$, $\widehat{p_2}$ and $\widehat{p_3}$.  Y claims that she
has more supporters than the other two candidates combined.  Give a
formula for an approximate 95\% confidence interval for $p_2 -
(p_1+p_3)$.

{\bf 7.} (15) Think of sales of books A and B at an online bookseller.
The vendor is considering recommending B to anyone who buys A.  Define

\begin{eqnarray*}
p_1 &=& \textrm{P(buy A and buy B)} \\
p_2 &=& \textrm{P(buy A and not buy B)} \\
p_3 &=& \textrm{P(not buy A and buy B)} \\
p_4 &=& \textrm{P(not buy A and not buy B)}
\end{eqnarray*}


The seller has decided to recommend B if P(buy B $|$ buy A) $>$ 0.4.
Devise an approximate $\alpha = 0.05$ test of 

\begin{equation}
H_0:\ \textrm{P(buy B $|$ buy A)} = 0.4
\end{equation}

vs.  $H_A:$ P(buy B $|$ buy A) $>$ 0.4, based on our sample
estimators $\widehat{p_i}$, i = 1,2,3,4.

\onecolumn 

{\bf Solutions:}

{\bf 1.}  $11.520 \pm 1.96 \cdot 9.939/\sqrt{344}$

{\bf 2.}

\begin{Verbatim}[fontsize=\relsize{-2}]
cat("the standard error is",s/sqrt(nreps))
\end{Verbatim}

{\bf 3.}

\begin{Verbatim}[fontsize=\relsize{-2}]
propci <- function(x,alpha) {
   phat <- mean(x)
   se <- sqrt(phat*(1-phat)/length(x))
   cat(phat,"+-",qnorm(1-alpha/2)*se)
}
\end{Verbatim}

% {\bf 4.a}  We need to have $P(X > r) = \alpha$ under $H_0$.  But $P(X
% > r) = (c-r)/c$, so we set $(200-r)/200 = 0.10$, yielding r = 180.
% 
% {\bf 4.b}  We need to find the largest r such that we would still reject
% $H_0$ with X = 197.  This gives r = 196.  $P(X > 196) = 4/200 = 0.02$.

{\bf 4.a}  Set

\begin{equation}
\alpha = P(X > r) = \int_{r}^{\infty} ct^{-2}~ dt = \frac{c}{r}
\end{equation}

Under $H_0$ we have c = 1.  So, $r = 1/\alpha = 10$.

{\bf 4.b}

\begin{equation}
P(\textrm{reject} H_0) = P(X > 10) = 
\int_{10}^{\infty} 5t^{-2}~ dt = 0.5
\end{equation}

{\bf 5.}  The answer is (iii).

\begin{equation}
E(\widehat{c}) = 2 E(\overline{X}) - 1 = 2 EX - 1 = c
\end{equation}

{\bf 6.}  Our point estimate is

\begin{equation}
\widehat{p_2} - (\widehat{p_1}+\widehat{p_3})
\end{equation}
In order to get a confidence interval, we need the standard
error:

\begin{equation}
\label{var}
Var[\widehat{p_2} - (\widehat{p_1}+\widehat{p_3})]  =
Var(\widehat{p_2}) +
Var(\widehat{p_1}) +
Var(\widehat{p_3}) - 
2Cov(\widehat{p_2},\widehat{p_1}) -
2Cov(\widehat{p_2},\widehat{p_3}) -
2Cov(\widehat{p_1},\widehat{p_3}) 
\end{equation}

Now note that $Var(\widehat{p_i}) = p_i/n$ and for $i \neq j$ 
$Cov(\widehat{p_i},\widehat{p_j}) = -p_i p_j/n$.  Plug these into
(\ref{var}), substitute the sample estimates $\widehat{p_i}$, and take
the square root.  You now have the standard error.  Add and subtract 
1.96 times the standard error from the point estimate.

{\bf 7.}  First,

\begin{equation}
P(\textrm{buy B} | \textrm{buy A}) = \frac{p_1}{p_1+p_2}
\end{equation}

So, we are testing 

\begin{equation}
H_0: \frac{p_1}{p_1+p_2} = 0.4
\end{equation}

which after some algebra is seen to be the same as testing

\begin{equation}
H_0: 1.5p_1 - p_2 = 0
\end{equation}

So, we set

\begin{equation}
Z = \frac{1.5 \widehat{p}_1 - \widehat{p}_2}{s.e.}
\end{equation}

where s.e. is the standard error of the numerator, calculated in a
manner similar to what is done in Problem 6.  We then reject $H_0$
if Z $>$ 1.65.

\end{document}



