\documentclass[twocolumn]{article}
% \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{hyperref}

\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.
SHOW YOUR WORK.  Some problems may require answers to be in the form of
numerical expression.  An example is

\begin{equation*}
2/7 \cdot 1.39 + \sqrt{29.002} + \int_0^10.8 2t ~ dt  +
(1,2)  
\left (
   \begin{array}{cc}
   1 & 4 \\
   6 & 1   
   \end{array}
\right )     
\left (
   \begin{array}{c}
   6  \\
   6    
   \end{array}
\right )     
\end{equation*}
 
No variables are allowed in numerical expressions, nor are ``sigma sum''
series.

{\bf 1.} (15) Consider the quadratic model for mean wait time versus
backoff probability in the ALOHA model, p.155-156 and Equation (6.8).
Suppose we have just four b values, instead of 100.  Give a numerical
expression for Q.

{\bf 2.} (35) The code below reads in a file, {\bf data.txt}, with the
header record

\begin{Verbatim}[fontsize=\relsize{-2}]
"age", "weight", "systolic blood pressure", "height"
\end{Verbatim}

and then does the regression analysis.

Suppose we wish to estimate $\beta$ in the model

\begin{equation*}
\textrm{mean weight} = \beta_0 + \beta_1 \textrm{height} + \beta_2
\textrm{age}
\end{equation*}

Fill in the blanks in the code:

\begin{Verbatim}[fontsize=\relsize{-2}]
dt <- ____________(____________________________________)
regr <- lm(___________________________________________________)
cvmat <- _______________(regr)
cat("the estimated value of beta2-beta0 is",
   ____________________________________________________)
cat("the estimated variance of beta2 - beta0 is",
   _______________________ cvmat _________________________)
# calculate the matrix Q
q <- cbind(______________________________________________)
\end{Verbatim}

{\bf 3.} (30) Say we have a random sample $X_1,...,X_n$ from a uniform
distribution on 1,2,...,c, with c unknown and to be estimated.  As shown
in Section 4.4.3, the MLE is $\max_i X_i$.  Fill in the blanks in the
following simulation code:

\begin{Verbatim}[fontsize=\relsize{-2}]
sim <- function(c,n,nreps) {
   mle <- vector(length(nreps))
   for (i in 1:nreps):
      x <- sample(_________________________________)
      mle[i] <- _____________(________________________________)
  cat("bias = ",____________________ - _________________________)
}
\end{Verbatim}

{\bf 4.} (20) Say we have a random sample $X_1,...,X_n$ from a population
with mean $\mu$ and variance $\sigma^2$.  The usual estimator of $\mu$
is the sample mean $\bar{X}$, but here we will use what is called a {\it
shrinkage estimator}:  Our estimate of $\mu$ will be $0.9 \bar{X}$.
Find the mean squared error of this estimator, and give an inequality
(you don't have to algebraically simplify it) that shows under what
circumstances $0.9 \bar{X}$ is better than $\bar{X}$.  (Strong advice:
Do NOT ``reinvent the wheel.''  Make use of what we have already
derived.)

{\bf Solutions:}

{\bf 1}  Let d = 0.7/4.  Then

\begin{equation*}
Q =
\left (
   \begin{array}{lll}
   1 & 0.2 & (0.2+d)^2 \\
   1 & 0.2 & (0.2+2d)^2 \\
   1 & 0.2 & (0.2+3d)^2 \\
   1 & 0.2 & (0.2+4d)^2 \\
   \end{array}
\right )     
\end{equation*}

{\bf 2.}

\begin{Verbatim}[fontsize=\relsize{-2}]
dt <- read.table("data.txt",header=T)
regr <- lm(dt[,2] ~ dt[,4]+dt[,1])
cvmat <- vcov(regr)
cat("the estimated value of beta2-beta0 is",
   dt$coef[3] -dt$coef[1],"\n")
cat("the estimated variance of beta2hat - beta0hat is",
   t(c(-1,0,1)) %*% cvmat %*% c(-1,0,1),"\n") 
# calculate the matrix Q
q <- cbind(1,nrow(dt),dt[,4],dt[,1])  # note recycling
\end{Verbatim}

{\bf 3.}

\begin{Verbatim}[fontsize=\relsize{-2}]
sim <- function(c,n,nreps) {
   mle <- vector(length(nreps))
   for (i in 1:nreps):
      x <- sample(1:c,n,replace=T)
      mle[i] <- max(x)
  cat("bias = ",mean(mle) - c)
}
\end{Verbatim}

{\bf 4.}

\begin{equation*}
Var(0.9 \bar{X} ) = 0.81 \sigma^2 / n
\end{equation*}

\begin{equation*}
\textrm{bias}(0.9 \bar{X}) = 0.9 \mu - \mu
\end{equation*}

\begin{equation*}
Var(\bar{X} ) = \sigma^2 / n
\end{equation*}

\begin{equation*}
\textrm{bias}(\bar{X}) = \mu - \mu = 0
\end{equation*}

So, $0.9 \bar{X}$ is better than $\bar{X}$ if

\begin{equation*}
0.81 \cdot \frac{\sigma^2}{n} + 0.01 \mu^2 <
\frac{\sigma^2}{n}
\end{equation*}

or (optionally simplifying)

\begin{equation}
\mu < \sqrt{\frac{19}{n}} ~ \sigma
\end{equation}

\end{document}

