% vim: tw=50
% 01/03/2022 11AM

\noindent
\ul{Variance}:
\[ \mathrm{Var}(X) = \EE[(X - \EE[X])^2] =
\EE[X^2] - (\EE[X])^2 \]
\[ \mathrm{Var}(aX + b) = a^2 \mathrm{Var}(X) \]

\subsubsection*{Examples}

Uniform: $U \sim U[a, b]$.
\[ \EE[U] = \int_a^b x \frac{\dd x}{b - a} =
\frac{\half b^2 - \half a^2}{b - a} = \frac{a +
b}{2} \]
\[ \EE[U^2] = \int_a^b x^2 \frac{\dd x}{b - a} =
\frac{\frac{1}{3} b^3 - \frac{1}{3} a^3}{b - a} =
\frac{1}{3} (a^2 + ab + b^2) \]
\begin{align*}
    \mathrm{Var}(U)
    &= \frac{1}{3} (a^2 + ab + b^2) - \left(
    \frac{a + b}{2} \right)^2 \\
    &= \frac{(b - a)^2}{12}
\end{align*}

\myskip
Exponential: $X \sim \mathrm{Exp}(\lambda)$.
\begin{align*}
    \EE[X]
    &= \int_0^\infty \lambda x e^{-\lambda x}
    \dd x \\
    &= [-x e^{-\lambda x}]_0^\infty +
    \int_0^\infty e^{-\lambda x} \dd x \\
    &= \frac{1}{\lambda} \\
    E[X^2]
    &= \int_0^\infty \lambda x^2 e^{-\lambda x}
    \dd x \\
    &= [-x^2 e^{-\lambda x}]_0^\infty +
    2\int_0^\infty x e^{-\lambda x} \dd x \\
    &= 0 + \frac{2}{\lambda^2} \\
    \mathrm{Var}(X)
    &= \frac{2}{\lambda^2} - \frac{1}{\lambda^2}
    \\
    = \frac{1}{\lambda^2}
\end{align*}
\ul{Goal}: $U \sim \mathrm{Unif}[a, b]$,
$\tilde{U} \sim \mathrm{Unif}[0, 1]$. Write $U =
(b - a) \tilde{U} + a$, and carry all calculations
over.

\subsubsection*{Transformations of Continuous Random Variables}

\ul{Goal}: View $g(X)$ as a continuous random
variable with its own density.

\begin{theorem*}
    \begin{itemize}
        \item $X$ continuous random variable with
            density $f$
        \item $g : \RR \to \RR$ continuous such
            that
            \begin{enumerate}[(i)]
                \item $g$ is either strictly
                    increasing or decreasing
                \item $g^{-1}$ is differentiable
            \end{enumerate}
    \end{itemize}
    Then $g(X)$ is a continuous random variable
    with density
    \[ \hat{f}(x) = f(g^{-1}(x)) \ub{\left|
    \dfrac{}{x} g^{-1}(x) \right|}_{(\dag)} \tag{$*$} \]
    ($\dag$ is $\ge 0$ if $g$ is strictly
    increasing).
\end{theorem*}

\subsubsection*{Comments}

\begin{itemize}
    \item Density is? Something to integrate over
        to get a probability
    \item ($*$) \emph{is} integration by
        substitution
    \item Proof use CDFs (which \emph{are}
        probabilities).
\end{itemize}

\begin{proof}
    \begin{align*}
        F_{g(X)}(x)
        &= \PP(g(X) \le x) \\
        &= \PP(X \le g^{-1}(x)) \\
        &= F_X(g^{-1}(X))
    \end{align*}
    Differentiate:
    \begin{align*}
        F_{g(X)}'(x)
        &= F_X'(g^{-1}(x)) \dfrac{}{x} g^{-1}(x)
        \\
        &= f(g^{-1}(x)) \dfrac{}{x} g^{-1}(x)
    \end{align*}
    ($g$ strictly decreasing is similar $\to$
    exercise (revision!))
\end{proof}

\myskip
\ul{Sanity check}: We've got two expressions for
$\EE[g(x)]$ (assume: $\mathrm{Im}(X) =
\mathrm{Im}(g(X)) = (-\infty, \infty)$)
new expression:
\begin{align*}
    \EE[g(X)]
    &= \int_{-\infty}^\infty x \hat{f}(x) \dd x \\
    &= \int_{-\infty}^\infty x f(g^{-1}(x))
    \dfrac{}{x} g^{-1}(x) \dd x
\end{align*}
Substitute: $g^{-1}(x) = u$. So $\dd u = \dd x
\dfrac{}{x} g^{-1}(x)$.
\[ = \int_{u = -\infty}^\infty g(u) f(u) \dd u \]

\begin{example*}
    \begin{itemize}
        \item $X \sim \mathrm{Exp}(\lambda)$, $Y =
            cX$.
            \[ \PP(Y \le x) = \PP \left( X \le
            \frac{X}{c} \right) = 1 - e^{-\lambda
            \frac{x}{c}} = 1 - e^{-
            \frac{\lambda}{c} x} = \text{CDF of
            $\mathrm{Exp} \left( \frac{\lambda}{c}
            \right)$} \]
        \item $\hat{f}(x) = \frac{1}{c} f \left(
            \frac{x}{c} \right) = \frac{1}{c}
            \lambda e^{-\lambda \frac{x}{c}} =
            \frac{\lambda}{c} e^{-
            \frac{\lambda}{c} x}$.
    \end{itemize}
\end{example*}

\begin{example*}
    The \emph{Normal} Distribution (also
    \emph{Gaussian}). Range: $(-\infty, \infty)$.
    Two parameters: $\mu \in (-\infty, \infty),
    \sigma^2 \in (0, \infty)$. (the mean and
    variance).
    \[ X \sim \mathrm{N}(\mu, \sigma^2) \]
    \[ f_X(x) = \frac{1}{\sqrt{2\pi \sigma^2}}
    \exp \left( -\frac{(x - \mu)^2}{2\sigma^2} \right) \]
    Special case: ``Standard normal'': $Z \sim
    \mathrm{N}(0, 1)$
    \[ f_Z(x) = \frac{1}{\sqrt{2\pi}}
    e^{-\frac{x^2}{2}} =: \varphi(x) \]
\end{example*}

\subsubsection*{Comments}

\begin{itemize}
    \item $\frac{1}{\sqrt{2\pi}}$ is a
        ``\emph{normalising constant}''. (Recall
        we need $\int f \dd x = 1$).
    \item $e^{-\frac{x^2}{2}} =$ very rapid decay
        as $x \to \pm \infty$.
    \item $\mathrm{N}(\mu, \sigma^2)$ used for
        modelling non-negative quantity. (because
        if $\mu$ is large $\PP(\mathrm{N}(\mu,
        \sigma^2) < 0)$ is \emph{very} small).
\end{itemize}

\subsubsection*{Checklist}

($Z$, standard normal)
\begin{enumerate}[(i)]
    \item $f_Z$ is a density.
        \begin{proof}
            \[ I = \int_{-\infty}^\infty
            e^{-\frac{x^2}{2}} \dd x \]
            Clever idea: use $I^2$ instead
            \[ I^2 = \int_{-\infty}^\infty
            \int_{-\infty}^\infty
            e^{-\frac{u^2}{2}} e^{-\frac{v^2}{2}}
            \dd u \dd v = \iint e^{-\frac{u^2 +
            v^2}{2}} \dd u \dd v \]
            Polar coordinates: $u = r\cos\theta$,
            $v = r\sin\theta$:
            \[ = \int_{r = 0}^\infty \int_{\theta
            = 0}^{2\pi} re^{-\frac{r^2}{2}} \dd r
            \dd \theta = 2\pi \int_{r = 0}^\infty
            re^{-\frac{r^2}{2}} \dd r = 2\pi \]
        \end{proof}
    \item $\EE[Z] = 0$ by symmetry.
    \item $\mathrm{Var}(Z) = 1$.
        \begin{proof}
            Sufficient to prove $\EE[Z^2] = 1$.
            \begin{align*}
                \EE[Z^2]
                &= \frac{1}{\sqrt{2\pi}}
                \int_{-\infty}^\infty x^2 e^{-
                \frac{x^2}{2}} \dd x \\
                &= \frac{1}{\sqrt{2\pi}}
                \int_{-\infty}^\infty x \cdot x
                e^{-\frac{x^2}{2}} \dd x \\
                &= \left[ -x \cdot
                \frac{e^{-\frac{x^2}{2}}}{\sqrt{2\pi}}
                \right]_{-\infty}^\infty +
                \frac{1}{\sqrt{2\pi}}
                \int_{-\infty}^\infty
                e^{-\frac{x^2}{2}} \dd x \\
                &= 1
            \end{align*}
        \end{proof}
\end{enumerate}
