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

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

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

Directions: {\bf \Large Work only on this sheet} (on both sides, if
needed).  MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf Important note:}  Remember that in problems calling for R code, you
are allowed to use any built-in R function, e.g. {\bf choose()}, {\bf
sum()}, {\bf integrate()}etc.  

{\bf 1.}  This problem concerns the dice game example, Section 7.3.5 of
our book.  In writing R code, assume that the matrix (7.60) is already
stored in a matrix named {\bf v}.

And there is good news!  Players now win \$8 each time they roll a four,
five or six.  Let $W_5$, $W_2$ and $W_8$ represent how much a player
wins in all her rolls that come up 1 dot, 2 or 3 dots, or 4, 5 or 6 dots,
respectively; for example, $W_2 = 2 Y$.  Denote the (column) vector
consisting of $W_5$, $W_2$ and $W_8$ by U.

Find the following quantities.  Unless specifically allowed, {\bf do not use
loops, {\bf +} or {\bf sum()}}.  Do not make corrections for continuity.

\begin{itemize}

\item [(a)] (10) $EW_2$

\item [(b)] (10) $Var(W_5)$

\item [(c)] (10) $P(Y = 12)$ (exact)

\item [(d)] (10) $P(Y \leq 12)$ (exact)

\item [(e)] (15) $P(Y \leq 12)$ (approximate)

\item [(f)] (15) $Cov(L)$ where $L = (X-Y,Y+Z)'$

\item [(g)] (10) $Cov(U)$

\end{itemize}

{\bf 2.} (20) Here you will write code to help Justin conduct his
opinion poll on Amanda's chances of winning the election.  It will be an
e-mail poll.  Assume (as will actually be the case when my grading
script runs) that we have the following global variables: {\bf voters},
a data frame containing information on all the registered voters in
Davis, one voter per row; {\bf emailcol}, the column number in which the
voters' e-mail addresses are stored; and {\bf n}, the number of people
to sample.  The code will display a simple random sample of e-mail
addresses.  Single line of code (semicolons OK), no loops.

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.a}  $2 \cdot 50\cdot 2/6$

{\bf 1.b}  $5^2 \cdot 50 \cdot 5/36$

{\bf 1.c} 

\begin{lstlisting}
dbinom(12,50,2/6)
\end{lstlisting}

{\bf 1.d} 

\begin{lstlisting}
pbinom(12,50,2/6)
\end{lstlisting}

{\bf 1.e}

\begin{lstlisting}
pnorm(12,50*2/6,sqrt(50*(2/6)*(4/6)))
\end{lstlisting}

{\bf 1.f}

\begin{lstlisting}
a <- rbind(c(1,-1,0),c(0,1,1)); a %*% v %*% t(a)
\end{lstlisting}

{\bf 1.g}

\begin{lstlisting}
a <- matrix(0,nrow=3,ncol=3); diag(a) <- c(5,2,8); a %*% v %*% t(a)
\end{lstlisting}

{\bf 2.}

\begin{lstlisting}
polled <- sample(1:nrow(voters),n,replace=F); voters[polled,emailcol]
\end{lstlisting}

\end{document}

