\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.}  Consider the good ol' bus ridership examples.  Except when
referring to the examples in which there is a limit on the number of
passengers who can fit into the bus, assume no limit.

\begin{itemize}

\item [(a)] (15) Find the probability that in 10 consecutive stops, it
turns out that at exactly 3 of them there are no new passengers
boarding.  

\item [(b)] (10) Find Var(T) in (3.134).  (Helpful hint:  $B_1$ and $B_2$
have the same distribution, thus the same variance.)

\item [(c)] (10) In Sec. 4.5 (max 20 riders), find $p_{12}$.

\item [(d)] (15) Consider (4.2).  The variable {\bf t} there
corresponds to what variable in the code in Sec.\ 2.12.4?  (Assume the
code has been modified to reflect a 20-rider limit.)

\item [(e)] (10) In Sec. 4.5 (max 20 riders), suppose we code the
transition matrix in the R matrix {\bf p}.  Find $P(L_{28} = 18 | L_{25}
= 18)$.  Your answer must be a valid R expression that involves {\bf p};
no loops.

\item [(f)] (10) In Sec. 4.5, suppose the bus is tiny, with a capacity of
only 3 passengers.  Find the long-run average number of passengers who
alight from the bus.  Write your answer as a valid R expression in the
$\pi$ vector, which we will assume is named {\bf pivec}.  Remember, {\bf
pivec[1]} is $\pi_0$, etc.

\end{itemize}

{\bf 2.} (10) Find Var(L) in (3.118).  

{\bf 3.} (10) Suppose X has the density $t e^{-t}$ on $(0,\infty)$, 0
elsewhere.  Find EX.  You'll probably want to use  the {\bf exp()}
function in R.

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.a} {\bf dbinom(3,10,0.5)}

{\bf 1.b}

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

\begin{equation}
Var(B_1) = (0^2 0.5 + 1^2 0.4 + 2^2 0.1) - (0.4 + 2 \cdot 0.1)^2
\end{equation}

{\bf 1.c}

\begin{eqnarray}
p_{12} &=& P(L_{i+1} = 2 | L_i = 1) \\
&=& P(\textrm{the 1 doesn't alight, 1 new or the 1 alights, 2 new }) \\ 
&=& (0.8) (0.4) + (0.2) (0.1)
\end{eqnarray}

{\bf 1.d} {\bf nstops}

{\bf 1.e}

\begin{lstlisting}
(p %*% p %*% p)[19,19]
\end{lstlisting}

{\bf 1.f}  Mean of binomial is np.

\begin{lstlisting}
pivec[2] * (1 * 0.2) + pivec[3] * (2 * 0.2) + pivec[4] * (3 * 0.2) 
\end{lstlisting}

{\bf 2.}  From (3.117),

\begin{equation}
Var(L) = 3 \cdot \frac{1-0.1}{0.1^2}
\end{equation}

{\bf 3.}

\begin{lstlisting}
integrate(function(t) t^2 * exp(-t) ,0,Inf)$value
\end{lstlisting}

\end{document}

