% $Header: /cvsroot/latex-beamer/latex-beamer/examples/beamerexample5.tex,v 1.22 2004/10/08 14:02:33 tantau Exp $

\documentclass[11pt]{beamer}
\usepackage{amscd}

%\usetheme{Madrid} % Darmstadt, Boadilla


\mode<presentation> {
  \usetheme{Madrid}
  \setbeamercovered{transparent}
}

\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsbsy,alltt,amsmath,times}
\usepackage{epsfig, color, graphicx, rotate, colordvi}
%\usepackage{fancybox,fancyhdr,times,subfigure}
\usepackage{hyperref, mathptmx}


\setbeamercovered{dynamic}

\newcommand{\Lang}[1]{\operatorname{\text{\textsc{#1}}}}

\newcommand{\Class}[1]{\operatorname{\mathchoice
  {\text{\sf \small #1}}
  {\text{\sf \small #1}}
  {\text{\sf #1}}
  {\text{\sf #1}}}}

\newcommand{\NumSAT}      {\text{\small\#SAT}}
\newcommand{\NumA}        {\#_{\!A}}

\newcommand{\barA}        {\,\bar{\!A}}

\newcommand{\Nat}{\mathbb{N}}
\newcommand{\Set}[1]{\{#1\}}

\newtheorem{thm}{Result}%[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{defn}[thm]{Definition}
\newtheorem{exam}{Example}%[section]
\newtheorem{rem}{Remark}

\newcommand{\cred}{\textcolor {red}}
\newcommand{\cblue}{\textcolor {blue}}
\newcommand{\cgreen}{\textcolor {green}}

\def\ul{\underline}

\def\sign{\;{\rm sign}}
\def\rank{\;{\rm rank}}
\def\disp{\displaystyle}
\def\sn{\sqrt{n}}
\def\Pr{\mathrm{P}}

\def\Cov{\;{\rm Cov}}
\def\L{\underline L}
\def\LL{\overline L}

\def\balpha{{\boldsymbol{\alpha}}}
\def\cal{\mathcal}
\def\conas{\stackrel{a.s.} {\longrightarrow}}         % conv. a.s.
\def\conp{\stackrel{\cal P} {\longrightarrow}}        % conv. in probability
\def\conD{\stackrel{\mathcal{L}} {\longrightarrow}}        % conv. in distribution
\def\conw{\stackrel{\mathcal{L}} {\rightarrow}}        % conv. in distribution
\def\hat{\widehat}
%\def\endproof{\begin{flushright}$\lozenge$\end{flushright}}
\def\Proof{\noindent{\it Proof }}
\def\endproof{\hfill{$\Box$}}
\newcommand{\wcon}{\stackrel{\mathcal{L}}{\longrightarrow}}
\def\Var{\mbox{var}}
\def\br{\begin{array}}
\def\er{\end{array}}

%%%%%%%%%%%%%%% MY DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Put your own definitions
%
\def\VaR{{\rm VaR}}
\def\E{{\rm E}}
\def\beqrs{\begin{eqnarray*}}           %\beqrs
\def\eeqrs{\end{eqnarray*}}             %\eeqrs

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfdeclaremask{tu}{beamer-tu-logo-mask}
\pgfdeclaremask{computer}{beamer-computer-mask}
\pgfdeclareimage[interpolate=true,mask=computer,height=2cm]{computerimage}{beamer-computer}
\pgfdeclareimage[interpolate=true,mask=computer,height=2cm]{computerworkingimage}{beamer-computerred}
\pgfdeclareimage[mask=tu,height=.5cm]{logo}{beamer-tu-logo}

\logo{\pgfuseimage{logo}}

\title[Stat 609 Lecture 16]{Stat 609: Mathematical Statistics \\ Lecture 16}
\author[UW-Madison]{Jun Shao}
\institute[Statistics]{%
%  Department of Statistics\\
%  University of Wisconsin\\
%  Madison, WI 53706, USA\\
%~~~\\
  }
\date[2015]{}

\colorlet{redshaded}{red!25!bg}
\colorlet{shaded}{black!25!bg}
\colorlet{shadedshaded}{black!10!bg}
\colorlet{blackshaded}{black!40!bg}

\colorlet{darkred}{red!80!black}
\colorlet{darkblue}{blue!80!black}
\colorlet{darkgreen}{green!80!black}

\def\radius{0.96cm}
\def\innerradius{0.85cm}

\def\softness{0.4}
\definecolor{softred}{rgb}{1,\softness,\softness}
\definecolor{softgreen}{rgb}{\softness,1,\softness}
\definecolor{softblue}{rgb}{\softness,\softness,1}

\definecolor{softrg}{rgb}{1,1,\softness}
\definecolor{softrb}{rgb}{1,\softness,1}
\definecolor{softgb}{rgb}{\softness,1,1}

\newcommand{\Bandshaded}[2]{
  \color{shadedshaded}
  \pgfmoveto{\pgfxy(-0.5,0)}
  \pgflineto{\pgfxy(-0.6,0.1)}
  \pgflineto{\pgfxy(-0.4,0.2)}
  \pgflineto{\pgfxy(-0.6,0.3)}
  \pgflineto{\pgfxy(-0.4,0.4)}
  \pgflineto{\pgfxy(-0.5,0.5)}
  \pgflineto{\pgfxy(4,0.5)}
  \pgflineto{\pgfxy(4.1,0.4)}
  \pgflineto{\pgfxy(3.9,0.3)}
  \pgflineto{\pgfxy(4.1,0.2)}
  \pgflineto{\pgfxy(3.9,0.1)}
  \pgflineto{\pgfxy(4,0)}
  \pgfclosepath
  \pgffill

  \color{black}
  \pgfputat{\pgfxy(0,0.7)}{\pgfbox[left,base]{#1}}
  \pgfputat{\pgfxy(0,-0.1)}{\pgfbox[left,top]{#2}}
}

\newcommand{\Band}[2]{
  \color{shaded}
  \pgfmoveto{\pgfxy(-0.5,0)}
  \pgflineto{\pgfxy(-0.6,0.1)}
  \pgflineto{\pgfxy(-0.4,0.2)}
  \pgflineto{\pgfxy(-0.6,0.3)}
  \pgflineto{\pgfxy(-0.4,0.4)}
  \pgflineto{\pgfxy(-0.5,0.5)}
  \pgflineto{\pgfxy(4,0.5)}
  \pgflineto{\pgfxy(4.1,0.4)}
  \pgflineto{\pgfxy(3.9,0.3)}
  \pgflineto{\pgfxy(4.1,0.2)}
  \pgflineto{\pgfxy(3.9,0.1)}
  \pgflineto{\pgfxy(4,0)}
  \pgfclosepath
  \pgffill

  \color{black}
  \pgfputat{\pgfxy(0,0.7)}{\pgfbox[left,base]{#1}}
  \pgfputat{\pgfxy(0,-0.1)}{\pgfbox[left,top]{#2}}
}

\newcommand{\BaenderNormal}
{%
  \pgfsetlinewidth{0.4pt}
  \color{black}
  \pgfputat{\pgfxy(0,5)}{\Band{input tapes}{}}
  \pgfputat{\pgfxy(0.35,4.6)}{\pgfbox[center,base]{$\vdots$}}
  \pgfputat{\pgfxy(0,4)}{\Band{}{}}

  \pgfxyline(0,5)(0,5.5)
  \pgfxyline(1.2,5)(1.2,5.5)
  \pgfputat{\pgfxy(0.25,5.25)}{\pgfbox[left,center]{$w_1$}}

  \pgfxyline(0,4)(0,4.5)
  \pgfxyline(1.8,4)(1.8,4.5)
  \pgfputat{\pgfxy(0.25,4.25)}{\pgfbox[left,center]{$w_n$}}
  \ignorespaces}

\newcommand{\BaenderZweiNormal}
{%
  \pgfsetlinewidth{0.4pt}
  \color{black}
  \pgfputat{\pgfxy(0,5)}{\Band{Zwei Eingabebänder}{}}
  \pgfputat{\pgfxy(0,4.25)}{\Band{}{}}

  \pgfxyline(0,5)(0,5.5)
  \pgfxyline(1.2,5)(1.2,5.5)
  \pgfputat{\pgfxy(0.25,5.25)}{\pgfbox[left,center]{$u$}}

  \pgfxyline(0,4.25)(0,4.75)
  \pgfxyline(1.8,4.25)(1.8,4.75)
  \pgfputat{\pgfxy(0.25,4.5)}{\pgfbox[left,center]{$v$}}
  \ignorespaces}

\newcommand{\BaenderHell}
{%
  \pgfsetlinewidth{0.4pt}
  \color{black}
  \pgfputat{\pgfxy(0,5)}{\Bandshaded{input tapes}{}}
  \color{shaded}
  \pgfputat{\pgfxy(0.35,4.6)}{\pgfbox[center,base]{$\vdots$}}
  \pgfputat{\pgfxy(0,4)}{\Bandshaded{}{}}

  \color{blackshaded}
  \pgfxyline(0,5)(0,5.5)
  \pgfxyline(1.2,5)(1.2,5.5)
  \pgfputat{\pgfxy(0.25,5.25)}{\pgfbox[left,center]{$w_1$}}

  \pgfxyline(0,4)(0,4.5)
  \pgfxyline(1.8,4)(1.8,4.5)
  \pgfputat{\pgfxy(0.25,4.25)}{\pgfbox[left,center]{$w_n$}}
  \ignorespaces}

\newcommand{\BaenderZweiHell}
{%
  \pgfsetlinewidth{0.4pt}
  \color{black}
  \pgfputat{\pgfxy(0,5)}{\Bandshaded{Zwei Eingabebänder}{}}%
  \color{blackshaded}
  \pgfputat{\pgfxy(0,4.25)}{\Bandshaded{}{}}
  \pgfputat{\pgfxy(0.25,4.5)}{\pgfbox[left,center]{$v$}}
  \pgfputat{\pgfxy(0.25,5.25)}{\pgfbox[left,center]{$u$}}%

  \pgfxyline(0,5)(0,5.5)
  \pgfxyline(1.2,5)(1.2,5.5)

  \pgfxyline(0,4.25)(0,4.75)
  \pgfxyline(1.8,4.25)(1.8,4.75)
  \ignorespaces}

\newcommand{\Slot}[1]{%
  \begin{pgftranslate}{\pgfpoint{#1}{0pt}}%
    \pgfsetlinewidth{0.6pt}%
    \color{structure}%
    \pgfmoveto{\pgfxy(-0.1,5.5)}%
    \pgfbezier{\pgfxy(-0.1,5.55)}{\pgfxy(-0.05,5.6)}{\pgfxy(0,5.6)}%
    \pgfbezier{\pgfxy(0.05,5.6)}{\pgfxy(0.1,5.55)}{\pgfxy(0.1,5.5)}%
    \pgflineto{\pgfxy(0.1,4.0)}%
    \pgfbezier{\pgfxy(0.1,3.95)}{\pgfxy(0.05,3.9)}{\pgfxy(0,3.9)}%
    \pgfbezier{\pgfxy(-0.05,3.9)}{\pgfxy(-0.1,3.95)}{\pgfxy(-0.1,4.0)}%
    \pgfclosepath%
    \pgfstroke%
  \end{pgftranslate}\ignorespaces}

\newcommand{\SlotZwei}[1]{%
  \begin{pgftranslate}{\pgfpoint{#1}{0pt}}%
    \pgfsetlinewidth{0.6pt}%
    \color{structure}%
    \pgfmoveto{\pgfxy(-0.1,5.5)}%
    \pgfbezier{\pgfxy(-0.1,5.55)}{\pgfxy(-0.05,5.6)}{\pgfxy(0,5.6)}%
    \pgfbezier{\pgfxy(0.05,5.6)}{\pgfxy(0.1,5.55)}{\pgfxy(0.1,5.5)}%
    \pgflineto{\pgfxy(0.1,4.25)}%
    \pgfbezier{\pgfxy(0.1,4.25)}{\pgfxy(0.05,4.15)}{\pgfxy(0,4.15)}%
    \pgfbezier{\pgfxy(-0.05,4.15)}{\pgfxy(-0.1,4.2)}{\pgfxy(-0.1,4.25)}%
    \pgfclosepath%
    \pgfstroke%
  \end{pgftranslate}\ignorespaces}

\newcommand{\ClipSlot}[1]{%
  \pgfrect[clip]{\pgfrelative{\pgfxy(-0.1,0)}{\pgfpoint{#1}{4cm}}}{\pgfxy(0.2,1.5)}\ignorespaces}

\newcommand{\ClipSlotZwei}[1]{%
  \pgfrect[clip]{\pgfrelative{\pgfxy(-0.1,0)}{\pgfpoint{#1}{4.25cm}}}{\pgfxy(0.2,1.25)}\ignorespaces}


\AtBeginSection[]{\frame{\frametitle{Outline}\tableofcontents[current]}}
\def\back{\!\!\!\!\!} 
\begin{document}

%\frame{\titlepage}

\frame {\vspace{-3mm}
\frametitle{Lecture 16: Hierarchical models and miscellanea}
\begin{alertblock}{}
It is often easier to model a practical situation by thinking of things in a hierarchy.
\end{alertblock}
\vspace{-2mm}
\begin{block}{Example 4.4.1 (binomial-Poisson hierarchy)}
\begin{itemize}
\item
An insect lays many eggs, each surviving with probability $p$.
\item
On the average, how many eggs will survive?
\item
Let $Y$ be the number of eggs and $X$ be the number of survivors; both are random variables.
\item
We can model this situation by first modeling the distribution of $Y$; given $Y$, we then model the distribution of $X|Y$.
\item
We can then obtain the joint distribution of $(X,Y)$ and marginal distributions of $X$ and $Y$.
\item
We can model the number of eggs by a Poisson distribution, i.e., $Y \sim Poisson(\lambda )$, where $\lambda >0$
is the average of eggs.
\item
Given $Y$, we can model the number of survivors as $X|Y \sim binomial(p,Y)$.
\end{itemize}
\end{block}
}
\frame{\vspace{-2mm}
\begin{block}{}
\begin{itemize}
\item
What is the marginal distribution of $X$?

For $x = 0,1,2,...$, \vspace{-2mm}
\beqrs
P(X=x) & = & \sum_{y=x}^\infty P(X=x, Y = y) \quad\quad\quad x \leq y  \\
&=& \sum_{y=x}^\infty P(X=x| Y = y) P(Y=y) \\
& = & \sum_{y=x}^\infty {y \choose x} p^x(1-p)^{y-x} \frac{e^{-\lambda} \lambda^y }{y!} \\
&=& \frac{(\lambda p)^x e^{-\lambda}}{x! } \sum_{y=x}^\infty \frac{[(1-p)\lambda]^{y-x}}{(y-x)!} \\
& = &  \frac{(\lambda p)^x e^{-\lambda}}{x! } \sum_{t=0}^\infty \frac{[(1-p)\lambda]^{t}}{t!} \quad \quad\quad t=y-x \\
&=&  \frac{(\lambda p)^x e^{-\lambda}}{x! } e^{(1-p)\lambda } =  \frac{e^{-p\lambda }(\lambda p)^x }{x! }
\eeqrs
The distribution of $X$ is $Poisson(p\lambda )$!
\end{itemize}
\end{block}}
\frame{
\begin{block}{}
\begin{itemize}
\item
Then, $E(X) = p \lambda$, which can also be obtained using \vspace{-2mm}
\[ E(X) = E[E(X|Y)] = E( pY) = pE(Y) = p\lambda \vspace{-2mm}\]
 without using the marginal distribution of $X$.
\item
If we begin with our model by saying that $X \sim Poisson(\theta )$, then $\theta = p\lambda$ with $Y$ playing no role at all.
Introducing $Y$ in the hierarchy was mainly aid our understanding of the model.
\end{itemize}
\end{block}\vspace{-2mm}
\begin{alertblock}{Example (binomial-binomial hierarchy)}
A very similar hierarchical model can be described as follows.
\begin{itemize}
\item
 A market survey is conducted to study whether a new
product is preferred over the product currently available in the
market (old product).
\item
The survey is conducted by mail.
Questionnaires are sent along with the sample products (both new and
old) to $N$ customers randomly selected from a population.
\item
Each customer is asked to fill out the
questionnaire and return it, with response 1
(new is better than old) or 0 (otherwise).
\end{itemize}
\end{alertblock}}
\frame{
\begin{alertblock}{}
\begin{itemize}
\item
Let $X$ be the number of ones in
the returned questionnaires.

What is the distribution of $X$?
\item
       If every customer returns the questionnaire, then (from
elementary probability) $X \sim binomial( p,N)$  (assuming that the population is large enough so that
customers respond independently), where $p \in (0,1)$ is the overall
rate of customers who prefer the new product.
\item
Some customers, however,
do not return the questionnaires.

Let $Y$ be the number of customers who respond.
\item
If customers respond independently with the same
probability $\pi \in (0,1)$, then $Y \sim binomial( \pi,N)$.
\item
Given $Y=y$ (an integer between 0 and $N$),
$X|Y=y \sim (p,y)$ if $y\geq 1$ and
the point mass at 0 if $y=0$.
\item
For $x = 0,1,...,N$, \vspace{-2mm}
\[ P(X=x) =  \sum_{k=x}^N P(X=x, Y=k)  = \sum_{k=x}^N P(X=x|Y=k) P(Y=k) \]
\end{itemize}
 \end{alertblock}
}
\frame{
\begin{alertblock}{} \vspace{-4mm}
\beqrs
&=& \sum_{k=x}^N {k \choose x}
p^x (1-p)^{k-x}  {N\choose k} \pi^k (1-\pi )^{N-k}\\
 &= &  \! {N\choose x} (\pi p)^x (1-\pi p)^{N-x} \sum_{k=x}^N
\! {N-x \choose k-x} \! \! \left( \frac{\pi -\pi p}{
1-\pi p} \right)^{k-x} \! \! \! \left(\frac{1-\pi}{1-\pi p}\right)^{N-k}\\
 &= &  \! {N \choose x} (\pi p)^x (1-\pi p )^{N-x}
\eeqrs
It turns out that the marginal distribution of
$X$ is the $binomial(\pi p,N)$ distribution.
\end{alertblock}\vspace{-2mm}
\begin{block}{}
\begin{itemize}
\item
Hierarchical models can have more than two stages.
\item
The advantage is that complicated processes may be modeled by a sequence of relatively simple models placed in a hierarchy.
\item
Conditional distributions play a central role.
\item
The random variables in hierarchical models may be all discrete (as in our previous examples), all continuous, or
some discrete and some continuous.
\end{itemize}
\end{block}}
\frame{
\begin{alertblock}{More general joint pdf's and conditional distributions}
So far we have considered only the situation where all random variables are continuous or all are discrete.

What if $X$ is a continuous random variable and $Y$ is a discrete
random variable on ${\cal Y}$?

We can define the joint ``pdf'' to be a function $f(x,y)$ satisfying \vspace{-2mm}
\[ P(X \leq x, Y=y)  = \int_{-\infty}^x f(t,y)dt , \quad \quad x \in {\cal R} , \ y\in {\cal Y}\]
Then the marginal pdf of $X$ and pmf of $Y$ are respectively \vspace{-2mm}
\[ f_X(x)= \sum_{y \in {\cal Y}} f(x,y) \quad {\rm and} \quad
f_Y(y)= \int_{-\infty}^\infty f(x,y)dx \vspace{-2mm} \]
The conditional pdf of $X|Y$ or  pmf of $Y|X$ can be defined as before.

Similarly we can deal with the situation where $X$ is a continuous random vector and $Y$ is a discrete random vector.

If $X$ or $Y$ is neither discrete nor continuous, we can still define
conditional distributions. But it involves higher level mathematics.
\end{alertblock}
}
\frame{
\begin{block}{Example.}
Suppose that $X$ is a continuous random variable and $Y$ is
a discrete random variable with ${\cal Y} = \{0,1\}$, and the joint pdf is\vspace{-2mm}
\[ f(x,y) = \left\{ \br{ll}
\frac{\alpha}{\sqrt{2\pi}} e^{-x^2/2} & \quad y=0, \vspace{2mm} \\
\frac{1-\alpha}{2} e^{-|x|} & \quad y=1, \er \right. \quad x \in {\cal R} \vspace{-2mm}\]
where $0<\alpha<1$. Then\vspace{-2mm}
\[ f_X(x)= f(x,0)+f(x,1) = \frac{\alpha}{\sqrt{2\pi}} e^{-x^2/2}+
\frac{1-\alpha}{2} e^{-|x|}\quad \quad x \in {\cal R} \]
\[f_Y(y) = \int_{-\infty}^\infty f(x,y)dx =\left\{ \br{ll}
\alpha & \quad y=0 \vspace{2mm}\\
1-\alpha & \quad y=1 \er \right.  \]
\[ f(y|x) = \frac{f(x,y)}{f_X(x)} =\left\{ \br{ll}
\frac{\alpha}{\sqrt{2\pi}} e^{-x^2/2}\bigg/
\left(\frac{\alpha}{\sqrt{2\pi}} e^{-x^2/2}+
\frac{1-\alpha}{2} e^{-|x|}\right) & \  y=0 \vspace{2mm} \\
\frac{1-\alpha}{2} e^{-|x|}\bigg/
\left(\frac{\alpha}{\sqrt{2\pi}} e^{-x^2/2}+
\frac{1-\alpha}{2} e^{-|x|} \right) & \  y=1 \er \right. \]
\end{block}

}
\frame{
\begin{block}{}
\[ f(x|y) = \frac{f(x,y)}{f_Y(y)} =\left\{ \br{ll}
\frac{1}{\sqrt{2\pi}} e^{-x^2/2}  & \quad y=0 \vspace{2mm}\\
\frac{1}{2} e^{-|x|} & \quad y=1 \er \right. \quad x \in {\cal R}  \]
\end{block}\vspace{-2mm}
\begin{alertblock}{Mixture distributions}
In the previous example, the pdf $f_X$ is referred to as a mixture distribution (or pdf), since it is a convex combination of two distributions (pdf's).
\end{alertblock}
\vspace{-2mm}
\begin{block}{Example 4.4.5 (three-stage hierarchy)}
Consider a generalization of Example 4.4.1, where instead of one mother insect there are a large number of mothers and one mother is chosen at random from a (possibly continuous)  distribution $G$.
\vspace{2mm}

The following three-stage hierarchy may be more appropriate: \vspace{-2mm}
\beqrs
\mbox{number of survivors $X$ from $Y$ eggs} & & X|Y \sim binomial(p, Y) \\
\mbox{number of eggs $Y$ from a given mother $Z$} &  & Y|Z \sim Poisson(Z) \\
\mbox{a particular mother $Z$} & & Z \sim G
\eeqrs
\end{block}
}
\frame{\vspace{-2mm}
\begin{block}{}
Suppose that $Z \sim exponential (\beta)$. Then\vspace{-2mm}
\[ E(X) = E[E(X|Y)] = pE(Y) = p E[E(Y|Z)] = pE(Z)= p \beta \vspace{-2mm} \]
The three-stage model can be thought of as a two-stage model by combining the last two stages; we just need to obtain the marginal distribution of $Y$.\vspace{-2mm} \beqrs
 P(Y=y) &=& \int_0^\infty f(y|z)f_Z(z)dz = \int_0^\infty \frac{e^{-z} z^y}{y!} \frac{1}{\beta} e^{-z/\beta } dz \\
 & = & \frac{1}{\beta y!} \int_0^\infty z^y e^{-z(1+\beta^{-1})} dz =
 \frac{1}{\beta y!} \Gamma (y+1) \frac{1}{(1+\beta^{-1})^{y+1}} \\
 & = & \frac{1}{\beta } \frac{\beta^{y+1}}{(1+\beta)^{y+1}} =
 \frac{1}{1+\beta } \left( 1- \frac{1}{1+\beta} \right)^y
\eeqrs
which is the geometric distribution with probability $(1+ \beta)^{-1}$, i.e.,
\vspace{-2mm}
\beqrs
\mbox{number of survivors $X$ from $Y$ eggs} & & X|Y \sim binomial(p, Y) \\
\mbox{number of eggs $Y$} &  & Y \sim geometric((1+\beta )^{-1})
\eeqrs
However, the three-stage model is easier to understand.
\end{block}
}
\frame{\vspace{-2mm} 
\begin{alertblock}{Calculation of mean and variance}
Aside from the advantage in understanding models, hierarchical models can often make the calculation of mean and variance easier.
\vspace{1mm}

Let $X$ be a random variable having a pdf that is the noncentral chi- square pdf with noncentrality parameter $\lambda$ and degrees of freedom
$n$: \vspace{-2mm}
\[ f_X(x) = \sum_{k=1}^\infty \frac{x^{n/2+k-1} e^{-x/2}}{\Gamma ( n/2+k) 2^{n/2+k} } \frac{(\lambda/2)^ke^{-\lambda/2}}{k!} \quad \quad x>0  \vspace{-2mm}  \]
Calculating $E(X)$ is directly using this pdf not easy.
\vspace{1mm}

However, the pdf is the marginal pdf of $X$ in the following two-stage model: \vspace{-2mm}
\beqrs
 X|K & \sim &  \mbox{chi square with degrees of freedom $n+2K$} \\
  K & \sim & Poisson (\lambda /2 ) 
  \eeqrs
$~$ \vspace{-8mm} 

Then \vspace{-2mm}
\beqrs
 E(X) \back & = & \back E[E(X|K)] = E(n+2K) = n+ 2E(K) = n+\lambda \\ 
 {\rm Var}(X) \back & = & \back  E[{\rm Var}(X|K)] + {\rm Var}(E(X|K)) = 
E(2n+4K) + {\rm Var}(n+2K) \\
\back & = & \back 2n + 4E(K) + 4{\rm Var}(K) = 2n+4 \lambda 
\eeqrs
\end{alertblock}}
\frame{
\begin{block}{Example 4.4.6.}
Suppose that \vspace{-2mm}
\[ X|P \sim binomial (n,P) , \quad\quad P \sim beta(\alpha , \beta ) \]
How to calculate $E(X)$ and Var$(X)$?
\[ E(X) = E[E(X|P)] = E(nP) = nE(P) = \frac{n\alpha}{\alpha + \beta } \]
Using the variance formula derived previously, \vspace{-2mm}
\beqrs
{\rm Var}(X) &=& {\rm Var}(E(X|P)) + E[ {\rm Var}(X|P)] \\
& = & {\rm Var}(nP) + E[ nP(1-P)] \\
&=& n^2 {\rm Var}(P) +n E(P)-nE(P^2) \\
&=& \frac{n^2 \alpha\beta }{(\alpha +\beta )^2 (\alpha + \beta +1)} +
\frac{n \alpha}{\alpha + \beta } - \frac{n \alpha (\alpha +1)}{(\alpha + \beta )(\alpha + \beta +1)} \vspace{1mm} \\
& = & \frac{n\alpha \beta (\alpha + \beta +n)}{(\alpha + \beta)^2(\alpha + \beta + 1)}
\eeqrs
\end{block}
}
\frame{
	\begin{alertblock}{Theorem 4.7.9 (Covariance inequality)}
		Let $X$ be a random variable and $g$ and $h$ be nondecreasing functions such that $E[g(X)]$, $E[h(X)]$, and $E[g(X)h(X)]$ exist.
		Then \vspace{-2mm}
		\[ {\rm Cov}(g(X),h(X)) \geq 0. \]
	\end{alertblock}\vspace{-2mm}
	\begin{alertblock}{Proof.}
		Let  $Z= h(X)$, $ \mu_z = E[h(X)]$, and $h^{-1}(t) = \inf \{ x: h(x) \geq t \}$.
		\vspace{1mm}
		
		Then $h(x) \geq \mu_z $ iff $x \geq h^{-1}(\mu_z)$, and \vspace{-2mm}
		\beqrs
		\back & & \back {\rm Cov}(g(X),h(X)) \\
		\back & = & \back E[\{ g(X)-E[g(X)]\} (Z-\mu_z)] =E[ g(X) (Z-\mu_z )] \\
		\back &= & \back E[g(X)(Z-\mu_z)I(\{ Z < \mu_z \} ) ]  +E[g(X)(Z-\mu_z )I(\{ Z \geq \mu_z \}) ] \\
		\back & \geq & \back E[g(h^{-1}(\mu_z)) ( Z - \mu_z )I(\{Z < \mu_z \}) ] \\
		\back &  & \back + E[g(h^{-1}(\mu_z)) ( Z - \mu_z )I(\{Z \geq \mu_z \}) ] \\
		\back &=& \back E[g(h^{-1}(\mu_z)) (Z-\mu_z)] =  g(h^{-1}(\mu_z)) E(Z-\mu_z) \\
		\back &=& \back  0
		\eeqrs
	\end{alertblock}}
	
	\frame{\vspace{-2mm}
		\begin{alertblock}{Best prediction}
			Let $X$ be a random variable on  with $E(X^2)<\infty$
			\vspace{1mm}
			
			We want  to
			predict the future value of $X$ by constructing a $g(Y)$, where $Y$ is another random variable currently observed.
			\vspace{1mm}
			
			We now show that
			$E(X|Y)$ is the best predictor of $X$ in the sense that \vspace{-2mm}
			\[
			E[X-E(X|Y)]^2 = \min_{g:  E[g(Y)]^2 < \infty} E[X-g(Y)]^2 . \vspace{-6mm} \]
			\beqrs
			E[X-g(Y)]^2  \back & = & \back E[X-E(X|Y)+E(X|Y)-g(Y)]^2 \\
			\back & = & \back E[X-E(X|Y)]^2 + E[E(X|Y)-g(Y)]^2 \\
			\back & & \back  + \, 2 E\{[X-E(X|Y)][E(X|Y)-g(Y)]\} \\
			\back &  = & \back E[X-E(X|Y)]^2 + E[E(X|Y)-g(Y)]^2 \\
			\back & & \back  + \, 2 E\bigl\{ E\{ [X-E(X|Y)][E(X|Y)-g(Y)] | Y\} \bigr\} \\
			\back & = & \back E[X-E(X|Y)]^2 + E[E(X|Y)-g(Y)]^2 \\
			\back & & \back   + \, 2E\{ [E(X|Y)-g(Y)] E [X-E(X|Y) | Y]\} \\
			\back &  = & \back  E[X-E(X|Y)]^2 + E[E(X|Y)-g(Y)]^2 \\
			\back &    \geq  & \back E[X-E(X|Y)]^2
			\eeqrs
		\end{alertblock}}
		\frame{
			\begin{block}{}
				In some applications, the concept of independence of $X$ and $Y$ is not enough.
				\vspace{1mm}
				
				There are situations in which $X$ and $Y$ are not independent, but if some information regarding another random vector
				$Z$ is given, then $X$ and $Y$ are conditionally independent.
			\end{block}\vspace{-2mm}
			\begin{block}{Definition (conditional Independence)}
				Let  $X$, $Y$, and $Z$ be random vectors.
				$X$ and $Y$ are conditionally independent given $Z$ iff \vspace{-2mm}
				\[ F(x,y|z ) = F(x|z)F(y|z) \quad \quad \mbox{for all $x$, $y$, $z$} \vspace{-2mm}\]
				where $F(x,y|z)$ is the cdf of $(X,Y)|Z=z$, $F(x|z)$ is the cdf of $X|Z=z$, and
				$F(y|z)$ is the cdf of $Y|Z=z$.
			\end{block}
			\vspace{-2mm}
			\begin{alertblock}{Example}
				Let $Z$, $U$, and $V$ be independent random variables,  $X = Z + U$, and $Y = Z+V$.
				
				Then $X$ and $Y$ are not independent because of the common
				term $Z$.
			\end{alertblock}
		}
		\frame{
			\begin{alertblock}{}
				For example, if $E(XY)$ exists, then \vspace{-2mm}
				\beqrs
				{\rm Cov}(X,Y) &=& {\rm Cov}(Z+U,Z+V) \\
				&=& {\rm Cov}(Z,Z) +
				{\rm Cov}(Z,U)+{\rm Cov}(Z,V)+{\rm Cov}(U,V) \\
				&=& {\rm Var}(Z) > 0 \vspace{-2mm}
				\eeqrs
				But conditioned on $Z=z$, $X$ and $Y$ are independent because
				$X=z+U$ and $Y=z+V$ and $U$ and $V$ are independent.
				\vspace{1mm}
				
				A rough proof is the following. \vspace{-2mm}
				\beqrs
				F(x-z , y-z |z ) &=& F(u,v|z) = F(u,v) = F(u)F(v) \\
				&= & F(u|z)F(v|z) = F(x-z|z)F(y-z|z) \vspace{-2mm}
				\eeqrs
				This holds for all $x$, $y$, and $z$, and hence\vspace{-2mm}
				\[ F(x , y |z ) = F(x|z)F(y|z)  \]
				
			\end{alertblock}
		}
		
		
\end{document}


