\documentclass{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.} Suppose in running R we have a data set {\bf people}, whose
first and second columns contain the heights and ages of the people in
our sample, with the third column showing their weights.  We will model
the regression function of weight on height and age as linear, i.e.
$E(\textrm{weight} | \textrm{height, age} = \beta_0 + \beta_1 \textrm{
height} + \beta_2 \textrm{ age}$.

This question will ask you to write R code, calling {\bf lm()}, etc.
For full credit, make efficient use of R (though you are restricted to
the parts of R that are in our course).  Also, treat the parts below
as sequential.  For example, if there is code you write for (a) which
you also need in (b), treat it as having already been executed when you
write your answer for (a).

   \begin{itemize}

   \item [(a)] (15) Give a R code that computes and prints out an
   approximate 95\% confidence interval for $\beta_0$.

   \item [(b)] (15) Give R code that computes and prints out an
   approximate 95\% confidence interval for the mean weight of all
   people of height 70.2 and age 28.

   \item [(c)] (15) Give R code that computes and prints out an estimate
   for $\sigma^2$, where we assume that $Var(Y|X=t) = \sigma^2$ for all
   t.  

   \end{itemize}

{\bf 2.} (10) Suppose we roll two dice, with the numbers of dots that come
up being denoted by U and V.  Let W = U + V.  Find $m_{W;U}(2)$.  (This
can be done intuitively or mathematically.)

{\bf 3.} (20) Suppose the regression of Y on a single predictor variable
X, with our model being $m_{Y;X}(t) = \beta_1 t$.  There is NO $\beta_0$
term in the model, so it is a ONE-parameter family.  Assume homogeneous
variance as usual, i.e. $Var(Y|X=t) = \sigma^2$ for all t.  Find exact
variance of $\widehat{\beta}_1$.  Your answer will be a function of
$X_i^{(1)}$, i = 1,...,n and $\sigma^2$.

{\bf 4.} Consider the Markov model of the shared-memory
multiprocessor system in our PLN.  In each part below, your answer will
be a function of $q_1,...,q_m$.

   \begin{itemize}

   \item [(a)] (10) For the case m = 3, find $p_{(2,0,1),(1,1,1)}$.

   \item [(b)] (15) For the case m = 6, give a compact expression for
   $p_{(1,1,1,1,1,1),(i,j,k,l,m,n)}$.  (Hint:  Some material in a
   previous PLN solves this problem immediately.)

   \end{itemize}

{\bf Bonus Question} Suppose that we have a classification setting in which Y =
0,1, and in which given Y = i, X has an exponential distribution with
$\lambda = \lambda_i$, i = 0, 1.  It is stated in the PLN that the
logistic model holds here.  Prove this.

{\bf Solutions:}

{\bf 1.a}

\begin{Verbatim}[fontsize=\relsize{-2}]
lmout <- lm(people[,3] ~ people[,1] + people[,2])
center <- lmout$coefficients[1]
covhat <- vcov(lmout)
se <- sqrt(covhat[1,1])
print(center-1.96*se,center+1.96*se)
\end{Verbatim}

{\bf 1.b} This was just like the homework problem.

\begin{Verbatim}[fontsize=\relsize{-2}]
a <- c(1,70.2,28)
tmp <- a %*% covhat
se <- tmp %*% a
se <- sqrt(se)
center <- a %*% lmout$coefficients
print(center-1.96*se,center+1.96*se)
\end{Verbatim}

{\bf 1.c}

\begin{Verbatim}[fontsize=\relsize{-2}]
diffs <- people[,3] - lmout$fitted.values
sumofsquares <- diffs %*% diffs
print(sumofsquares/nrow(people))
\end{Verbatim}

Some students called {\bf var()} on {\bf diffs}.  This actually works,
but for reasons far beyond the content of our course.

{\bf 2.} $m_{W;U}(2) = E(W | U = 2)$.  This expected value will be 2+EV
= 5.5. 

{\bf 3.} This is similar to the homework problem.

Since there is no $\beta_0$ in the model, there is no
1s column in Q:

\begin{equation}
Q = 
\left (
\begin{array}{c}
X_1^{(1)} \\
X_2^{(1)} \\
... \\
X_n^{(1)} 
\end{array}
\right )
\end{equation}

Then

\begin{equation}
Q'Q = \sum_{i=1}^n {X_i^{(1)}}^2
\end{equation}

and thus 

\begin{equation}
Var[\widehat{\beta_1}] =
\frac{\sigma^2}{\sum_{i=1}^n {X_i^{(1)}}^2}
\end{equation}

{\bf 4.a}  In state (2,0,1), at the end of the time slot one CPU at
Module 1 must choose Module 2 and the CPU at Module 3 must choose Module
3, or vice versa.  So, $p_{(2,0,1),(1,1,1)} = 2 q_2 q_3$.

{\bf 4.b}  Guess what, it's a multinomial situation!  At the end of the
time slot in state (1,1,1,1,1,1), each of the six CPUs will choose a
module for its next request.  That's six independent trials, with six
possible outcomes for each trial, and with the probabilities of those
outcomes in a trial being $q_1,...,q_6$.  So, the random vector 
(i,j,k,l,m,n) has a multinomial distribution with these parameters, and

\begin{equation}
p_{(1,1,1,1,1,1),(i,j,k,l,m,n)} =
\frac
{6!}
{i!j!k!l!m!n!}
\end{equation}

{\bf BQ} From the PLN, we know that

\begin{equation}
P(Y=1 | X=t) =
\frac{1}
{1 + \frac{(1-q) f_{X|Y=0}(t)}{q f_{X|Y=1}(t)}}
\end{equation}

The right-hand side is equal to

\begin{equation}
\frac{1}
{1 + 
\frac{(1-q) \lambda_0}{q \lambda_1} \cdot
e^{(\lambda_0-\lambda_1)t}
}
\end{equation}

So, we can see that the logistic model holds, with

\begin{equation}
\beta_0 = -\ln( \frac{(1-q) \lambda_0}{q \lambda_1}  )
\end{equation}

and 

\begin{equation}
\beta_1 = \lambda_1-\lambda_0
\end{equation}


\end{document}

