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

\usepackage{amsmath}


\begin{document}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: {\bf \Large 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  1.}  (20) Consider the ALOHA example, Sec. 3.14.3.  Write a call to the
built-in R function {\bf dbinom()} to evaluate (3.123) for general m and
p.

{\bf 2.}  Consider the bus ridership example, Sec. 2.10.  Suppose upon
arrival to a certain stop, there are 2 passengers.  Let A denote the
number of them who choose to alight at that stop.

\begin{itemize}

\item [(a)] (10) State the parametric family that the distribution of A
belongs to.

\item [(b)] (20) Find $p_A(1)$ and $F_A(1)$, writing each answer in
decimal expression form e.g. $12^8 \cdot 0.32 + 0.3333$.

\end{itemize}

{\bf 3.} (20) Consider the following simple inventory model.  A store
has 1 or 2 customers for a certain item each day, with probabilities p
and q (p+1 = 1).  Each customer is allowed to buy only 1 item.

When the stock on hand reaches 0 on a day, it is replenished to r
items immediately after the store closes that day.

If at the start of a day the stock is only 1 item and 2 customers wish
to buy the item, only one customer will complete the purchase, and the
other customer will leave emptyhanded.  

Let $X_n$ be the stock on hand at the end of day n ({\it after}
replenishment, if any).  Then $X_1, X_2,...$ form a Markov chain, with
state space 1,2,...,r.

Write a function {\bf inventory(p,q,r)} that returns the $\pi$ vector
for this Markov chain.  It will call {\bf findpi1()}, similarly to the
two code snippets in p.65.

\onecolumn

{\bf Solutions:}

{\bf 1.}

\begin{lstlisting}[numbers=left]
dbinom(1,m,p)
\end{lstlisting}

{\bf 2.a} binomial

{\bf 2.b}

\begin{equation}
p_A(1) = 2 (0.2)(0.8)
\end{equation}

\begin{equation}
F_A(1) = P(A = 0 \textrm{ or } A = 1) =
(0.8)^2 +
2 (0.2)(0.8)
\end{equation}

{\bf 3.}

\begin{lstlisting}
inventory <- function(p,q,r) {
   tm <- matrix(rep(0,r^2),nrow=r)
   for (i in 3:r) {
      tm[i,i-1] <- p
      tm[i,i-2] <- q
   }
   tm[2,1] <- p
   tm[2,r] <- q
   tm[1,r] <- 1
   return(findpi1(tm))
}
\end{lstlisting}

\end{document}

