% \documentclass[serif]{beamer} % Serif for Computer Modern math font.
\documentclass[serif, handout]{beamer} % Handout to ignore pause statements.

\hypersetup{colorlinks,linkcolor=,urlcolor=red}

\usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice!
\setbeamertemplate{navigation symbols}{} % Suppress navigation symbols
% \usetheme{Berlin} % Displays sections on top
\usetheme{Frankfurt}  % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides
%\usetheme{Berkeley}

\usepackage[english]{babel}
\usepackage{amsmath} % for binom
\usepackage{amsfonts} % for \mathbb{R} The set of reals
% \usepackage{graphicx} % To include pdf files!
% \definecolor{links}{HTML}{2A1B81}
% \definecolor{links}{red}
\setbeamertemplate{footline}[frame number] 

\mode<presentation>

\title{Transformations of Jointly Distributed Random Variables\footnote{ This slide show is an open-source document. See last slide for copyright information.}}
\subtitle{STA 256: Fall 2019}
\date{} % To suppress date

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}
\frametitle{Overview}
\tableofcontents
\end{frame}

\begin{frame}
\frametitle{Transformations of Jointly Distributed Random Variables} \pause
%\framesubtitle{} 
Let $Y = g(X_1, \ldots, X_n)$.  What is the probability distribution of~$Y$?  \pause

For example,
\begin{itemize}
    \item $X_1$ is the number of jobs completed by employee 1.
    \item $X_2$ is the number of jobs completed by employee 2.
    \item You know the probability distributions of $X_1$ and $X_2$. \pause
    \item You would like to know the probability distribution of $Y = X_1 + X_2$.
\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Convolutions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Convolutions of discrete random variables} \pause
%\framesubtitle{} 
\begin{itemize}
    \item Let $X$ and $Y$ be discrete random variables. 
    \item The standard case is where they are independent. 
    \item Want probability mass function of $Z = X + Y$.
\end{itemize} \pause
\begin{eqnarray*}
    p_{_Z}(z)  & = & P(Z=z) \\ \pause
            & = & P(X+Y=z) \\ \pause
            & = & \sum_x P(X+Y=z|X=x)P(X=x) \\ \pause
            & = & \sum_x P(x+Y=z|X=x)P(X=x) \\ \pause
            & = & \sum_x P(Y=z-x|X=x)P(X=x) \\ \pause
            & = & \sum_x P(Y=z-x)P(X=x) \mbox{ by independence}\\ \pause
            & = & \sum_x p_{_X}(x) p_{_Y}(z-x)
\end{eqnarray*} 
\end{frame}

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

\begin{frame}
\frametitle{Summarizing}
\framesubtitle{Convolutions of discrete random variables} 
Let $X$ and $Y$ be \emph{independent} discrete random variables, and $Z = X + Y$. 
{\LARGE
\begin{displaymath}
    p_{_Z}(z) = \sum_x p_{_X}(x) p_{_Y}(z-x)
\end{displaymath} 
} % End size
\end{frame}


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

\begin{frame}
\frametitle{Two Important results}
\framesubtitle{Proved using the convolution formula}  \pause
\begin{itemize}
    \item Let $X \sim$ Poisson($\lambda_1$) and $Y \sim$ Poisson($\lambda_2$) be independent. \pause Then $Z=X+Y \sim$ Poisson($\lambda_1+\lambda_2$).  \pause  % Sum using binomial theorem
    \item Let $X \sim$ Binomial($n_1,\theta$) and $Y \sim$ Binomial($n_2,\theta$) be independent. \pause Then $Z=X+Y \sim$ Binomial($n_1+n_2,\theta$) % Sum over a hypergeometric.
\end{itemize}
\end{frame}

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

\begin{frame}
\frametitle{Convolutions of \emph{continuous} random variables} \pause
%\framesubtitle{} 
\begin{itemize}
    \item Let $X$ and $Y$ be continuous random variables.  
    \item The standard case is where they are independent. 
    \item Want probability density function of $Z = X + Y$.
\end{itemize} \pause
\begin{columns}  
\column{0.5\textwidth}
\begin{eqnarray*}
    f_{_Z}(z)  & = & \frac{d}{dz} P(Z \leq z) \\ \pause
            & = & \frac{d}{dz} P(X+Y \leq z) \\
            &&\\ &&\\ &&\\ &&\\ &&\\ 
            \pause
\end{eqnarray*} 
\column{0.5\textwidth}
%\begin{center}
\includegraphics[width=2in]{x+y<z}\vspace{2mm}
%\end{center} 
\end{columns}
\end{frame}

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

\begin{frame}
\frametitle{Continuing \ldots}
%\framesubtitle{} 
\begin{columns}  
\column{0.4\textwidth}
\includegraphics[width=2in]{x+y<z} 
\column{0.7\textwidth}
\begin{eqnarray*}
    f_{_Z}(z)  & = & \frac{d}{dz} P(X+Y \leq z) \\ 
            & = & \frac{d}{dz} \int_{-\infty}^\infty {\color{red}\int_{-\infty}^{z-x} f_{_{X,Y}}(x,y) \, dy } \, dx \\ \pause
\end{eqnarray*}
\hspace{20mm}{\color{red} $t = y+x$  \hspace{2mm} $y=t-x$ \hspace{2mm} $dy=dt$ } \pause
\begin{center}               
\begin{tabular}{c|c} 
$y$      & $t=y+x$\\ \hline 
$z-x$    & $z$ \\
$-\infty$ & $-\infty$
\end{tabular} \pause \vspace{2mm}

{\color{red} $\int_{-\infty}^z f_{_{X,Y}}(x,t-x) \, dt$ }
\end{center}               
\end{columns}
\end{frame}

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

\begin{frame}
\frametitle{Still continuing, have}
%\framesubtitle{} 
\begin{eqnarray*}
    f_{_Z}(z)  & = & \frac{d}{dz} \int_{-\infty}^\infty {\color{red} \int_{-\infty}^z} 
                  f_{_{X,Y}}(x,{\color{red}t}-x) \, {\color{red}dt}  \, dx \\ \pause
            & = & \frac{d}{dz} {\color{red} \int_{-\infty}^z} \int_{-\infty}^\infty 
                  f_{_{X,Y}}(x,{\color{red}t}-x)  \, dx \, {\color{red}dt} \\ \pause
            & = &  \int_{-\infty}^\infty   f_{_{X,Y}}(x,{\color{red}z}-x)  \, dx  \\ \pause
            & = & \int_{-\infty}^\infty  f_{_X}(x)f_{_Y}(z-x)  \, dx 
            \mbox{ ~if $X$ and $Y$ are independent.}
            \end{eqnarray*}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Compare}
%\framesubtitle{For continuous (and independent) random variables, $Z=X+Y$} 
For continuous random variables:
{\LARGE
\begin{displaymath}
    f_{_Z}(z) = \int_{-\infty}^\infty  f_{_X}(x)f_{_Y}(z-x)  \, dx
\end{displaymath}
} % End size
For discrete random variables: 
{\LARGE
\begin{displaymath}
    p_{_Z}(z) = \sum_x p_{_X}(x) p_{_Y}(z-x)
\end{displaymath}  \pause
} % End size

\vspace{4mm}
Of course you need to pay attention to the limits of integration or summation\pause, because $f_{_X}(x)f_{_Y}(z-x)$ may be zero for some $x$.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Two Important results for continuous random variables}
\framesubtitle{Proved using the convolution formula}  \pause
\begin{itemize}
    \item Let $X$ and $Y$ be independent exponential random variables with parameter $\lambda >0$. \pause Then \\ $Z=X+Y \sim$ Gamma($\alpha=2,\lambda$).  \pause  % Integrate cdf of exponential.
    \item Let $X \sim$ Normal($\mu_1,\sigma^2_1$) and $Y \sim$ Normal($\mu_2,\sigma^2_2$) be independent. \pause Then \\
    $Z=X+Y \sim$ Normal$\left(\mu_1+\mu_2,\sigma^2_1+\sigma^2_2\right)$. % Complete the square, ugh!
\end{itemize}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Jacobians}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{The Jacobian Method} \pause
%\framesubtitle{} 
\begin{itemize}
    \item $X_1$ and $X_2$ are continuous random variables. \pause
    \item $Y_1 = g_1(X_1,X_2)$ and $Y_2 = g_2(X_1,X_2)$.  \pause
    \item Want $f_{_{Y_1,Y_2}}(y_1,y_2)$ \pause
\end{itemize}
Solve for $x_1$ and $x_2$, obtaining $x_1(y_1,y_2)$ and $x_2(y_1,y_2)$\pause. Then 
\begin{displaymath}
    f_{_{Y_1,Y_2}}(y_1,y_2) = f_{_{X_1,X_2}}(\, x_1(y_1,y_2),x_2(y_1,y_2) \,) \pause \cdot abs
    \renewcommand{\arraystretch}{1.5}
    \left| \begin{array}{cc}
    \frac{\partial x_1}{\partial y_1} & \frac{\partial x_1}{\partial y_2} \\
    \frac{\partial x_2}{\partial y_1} & \frac{\partial x_2}{\partial y_2}
    \end{array}\right|
    \renewcommand{\arraystretch}{1.0}
\end{displaymath}  \pause
The determinant 
$\left| \begin{array}{cc}
    a & b \\
    c & d
\end{array}\right| = ad-bc$.
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{More about the Jacobian method}
\framesubtitle{$Y_1 = g_1(X_1,X_2)$ and $Y_2 = g_2(X_1,X_2)$}  \pause
\begin{itemize}
    \item It follows directly from a change of variables formula in multi-variable integration. The proof is omitted. \pause
    \item It must be possible to solve $y_1 = g_1(x_1,x_2)$ and $y_2 = g_2(x_1,x_2)$ for $x_1$ and $x_2$. \pause
    \item That is, the function $g: \mathbb{R}^2 \rightarrow \mathbb{R}^2$ must be one to one (injective). \pause
    \item Frequently you are only interested in $Y_1$, and $Y_2 = g_2(X_1,X_2)$ is chosen to make reverse solution easy. \pause
    \item The partial derivatives must all be continuous, except possibly on a set of probability zero (they almost always are). \pause
    \item It extends naturally to higher dimension.
\end{itemize}
\end{frame}

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

\begin{frame}
\frametitle{Change from rectangular to polar co-ordinates}
\framesubtitle{By the Jacobian method} \pause
A point on the plane may be represented as $(x,y)$, or \pause

\begin{center}
\includegraphics[width=2.5in]{circle}
\end{center} 

An angle $\theta$ and a radius $r$. 

\end{frame}

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

\begin{frame}
\frametitle{Change of variables}
\framesubtitle{From rectangular to polar coordinates} 
\begin{columns}  
\column{0.6\textwidth}
\begin{center}
\includegraphics[width=2.5in]{circle}
\end{center} \pause

\column{0.4\textwidth}
  \begin{itemize}
    \item[] $x = r \cos(\theta)$ 
    \item[] $y = r \sin(\theta)$ \pause
    \item[] $x^2 + y^2 = r^2$ \pause
  \end{itemize}

  \begin{itemize}
    \item As $x$ and $y$ range from $-\infty$ to $\infty$, \pause
    \item $r$ goes from 0 to $\infty$ 
    \item And $\theta$ goes from $0$ to $2\pi$.
  \end{itemize}
\end{columns}
\end{frame}


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


\begin{frame}
\frametitle{Integral $\int_0^\infty \int_0^\infty f_{x,y}(x,y) \, dx \, dy$} \pause
%\framesubtitle{} 
Change of variables: \pause
\begin{columns}  
\column{0.5\textwidth}
  \begin{itemize}
    \item[] $x = r \cos(\theta)$
    \item[] $y = r \sin(\theta)$ 
  \end{itemize}
\column{0.5\textwidth}
\begin{center}
\includegraphics[width=1.75in]{circle}
\end{center} 
\end{columns}\pause
\begin{eqnarray*}
    & & \int_0^\infty \int_0^\infty f_{x,y}(x,y) \, dx \, dy \\ 
    &=& \pause \int_0^{\pi/2} \int_0^\infty f_{x,y}(r\cos\theta,r\sin\theta) \, abs
     \renewcommand{\arraystretch}{1.5}
    \left| \begin{array}{cc}
    \frac{\partial x}{\partial r} & \frac{\partial x}{\partial \theta} \\
    \frac{\partial y}{\partial r} & \frac{\partial y}{\partial \theta}
    \end{array}\right|
    \renewcommand{\arraystretch}{1.0}
    \, dr \, d\theta 
\end{eqnarray*} 
\end{frame}



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


\begin{frame}
\frametitle{Evaluate the determinant}
\framesubtitle{(with $x = r\cos(\theta)$ and $y = r\sin(\theta)$)}  
\begin{eqnarray*}
    \renewcommand{\arraystretch}{1.5}
    \left| \begin{array}{cc}
    \frac{\partial x}{\partial r} & \frac{\partial x}{\partial \theta} \\
    \frac{\partial y}{\partial r} & \frac{\partial y}{\partial \theta}
    \end{array}\right|
    \renewcommand{\arraystretch}{1.0} \pause
    & = & 
    \renewcommand{\arraystretch}{1.5}
    \left| \begin{array}{cc}
    \frac{\partial \, r\cos(\theta)}{\partial r} & \frac{\partial \, r\cos(\theta)}{\partial \theta} \\
    \frac{\partial \, r\sin(\theta)}{\partial r} & \frac{\partial \, r\sin(\theta)}{\partial \theta}
    \end{array}\right|
    \renewcommand{\arraystretch}{1.0} \pause
    \\ 
    && \\
    & = & 
    \left| \begin{array}{cc}
    \cos(\theta) & -r\sin(\theta) \\
    \sin(\theta) & r\cos(\theta)
    \end{array}\right| \pause
    \\
    && \\
    & = & r \cos^2\theta - - r\sin^2\theta \pause  \\
    & = & r (\sin^2\theta + \cos^2\theta)  \pause  \\
    & = & r 
\end{eqnarray*} 
\end{frame}

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


\begin{frame}
\frametitle{So the integral is} \pause
%\framesubtitle{} 
{\large
\begin{displaymath}
    \int_0^\infty \int_0^\infty f_{x,y}(x,y) \, dx \, dy = 
    \int_0^{\pi/2} \int_0^\infty f_{x,y}(r\cos\theta,r\sin\theta) \, r \, dr \, d\theta 
\end{displaymath} \pause
} % End size
\begin{itemize}
    \item The standard formula for change from rectangular to polar co-ordinates is $dx \, dy = r \, dr \, d\theta$. \pause
    \item It comes from a Jacobian. \pause
    \item Other limits of integration are possible. \pause
    \item $f(x,y)$ does not have to be a density.
\end{itemize}

\end{frame}

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

\begin{frame}
\frametitle{Copyright Information}

This slide show was prepared by  \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner},
Department of Statistical Sciences, University of Toronto. It is licensed under a 
\href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US}
     {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website:

\vspace{5mm}
\href{http://www.utstat.toronto.edu/~brunner/oldclass/256f19} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/256f19}}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}



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

\begin{frame}
\frametitle{} \pause
%\framesubtitle{} 
\begin{itemize}
    \item  \pause
    \item  \pause
    \item 
\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
\includegraphics[width=2in]{BivariateNormal}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

