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

{\bf 1.} (20) Suppose we roll our usual three-sided die, with
probabilities 1/2, 1/3 and 1/6 of coming up 1, 2 or 3 dots,
respectively.  Let X denote the number of dots.  Find $h_X(2)$.  Express
your answer as a single common fraction.  

{\bf 2.} (25) Write R code (but not simulation) that computes the value of

$$
\int_{27}^{30}
\frac{1}{\sqrt{2\pi} \cdot 5} ~ e^{- 0.5 \left (\frac{t-28}{5}
\right )^2} ~ dt
$$


{\bf 3.} (25) Consider the disk performance example on p.76.  We will
scale things so that the track number is a continuous value in [0,1].
Fill in the gaps in the following code, which finds the (approximate)
mean time to satisfy a disk access request.  The arguments {\bf
fullsweep} and {\bf fullrotate} are the time needed to go from track 0.0
to track 1.0, and the time needed to make one revolution of the disk,
respectively.

\begin{Verbatim}[fontsize=\relsize{-2}]
disksim <- function(naccesses,fullsweep,fullrotate) {
   currtrack <- 0.5
   oldtrack <- 0.5
   sumacctime <- 0.0
   for (i in 1:naccesses) {
      currtrack <-                                   # gap
      seek <- abs(currtrack - oldtrack)
      oldtrack <- currtrack
      seektime <-                                    # gap
      rottime <-                                     # gap
      sumacctime <-                                  # gap
   }
   return(                )                          # gap
}
\end{Verbatim}

{\bf 4.} Consider the following variant of the bus ridership example on
p.20 and our current homework.  The probability that a passenger alights
is now q instead of 0.2, and the number of new passengers who wish to
board the bus at a stop, N, is now assumed to have a Poisson
distribution with parameter $\lambda$.  The capacity of the bus is still
c.  Answer the following, using expressions in c, q, $\lambda$ and the
stationary probability vector $\pi$ (you may not need them all).

\begin{itemize}

\item [(a)] (15) Find the transition probabilities $p_{00}$ and $p_{21}$.

\item [(b)] (15) Let S denote the number of stops that a passenger
travels.  If for instance she boards at stop 3 and alights at stop 8,
then S = 5.  Find Var(S)

\end{itemize}

{\bf Solutions:}

{\bf 1.}  

$$
h_X(2) = \frac{p_X(2)}{1-F_X(1)} =
\frac
{1/3}
{1-1/2} = 2/3
$$

{\bf 2.}

\begin{Verbatim}[fontsize=\relsize{-2}]
pnorm(30,mean=28,sd=5) - pnorm(27,mean=28,sd=5) 
\end{Verbatim}

{\bf 3.}

\begin{Verbatim}[fontsize=\relsize{-2}]
disksim <- function(naccesses,fullsweep,fullrotate) {
   currtrack <- 0.5
   oldtrack <- 0.5
   sumacctime <- 0.0
   for (i in 1:naccesses) {
      currtrack <- runif(1)
      seek <- abs(currtrack - oldtrack)
      oldtrack <- currtrack
      seektime <- seek * fullsweep
      rottime <- runif(0,fullrotate)
      sumacctime <- seektime + rottime
   }
   return(sumacctime/naccesses)
}
\end{Verbatim}

{\bf 4.a}  For $p_{00}$, that transition will occur if 0 board, which
has probability 

$$
\frac{\lambda^0 e^{-\lambda}}{0!} = e^{-\lambda}
$$

For the case $p_{21}$, either 1 alights and 0 board or 2 alight and 1
boards, so we have

$$
2 q (1-q)
\frac{\lambda^0 e^{-\lambda}}{0!} +
q^2 \cdot 
\frac{\lambda^1 e^{-\lambda}}{1!} =
q e^{-\lambda} [ 2(1-q) + q \lambda] =
q e^{-\lambda} [2 + (\lambda -2)q] 
$$

{\bf 4.b}  S has a geometric distribution with parameter q, so by
(3.75), $Var(S) = (1-q)/q^2$.

\end{document}

