% vim: tw=50
% 15/02/2022 11AM

\setcounter{customexample}{-1}
\begin{example}
    $\mathrm{Var}(X + Y) = \mathrm{Var}(X) +
    \mathrm{Var}(Y)$ for independent $X, Y$.
    Consider $Y = -X$. Then
    \[ \mathrm{Var}(Y) = \mathrm{Var}(-X) = (-1)^2
    \mathrm{Var}(x) = \mathrm{Var}(X) \]
    \[ 0 = \mathrm{Var}(0) = \mathrm{Var}(X + Y)
    \neq \mathrm{Var}(X) + \mathrm{Var}(Y) = 2
    \mathrm{Var}(X) \]
\end{example}

\begin{example}
    $(\sigma(1), \dots, \sigma(n))$ uniform on
    $\sum_n$. $A_i = \{\sigma(i) = i\}$. \\
    \[ N = \mathbbm{1}_{A_1} + \cdots +
    \mathbbm{1}_{A_n} = \text{number of fixed
    points} \]
    Already seen: $\EE[N] = n \times \frac{1}{n} =
    1$. Goal: $\mathrm{Var}(N)$.
    \begin{note*}
        $A_i$ and $A_j$ are \emph{not}
        independent.
    \end{note*}
    \begin{align*}
        \mathrm{Var}(\mathbbm{1}_{A_i})
        &= \frac{1}{n} \left( 1 - \frac{1}{n}
        \right) \\
        \mathrm{Cov}(\mathbbm{1}_{A_i},
        \mathbbm{1}_{A_j})
        &= \EE[\mathbbm{1}_{A_i}
        \mathbbm{1}_{A_j}] -
        \EE[\mathbbm{1}_{A_i}]\EE[\mathbbm{1}_{A_j}]
        \\
        &= \EE[\mathbbm{1}_{A_i \cap A_j}] -
        \EE[\mathbbm{1}_{A_i}]\EE[\mathbbm{1}_{A_j}]
        \\
        &= \PP(A_i \cap A_j) - \PP(A_i)\PP(A_j) \\
        &= \frac{1}{n(n - 1)} - \frac{1}{n} \times
        \frac{1}{n} \\
        &= \frac{1}{n^2(n - 1)} \\
        &> 0 \\
        \implies \mathrm{Var}(N)
        &= \sum_{i = 1}^n
        \mathrm{Var}(\mathbbm{1}_{A_i}) + \sum_{i
        \neq j} \mathrm{Cov}(\mathbbm{1}_{A_i},
        \mathbbm{1}_{A_j}) \\
        &= n \times \frac{1}{n} \left( 1 -
        \frac{1}{n} \right) + n(n - 1) \times
        \frac{1}{n^2(n - 1)} \\
        &= 1 - \frac{1}{n} + \frac{1}{n} \\
        &= 1
    \end{align*}
\end{example}

\noindent
Compare with $\mathrm{Bin} \left( n, \frac{1}{n}
\right)$:
\[ \EE = 1, \qquad \mathrm{Var} = n \times
\frac{1}{n} \left( 1 - \frac{1}{n} \right) = 1 -
\frac{1}{n} \]

\subsubsection*{Chebyshev's Inequality}

\begin{theorem*}[Chebyshev's Inequality]
    $X$ a random variable, $\EE[X] = \mu$,
    $\mathrm{Var}(X) = \sigma^2 < \infty$. Then:
    \[ \PP(|X - \mu| \ge \lambda) \le
    \frac{\mathrm{Var}(X)}{\lambda^2} \]
\end{theorem*}

\noindent
Comment: Remember the proof, not the statement!

\myskip
\begin{proof}
    Idea: Apply Markov's Inequality to
    \[ (X - \mu)^2 \]
    (which is non-negative as required). Then:
    \begin{align*}
        \PP(|X - \mu| \ge \lambda)
        &= \PP((X - \mu)^2 \ge \lambda^2) \\
        &\le \frac{\EE[(X - \mu)^2}{\lambda^2} \\
        &= \frac{\mathrm{Var}(X)}{\lambda^2}
    \end{align*}
\end{proof}

\subsubsection*{Comments}

\begin{itemize}
    \item Chebyshev's Inequality gives better
        bounds than Markov's inequality.
    \item Note can apply to all Random Variables,
        not just $\ge 0$.
    \item However, $\mathrm{Var}(X) < \infty$ is a
        stronger condition than $\EE[X] < \infty$.
\end{itemize}

\begin{definition*}
    \begin{itemize}
        \item Quantity $\sqrt{\mathrm{Var}(X)} =
            \sigma$ is called the \emph{standard
            deviation} of $X$.
        \item Same ``units'' as $X$. (Scales
            linearly)
        \item (Not many nice properties).
        \item Rewriting Chebyshev; use $\lambda =
            k\sqrt{\sigma^2}$, then
            \[ \PP(|X - \mu| \ge \sigma) \le
            \frac{1}{k^2} \]
        \item Nice uniform statement
    \end{itemize}
\end{definition*}

\subsubsection*{Conditional Expectation}

Setting: $(\Omega, \mathcal{F}, \PP)$. \\
Recall: $B \in \mathcal{F}$ with $\PP(B) > 0$ we
defined
\[ \PP(A \mid B) = \frac{\PP(A \cap B)}{\PP(B)} \]

\begin{definition*}
    $B \in \mathcal{F}$ with $\PP(B) > 0$, $X$ a
    random variable. The conditional expectation
    is
    \[ \EE[X \mid B] = \frac{\EE[X
    \mathbbm{1}_B]}{\PP(B)} \]
\end{definition*}

\begin{example*}
    $X$ dice, uniform on $\{1, \dots, 6\}$.
    \begin{align*}
        \EE[X \mid X \text{ prime}]
        &= \frac{\frac{1}{6}[0 + 2 + 3 + 0 + 5 +
        0]}{\frac{1}{2}} \\
        &= \frac{1}{3} (2 + 3 + 5 \\
        &= \frac{10}{3}
    \end{align*}
\end{example*}

\noindent
\ul{Alternative Characterisation}:
\[ \EE[X \mid B] = \sum_{x \in \mathrm{Im}\,\,X}
\PP(X = x \mid B) \]

\begin{proof}
    \begin{align*}
        RHS
        &= \sum \frac{x\PP(\{X = x\} \cap
        B)}{\PP(B)} \\
        &= \sum_{\substack{x \neq 0 \\x \in
        \mathrm{Im}\,\,X}} \frac{x\PP(X
        \mathbbm{1}_B = x}{\PP(B)}
    \end{align*}
    and note
    \[ \EE[X \mathbbm{1}_B] = \sum_{\substack{x
    \neq 0 \\ x \in \mathrm{Im}\,\,X}} x\PP(X
    \mathbbm{1}_B = x) \]
\end{proof}

\subsubsection*{Law of Total Expectation}

$(B_1, B_2, \dots)$ a finite or countably infinite
partition of $\Omega$ with $B_n \in \mathcal{F}$
for all $n$ such that $\PP(B_n) > 0$. $X$ is a
random variable. Then:
\[ \EE[X] = \sum_n \EE[X \mid B_n] \PP(B_n) \]
For example, $X = \mathbbm{1}_A$ recovers the law
of total probability.

\begin{proof}
    \begin{align*}
        RHS
        &= \sum_n \EE[X \mathbbm{1}_{B_n}] \\
        &= \EE[X \cdot (\mathbbm{1}_{B_1} + \cdots
        + \mathbbm{1}_{B_n})] \\
        &= \EE[X \cdot 1] \\
        &= \EE[X]
    \end{align*}
\end{proof}

\myskip
Application: Two stage randomness where $(B_n)$
describes what happens in stage 1. \\
\ul{Application 1}: ``random sums'' (random number
of terms). \\
$(X_n)_{n \ge 1}$ independent and identically
distributed random variables. $N \in \{0, 1, 2,
\dots\}$ random index independent of $(X_n)$.
\[ S_n = X_1 + \cdots + X_n \]
with $\EE[X_n] = \mu$ so $\EE[S_n] = n\mu$. Then
\begin{align*}
    \EE[S_N]
    &= \sum_{n \ge 0} \EE[S_N \mid N = n] \PP(N =
    n) \\
    &= \sum \EE[S_n] \PP(N = n) \\
    &= \sum_{n \ge 0} n \mu \PP(N = n) \\
    &= \mu \EE[N]
\end{align*}
