\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{hyperref}

\usepackage{listings,relsize}

\begin{document}

\lstset{language=R,basicstyle=\smaller}

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.

{\bf \Large SHOW YOUR WORK!}  Any arithmetical answer must be expressed
as a common fraction (e.g. 2/3, 7/4), reduced to lowest terms.

{\bf 1.} (25) Urn I contains three blue marbles and three yellow ones, while
Urn II contains five and seven of these colors.  We draw a marble at
random from Urn I and place it in Urn II.  We then draw a marble at
random from Urn II.  Let $B_1$ denote the event that the first marble
drawn is blue, $Y_2$ denote the event that the second marble drawn is
yellow, and so on.  Fill in the blanks with equation numbers which will
serve as reasons for the steps,

\begin{eqnarray}
P(B_2) &=& P(B_1 \textrm{ and } B_2 \textrm{ or }
             Y_1 \textrm{ and } B_2) \\
       &=& P(B_1 \textrm{ and } B_2) + P(Y_1 \textrm{ and } B_2) 
             ~~~~ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \\ 
       &=& P(B_1) P(B_2 | B_1) + P(Y_1) P(B_2 | Y_1) 
             ~~~~ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 
\end{eqnarray}

{\bf 2.} (25) Fill in the blanks (and \underline{only} those blanks, no
extra code elsewhere) in the following R code, which returns the
(approximate) probability in (2.36) in the board game example:

\begin{lstlisting}[numbers=left]
boardsim <- function(nreps) {
   count4 <- 0
   countbonusgiven4 <- 0
   for (i in 1:                             ) {  # blank 1
      position <- sample(1:6,1)
      if (position == 3) {
                                                 # blank 2
         position <- (position + sample(1:6,1)) %% 8
      }                                          # blank 3
      if (position == 4) {
                                                 # blank 4
         if (bonus) countbonusgiven4 <- countbonusgiven4 + 1
      }
   }
   return(                                  )    # blank 5
}
\end{lstlisting}

{\bf 3.} (25) Suppose the random variable X takes on only the values 0 and
1.  Fill in the blank with either $<$, $\leq$, $=$, $\neq$, $\geq$ or
$no ~ relation$:

\begin{lstlisting}
EX               P(X = 1)
\end{lstlisting}

{\bf 4.} (25) Again for the board game example, suppose that the telephone
report is that A ended up at square 1 after his first turn.  Find the
probability that he got a bonus.

{\bf Solutions:}

{\bf 1.} (2.2), (2.5)

{\bf 2.}

\begin{lstlisting}
boardsim <- function(nreps) {
   count4 <- 0
   countbonusgiven4 <- 0
   for (i in 1:nreps) {
      position <- sample(1:6,1)
      if (position == 3) {
         bonus <- TRUE
         position <- (position + sample(1:6,1)) %% 8
      } else bonus <- FALSE
      if (position == 4) {
         count4 <- count4 + 1
         if (bonus) countbousngiven4 <- countbousngiven4 + 1
      }
   }
   return(countbousngiven4/count4)
}
\end{lstlisting}

{\bf 3.}  The answer is $=$, since

$$
EX = 1 \cdot P(X = 1) + 0 \cdot P(X = 0) = P(X = 1)
$$

{\bf 4.}  Landing at square 1 after one turn means R+B is either 1 or 9.
Let T = R + B.

\begin{eqnarray}
P(B > 0 | T = 1 \textrm{ or } T = 9) &=& 
\frac
   {P((T = 1 \textrm{ or } T = 9) \textrm{ and } B > 0)}
   {P(T = 1 \textrm{ or } T = 9)} \\
&=&
\frac
   {P((R,B) = (3,6))}
   {P((R,B) = (1,0) \textrm{ or } (R,B) = (3,6))} \\
&=& \frac
{\frac{1}{6} \cdot \frac{1}{6}}
{\frac{1}{6} + \frac{1}{6} \cdot \frac{1}{6}}
 \\
&=& \frac{1}{7}
\end{eqnarray}


\end{document}

