\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()}, etc.  

{\bf 1.}  Consider the derivation on p.19 of our text, starting with
(2.48).  We would like to add reasons for the steps, as in (2.9) and
(2.10).  Write your answers as equation numbers, e.g.  (8.88).  (Do not
include the English word ``equation.''  Remember, this will be graded by
computer, and in this problem the script will assume a numerical answer.)

\begin{itemize}

\item [(a)] (10) Give the ``mailing tube'' for (2.48).

\item [(b)] (15) Give the ``mailing tube'' for (2.49).

\end{itemize}

{\bf 2.}  Suppose three fair dice are rolled.  We wish to find 
the approximate probability that the first die shows fewer than 3 dots,
given that the total number of dots for the 3 dice is more than 8, using
the code below.

Fill in the blanks with {\bf a single line of code} in each case.

\begin{itemize}

\item [(a)] (15) Fill in Line 5.

\item [(b)] (15) Fill in Line 8.

\item [(c)] (15) Fill in Line 11.

\end{itemize}

\begin{lstlisting}[numbers=left]
dicesim <- function(nreps) {
   count1 <- 0
   count2 <- 0
   for (i in 1:nreps) {
      
      if (sum(d) > 8) {
         count1 <- count1 + 1
     
      }
   }
   
}
\end{lstlisting}

{\bf 3.}  Consider the bus ridership example, in Sec. 2.11 of our text.

\begin{itemize}

\item [(a)] (15) Find the probability that fewer people board at the
second stop than at the first.

\item [(b)] (15) Someone tells you that as she got off the bus at the
second stop, she saw that the bus then left that stop empty.  Find the
probability that she was the only passenger when the bus left the first
stop.

\end{itemize}

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.a} (2.2)

{\bf 1.b} (2.5)

{\bf 2.}

\begin{lstlisting}[numbers=left]
dicesim <- function(nreps) {
   count1 <- 0
   count2 <- 0
   for (i in 1:nreps) {
      d <- sample(1:6,3,replace=T)
      if (sum(d) > 8) {
         count1 <- count1 + 1
         if (d[1] < 3) count2 <- count2 + 1
      }
   }
   return(count2 / count1)
}
\end{lstlisting}

{\bf 3.a}

\begin{eqnarray}
P(B_2 < B_1) 
&=& P(B_1 = 1 \textrm{ and } B_2 < B_1 \textrm{ or } 
      B_1 = 2 \textrm{ and } B_2 < B_1) \\ 
&=& 0.4 \cdot 0.5 +
    0.1 \cdot (0.5 + 0.4) 
\end{eqnarray}

{\bf 3.b} We are given that $L_2 = 0$.  But we are {\it also} given that
$L_1 > 0$.  Then

\begin{eqnarray}
P(L_1 = 1 | L_2 = 0 \textrm{ and } L_1 > 0)&=& 
   \frac
      {P(L_1 = 1 \textrm{ and } L_2 = 0)}
      {P(L_2 = 0 \textrm{ and } L_1 > 0)} \\ 
&=& 
   \frac{P(B_1 = 1 \textrm{ and } L_2 = 0)}
   {P(
      B_1 = 1 \textrm{ and } L_2 = 0 \textrm{ or } 
      B_1 = 2 \textrm{ and } L_2 = 0)} \\
&=& \frac
      {(0.4)(0.2)(0.5)}
      {(0.4)(0.2)(0.5) + (0.1)(0.2)^2(0.5)}
\end{eqnarray}

\end{document}

