\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: MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} Consider the coin/die game, p.83.

\begin{itemize}

\item [(a)] (15) Find $Var(M)$.

\item [(b)] (15) Find $Var(W ~|~ M = 8)$.

\end{itemize}

{\bf 2.}  Consider the bus ridership example once again, in this case
in Sec. 3.16.  

\begin{itemize}

\item [(a)] (20) Find $P(T = 5)$.

\item [(b)] (15) Find $p_{B_1,T}(1,3)$.

\item [(c)] (15) Find $Var(T)$.  (You may find that some of the
computation has already been done for you in the text.)

\end{itemize}

{\bf 3.} (20) Below is a revised version of the bus ridership simulation
on p.26.  It computes the same quantity, but in a somewhat more
efficient manner.  Fill in the blanks.

\begin{lstlisting}
bussim <- function(nstops,nreps) {
   b <- sample(0:2, ________ ,  // blank (a)
      replace=TRUE,prob=c(0.5,0.4,0.1))
   b <- matrix(b,nrow=nreps)
   passeq0 <- vector(length=nreps)
   for (i in 1:nreps ) {
      passengers <- 0
      for (j in 1:nstops) {
         if (passengers > 0) 
            passengers <- passengers - 
               ________  // blank (b)
         passengers <- passengers + 
            ________  // blank (c)
      }
      passeq0[i] <- ________  // blank (d)
   }
   mean(passeq0)
}      
\end{lstlisting}

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1a.}  M has a geometric distribution with p = 1/6, so 
$Var(M) = (1 - 1/6) / (1/6)^2$ from our section on that distribution.

{\bf 1b.}  As noted in the example, give M = k, W has a binomial
distribution with k trials and success probability 0.5.  That
distribution has variance $k \cdot 0.5 (1 - 0.5)$, from our text
section on that distribution.

{\bf 2a.}  Ask the famous question, ``How can it happen?''  The only way
is $B_1 = 1 \textrm{ and } B_2 = 1$, which has probability $0.4^2$ .

{\bf 2b.}  We are being asked for $P(B_1 = 1 \textrm{ and } T = 3)$.
Again, ``How can it happen?''  Here we must have $B_1 = 1 \textrm{ and }
B_2 = 0$, which has probability $0.4 \cdot 0.5$.

{\bf 2c.}  

\begin{equation}
Var(T) = 3^2 Var(B_1) + 2^2 Var(B_2) = 13 Var(L_1)
\end{equation}

Then from p.59,

\begin{equation}
Var(L_1) = 0.4+4 \cdot 0.1-(0.4+2 \cdot 0.1)^2
\end{equation}

{\bf 3.}

\begin{lstlisting}
}m <- function(nstops,nreps) {
   b <- sample(0:2,nreps*nstops,
      replace=TRUE,prob=c(0.5,0.4,0.1))
   b <- matrix(b,nrow=nreps)
   passeq0 <- vector(length=nreps)
   for (i in 1:nreps ) {
      passengers <- 0
      for (j in 1:nstops) {
         if (passengers > 0) 
            passengers <- 
               passengers - rbinom(1,passengers,0.2)
         passengers <- passengers + b[i,j]
      }
      passeq0[i] <- passengers == 0
   }
   mean(passeq0)
}      
\end{lstlisting}

\end{document}
