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

\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 train rendezvous problem in Section 8.2.4.  In
each of the following, give your answer as a double integral, dt ds.
In your electronic answers file, give your answer as five R expressions
separated by commas (and optional spaces), as follows:  
lower limit in outer integral;
upper limit in outer integral;
lower limit in inner integral;
upper limit in inner integral;
integrand.  For instance, for

$$
\int_{3}^{8} ~  
\int_{s}^{1-s} ~ (s+t)^2 ~ dt ~ ds
$$

write

\begin{lstlisting}
3, 8, s, 1-s, (s+t)^2
\end{lstlisting}

\begin{itemize}

\item [(a)] (15) Find $P(X + Y > 1.8)$.

\item [(b)] (20 Find $F_{X,Y}(0.4,0.3)$.

\end{itemize}

{\bf 2.} Suppose the random vector $(X_1,X_2)'$ has mean vector 
(1.5,2.0)'.  Suppose also that each $X_i$ has variance 4 and that
$Cov(X_1,X_2) = 1.0$.

\begin{itemize}

\item [(a)] (15) Find $E(2X_1+3X_2)$, as an R matrix expression.

\item [(b)] (15) Find $Var(X_1+X_2)$, as an R matrix expression.

\end{itemize}

{\bf 3.}  The function below computes the correlation matrix
corresponding to a given covariance matrix.  Element (i,j) of the former
is the correlation between the i$^{th}$ and the j$^{th}$ elements of the
given random vector.

\begin{lstlisting}
covtocorr <- function(covmat) {
   n <- nrow(covmat)
   stddev <- vector(length=n)
   cormat <- matrix(nrow=n,ncol=n)
   for (i in 1:n) {
      stddev[i] <- blank (a)
      cormat[i,i] <- blank (b)
   }
   for (i in 1:(n-1)) {
      for (j in (i+1):n) {
         tmp <- blank (c)
         cormat[i,j] <- tmp
         cormat[j,i] <- tmp
      }
   }
   return(cormat)
}
\end{lstlisting}

\begin{itemize}

\item [(a)] (5) Fill in blank (a).

\item [(b)] (5) Fill in blank (b).

\item [(c)] (15) Fill in blank (c).

\end{itemize}

{\bf 4.} (15) Suppose we have three electronic parts, with independent
lifetimes that are exponentially distributed with mean 2.5.  They are
installed simultaneously.  Find the mean time until the last failure
occurs.

{\bf Solutions:}

{\bf 1.a}

\begin{lstlisting}
0.8, 1, 1.8-s, 1, 2-s-t
\end{lstlisting}

{\bf 1.a} 

\begin{lstlisting}
0, 0.4, 0, 0.3, 2-s-t
\end{lstlisting}

{\bf 2.a}

\begin{lstlisting}
c(2,3) %*% c(1.5,2.0) 
\end{lstlisting}

{\bf 2.b}

\begin{lstlisting}
c(1,1) %*% matrix(c(4,1,1,4),nrow=2) %*% c(1,1)
\end{lstlisting}

{\bf 3.}

\begin{lstlisting}
covtocorr <- function(covmat) {
   n <- nrow(covmat)
   stddev <- vector(length=n)
   cormat <- matrix(nrow=n,ncol=n)
   for (i in 1:n) {
      stddev[i] <- sqrt(covmat[i,i])
      cormat[i,i] <- 1.0
   }
   for (i in 1:(n-1)) {
      for (j in (i+1):n) {
         tmp <- covmat[i,j] / (stddev[i]*stddev[j])
         cormat[i,j] <- tmp
         cormat[j,i] <- tmp
      }
   }
   return(cormat)
}
\end{lstlisting}

{\bf 4.}  As in the computer worm example in Section 8.3.8, the mean is

\begin{lstlisting}
1/(3*0.4) + 1/(2*0.4) + 1/(1*0.4) 
\end{lstlisting}


\end{document}
