This is an exam. You can use any written resource and the internet but you can not discuss the exam with anyone!

The uploaded file should be called midterm.Rmd

Problem 1

Consider the discrete random vector (X,Y) with density P(X=k,Y=j)=c(k+j), k=1,..5 and j=1,..,7. Find the covariance of X and Y.

  1. analytically

  2. using simulation

Problem 2

Consider the random variable with density shown here:

It has density

\[ f(x) = \left\{ \begin{array}[lll] 00 &\text{ for } &x<0, x>1\\ 4x &\text{ for } &0<x<0.5\\ 4(1-x) &\text{ for } &0.5<x<1\\ \end{array} \right. \]

Generate data from this density using the runif command only. I can do this in a way that generates one x for each runif. If you can do so as well you get bonus points.

Problem 3

Consider the random variable with density shown here:

It has density

\[ f(x) = \frac{16}3\left\{ \begin{array}[lll] 00 &\text{ for } &x<0, x>1\\ 2x &\text{ for } &0<x<0.25\\ 1-2x &\text{ for } &0.25<x<0.5\\ x-0.5 &\text{ for } &0.5<x<0.75\\ 1-x &\text{ for } &0.75<x<1\\ \end{array} \right. \]

Generate data from this density using the runif command only using the accept reject method. Draw the histogram and overlay it with the density to show your method works. I have a routine that requires generating on average 5.3 runifs for one x. If you can do better you can get some bonus points.

Problem 4

Consider the random vector (X, Y) with density

\[ \begin{aligned} &f(x,y)=\frac{c}{(1+x+y)^5} \end{aligned} \]

for \(x>0,y>0\), 0 otherwise.

Write a routine that generates data from this random vector. Draw the histograms of the marginals with the marginal densities to check your routine. Find P(1<X<2, 0.5<Y<1) both analytically and using your simulated data.