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

\begin{corollary*}
    $X \ge Y$ (meaning $X(\omega) \ge Y(\omega)$
    for all $\omega \in \RR$) then $\EE[X] \ge \EE[Y]$.
\end{corollary*}

\begin{proof}
    $X = (X - Y) + Y$ hence
    \[ \EE[X] = \EE[X - Y] + \EE[Y] \]
    but $X - Y \ge 0$ hence $\EE[X - Y] \ge 0$.
\end{proof}

\noindent
\ul{Key Application}: Counting problems. \\
$(\sigma(1), \dots, \sigma(n))$ uniform on
$\sigma_n$.
\[ Z = |\{i : \sigma(i) = i\}| = \text{number of
fixed points} \]
Let $A_i = \{\sigma(i) = i\}$. (Recall $A_i$s are
\emph{not} independent) \\
\textbf{Key step}:
\[ Z = \mathbbm{1}_{A_1} + \cdots +
\mathbbm{1}_{A_n} \]
so
\begin{align*}
    \EE[Z]
    &= \EE[\mathbbm{1}_{A_1} + \cdots +
    \mathbbm{1}_{A_n}] \\
    &= \EE[\mathbbm{1}_{A_1}] + \cdots +
    \EE[\mathbbm{1}_{A_n}] \\
    &= \PP(A_1) + \cdots \PP(A_n) \\
    &= \frac{1}{n} \times n \\
    &= 1
\end{align*}

\begin{note*}
    Same answer as $\mathrm{Bin} \left( n,
    \frac{1}{n} \right)$.
\end{note*}

\noindent
\ul{Application}: $X$ takes values in $\{0, 1, 2,
\dots\}$. \\
\textbf{Fact}: $\EE[X] = \sum_{k \ge 1} \PP(X \ge
k)$.
\begin{proof}[1]
    Write
    \[ X = \sum_{k \ge 1} \mathbbm{1}_{(X \ge k)} \]
    Then
    \begin{align*}
        \EE[X]
        &= \EE \left[ \sum \mathbbm{1}_{(X \ge k)}
        \right] \\
        &= \sum \EE[\mathbbm{1}_{(X \ge k)}] \\
        &= \sum \PP(X \ge k)
    \end{align*}
\end{proof}

\myskip
\ul{Sanity Check}: for example if $X = 7$ then
\[ \mathbbm{1}_{(X \ge 1)} = \cdots =
\mathbbm{1}_{(X \ge 7)} = 1 \]
\[ \mathbbm{1}_{(X \ge 8)} = \mathbbm{1}_{(X \ge
9)} = \cdots = 0 \]

\subsubsection*{Markov's Inequality}

$X \ge 0$ a random variable. Then $\forall\,\, a
> 0$:
\[ \PP(X \ge a) \le \frac{\EE[X]}{a} \]
\myskip
\ul{Comment}: \\
Is $a = \frac{\EE[X]}{2}$ useful?
Definitely not. \\
Is $a$ is large useful? Maybe.

\begin{proof}
    Observe: $X \ge a \mathbbm{1}_{(X \ge a)}$.
    Then
    \[ \EE[X] \ge a \EE[\mathbbm{1}_{X \ge a}] =
    a \PP(X \ge a) \]
    now just rearrange.
\end{proof}

\myskip
Note that $\mathbbm{1}_{(X \ge a)}$ means
$X(\omega) \ge a \mathbbm{1}_{(X \ge a)}(\omega)$.
\\
Check: if $X \in [0, a)$ then RHS $= 0$, if $X \in
[a, \infty)$ then RHS $= a$.

\begin{note*}
    Also true for continuous random variables
    (later).
\end{note*}

\subsubsection*{Studying $\EE[f(X)]$}

Let $f : \RR \to \RR$ be a function. Then $f(X)$
is also a \emph{random variable}.

\begin{claim*}
    $\EE[f(X)] = \sum_{x \in \mathrm{Im}(X)} f(x)
    \PP(X = x)$.
\end{claim*}

\begin{proof}
    Let
    \[ A = \mathrm{Im}(f(X)) = \{y : y = f(x), x
    \in \mathrm{Im}(X)\} = \{f(x) : x \in
    \mathrm{Im}(X)\} \]
    Start with RHS:
    \begin{align*}
        \sum_{x \in \mathrm{Im}(X)} f(x) \PP(X =
        x)
        &= \sum_{y \in A} \sum_{\substack{x \in
        \mathrm{Im}(X) \\f(x) = y}} f(x) \PP(X =
        x) \\
        \sum_{y \in A} y \sum_{\substack{x \in
        \mathrm{Im}(X) \\f(x) = y}} \PP(X = x) \\
        &= \sum_{y \in A} y \PP(f(X) = y) \\
        &= \EE[f(X)]
    \end{align*}
\end{proof}

\subsubsection*{Motivation}

\[ U_n \sim \mathrm{Uniform}(\{-n, -n + 1, \dots,
n\}) \]
\[ V_n \sim \mathrm{Univorm}(\{-n, +n\}) \]
\[ Z_n = 0 \]
\[ S_n = \text{random walk for $n$ steps} \sim n -
2 \mathrm{Bin} \left( n, \frac{1}{2} \right) \]
All of these have $\EE = 0$.

\subsubsection*{Variance}

``Measure how concentrated a random variable is
around its mean''.

\begin{definition*}
    The \emph{variance} of $X$ is:
    \[ \mathrm{Var}(X) = \EE [(X - \EE[X])^2] \]
\end{definition*}

\noindent
Property:
\[ \mathrm{Var}(X) \ge 0 \]
with equality $\iff \PP(X = \EE[X]) = 1$.

\myskip
\ul{Alternative Characterisation}:
\[ \mathrm{Var}(X) = \EE[X^2] - (\EE[X])^2 \]

\begin{proof}
    Write $\mu = \EE[X]$. Then
    \begin{align*}
        \mathrm{Var}(X)
        &= \EE[(X - \mu)^2] \\
        &= \EE[X^2 - 2\mu X + \mu^2] \\
        &= \EE[X^2] - 2\mu \ub{\EE[X]}_\mu + \mu^2 \\
        &= \EE[X^2] - \mu^2
    \end{align*}
\end{proof}

\subsubsection*{Properties}

If $\lambda, c \in \RR$:
\begin{itemize}
    \item $\mathrm{Var}(\lambda X) = \lambda^2
        \mathrm{Var}(X)$
    \item $\mathrm{Var}(X + c) = \mathrm{Var}(X)$.
\end{itemize}

\begin{proof}
    $\EE[X + c] = \mu + c$
    \begin{align*}
        \mathrm{Var}(X + c)
        &= \EE[(X + c - (\mu + c))^2] \\
        &= \EE[(X - \mu)^2] \\
        &= \mathrm{Var}(X)
    \end{align*}
\end{proof}
