\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}

%NEW COMMANDS


\newcommand{\mat}[1]{\mbox{\boldmath{$#1$}}}
\newcommand{\proc}[1]{$\{#1_t\}$}
\newcommand{\eps}{\varepsilon}
\newcommand{\var}{{\rm Var}}
\newcommand{\cov}{{\rm Cov}}
\newcommand{\nid}{{\rm NID}}
\newcommand{\iid}{{\rm IID}}
\newcommand{\norm}{{\rm N}}
\newcommand{\wn}{{\rm WN}}
\newcommand{\diag}{{\rm diag}}


%FORMATTING
\thispagestyle{empty}
\parindent 0pt
\parskip 11pt
\topmargin -1cm

\oddsidemargin -0.5cm \evensidemargin -0.5cm \textwidth 16.5cm
\textheight 23.5cm

%DOCUMENT
\begin{document}

\begin{center}
\huge ST402 Principals and Methods of Statistical Practice \\
\huge Mid-term Test Solutions \\
\end{center}

\begin{enumerate}
%
% Qu 1
%
\item
   \begin{enumerate}
   \item The probabilities here are easily found
   \begin{eqnarray*}
    P(X=1)&=&\frac{2}{3}\\
    P(X=2)&=&\frac{1}{3}\\
    P(Y=0|X=1)&=&\frac{1}{3}\\
    P(Y=1|X=1)&=&\frac{2}{3}\\
    P(Y=1|X=2)&=&\frac{2}{3}\\
    P(Y=2|X=2)&=&\frac{1}{3}.\\
   \end{eqnarray*}
   So
   \begin{eqnarray*}
   E(Y|X=1)&=&0\times\frac{1}{3}+1\times\frac{2}{3}=\frac{2}{3}\\
   E(Y|X=2)&=&1\times\frac{2}{3}+2\times\frac{1}{3}=\frac{4}{3},\\
   \end{eqnarray*}
    and
    \[
   E(Y)=E(Y|X=1)P(X=1)+E(Y|X=2)P(X=2)
    \]
    \[
    =\frac{2}{3}\times\frac{2}{3}+\frac{4}{3}\times\frac{1}{3}=\frac{8}{9}.
    \]
   \item
   \begin{eqnarray*}
   P(Y=0)&=&P(Y=0|X=1)P(X=1)=\frac{1}{3}\times\frac{2}{3}=\frac{2}{9}.\\
   P(Y=1)&=&P(Y=1|X=1)P(X=1)+P(Y=1|X=2)P(X=2)\\
   &=&\frac{2}{3}\times\frac{2}{3}+\frac{2}{3}\times\frac{1}{3}=\frac{6}{9}.\\
   P(Y=2)&=&P(Y=2|X=2)P(X=2)=\frac{1}{3}\times\frac{1}{3}=\frac{1}{9}.
   \end{eqnarray*}
    \end{enumerate}
%
%
% Qu 2
%
\vspace{1cm} \item


\begin{enumerate}
\item The total probability is 1, so
\begin{eqnarray*}
1&=&\int_0^1\left(\int_0^{1-x}k(x+y)dy\right)dx\\
&=&\int_0^1\left[\frac{k(x+y)^2}{2}\right]_{y=0}^{y=1-x}dx\\
&=&\int_0^1\frac{k}{2}(1-x^2)dx=\frac{k}{2}\left[x-\frac{x^3}{3}\right]_0^1=\frac{k}{3}.
\end{eqnarray*}
So, $k=3$.

 \item
 \begin{eqnarray*}
 f_Y(y)&=&\int_0^{1-y}k(x+y)dx\\
 &=&\left[\frac{3(x+y)^2}{2}\right]_{x=0}^{x=1-y}\\
 &=&\frac{3}{2}(1-y^2).
 \end{eqnarray*}
 If $0<y<1$, $0<x<1-y$ then
 \begin{eqnarray*}
 f_{X|Y}(x|y)&=&\frac{f_{X,Y}(x,y)}{f_Y(y)}\\
 &=&\frac{3(x+y)}{\frac{3}{2}(1-y^2)}\\
 &=&\frac{2(x+y)}{1-y^2}.
 \end{eqnarray*}
For other values of $x,y$, we have $f_{X|Y}(x|y)=0$.

\begin{eqnarray*}
E\left[X\left|Y=\frac{1}{2}\right.\right]&=&\int_0^{\frac{1}{2}}x\frac{2(\frac{1}{2}+x)}{1-\frac{1}{4}}dx\\
&=&\frac{4}{3}\int_0^{\frac{1}{2}}x(1+2x)dx\\
&=&\frac{4}{3}\left[\frac{x^2}{2}+\frac{2x^3}{3}\right]_0^{\frac{1}{2}}\\
&=&\frac{4}{3}\left[\frac{1}{8}+\frac{2\times\frac{1}{8}}{3}\right]\\
&=&\frac{5}{18}.
\end{eqnarray*}
\end{enumerate}
%
\vspace{1cm}
% Qu 3
%
\item
\begin{enumerate}
 \item Because of independence
 \[
 f_{Y,Z}(y,z)=\begin{cases}\lambda^2e^{-\lambda(y+z)}&\text{$0<y<\infty$, $0<z<\infty$}\\
                                  0&\text{elsewhere}\end{cases}.
 \]
 \item
\begin{eqnarray*}
u&=&z+y\\
v&=&\frac{z}{y}
\end{eqnarray*}
so
\begin{eqnarray*}
y&=&\frac{u}{1+v}\\
z&=&\frac{uv}{1+v}.
\end{eqnarray*}
\begin{eqnarray*}
\frac{\partial (u,v)}{\partial (y,z)}&=&\begin{vmatrix}\frac{\partial u}{\partial y}&\frac{\partial u}{\partial z}\\
                                                       \frac{\partial v}{\partial y}&\frac{\partial v}{\partial z}
                                        \end{vmatrix}\\
                                        &=&\begin{vmatrix}1&1\\
                                                       -\frac{z}{y^2}&\frac{1}{y}
                                        \end{vmatrix}\\
                                        &=&\frac{1}{y}+\frac{z}{y^2}\\
                                        &=&\frac{y+z}{y^2}\\
                                        &=&\frac{(1+v)^2}{u}.
\end{eqnarray*}
So, for $0<u<\infty$, and $0<v<\infty$,
\[
\left|\frac{\partial (u,v)}{\partial (y,z)}\right|=\frac{(1+v)^2}{u}
\]
\item
\begin{eqnarray*}
f_{U,V}(u,v)&=&\lambda^2e^{-\lambda u}\left|\frac{\partial
(u,v)}{\partial (y,z)}\right|\\
&=&\begin{cases}\lambda^2e^{-\lambda
u}\frac{u}{(1+v)^2}&\text{$0<u<\infty$,
$0<y<\infty$}\\0&\text{elsewhere}\end{cases}.
\end{eqnarray*}
Since the joint density factorises into the product of a gamma density
function for $U$ and a Pareto density function for $V$, the random
variables $U,V$ are independent

\end{enumerate}
%
%

% Qu 4
%

\item Let

\begin{enumerate}
 \item
 \begin{eqnarray*}
 E[X]&=&E[E[X|N]]\\
 &=&E\left[E\left[\sum_{i=1}^NY_i\left| N\right.\right]\right]\\
 &=&E\left[\sum_{i=1}^NE\left[Y_i\left| N\right.\right]\right]\\
 &=&E\left[N\frac{1}{2}\right]\\
 &=&\frac{\lambda}{2}.
 \end{eqnarray*}
 As for the MGF,
\begin{eqnarray*}
 E\left[e^{tX}\right]&=&E\left[E\left[e^{tX}\left| N\right.\right]\right]\\
 &=&E\left[E\left[e^{t\sum_{i=1}^NY_i}\left|N\right.\right]\right]\\
 &=&E\left[\prod_{i=1}^NE\left[e^{tY_i}\left|N\right.\right]\right]\\
 &=&E\left[M_Y(t)^N\right]\\
 &=&E\left[\left(\frac{1}{2}(1+e^t)\right)^N\right]\\
 &=&\exp\left[\lambda\left[\frac{1}{2}\left(1+e^t\right)-1\right]\right]\\
 &=&\exp\left[\frac{\lambda}{2}\left(e^t-1\right)\right].
 \end{eqnarray*}
 So $X$ has a Poisson distribution with mean $\lambda/2$.
 \item
 Now we have
 \[
 M_N(s)=\frac{\frac{1}{2}}{1-\frac{1}{2}e^s}=\frac{1}{2-e^s}.
 \]
 So,
 \[
 E[X]=E[N]E[Y]=1\times \frac{1}{2}=\frac{1}{2},
 \]
and
\begin{eqnarray*}
M_X(t)&=&\frac{1}{2-\frac{1}{2}(1+e^t)}\\
&=&\frac{1}{\frac{3}{2}-\frac{1}{2}e^t}\\
&=&\frac{\frac{2}{3}}{1-\frac{1}{3}e^t}.
\end{eqnarray*}
So, $X$ has a geometric distribution with
\[
P(X=k)=\frac{2}{3}\left(\frac{1}{3}\right)^k
\]
for $k=0,1,2,\dots$.
\end{enumerate}
\end{enumerate}
\end{document}
