%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Lecture 9: Discrete Random Variables }

{\footnotesize Copyright, Michael Monagan and Jamie Mulholland, 2020.}

\vspace{1cm}

Grimaldi 3.7 (we will not cover variance)

\vspace{1cm}
\vspace{4cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{definition} [ Random Variable ]
Let $S$ be a sample space. A \textbf{random variable} $X$ on $S$ is a function
$X: S \rightarrow \mathbb{R}$
that associates a numerical value to each possible outcome. \\
The \textbf{range} $r(X)$ of $X$ is the set of all values it can take.
\end{definition}

Example 1.  If $S$ is the set of all binary sequences of size $n=4$. \\
            The function that counts the number of $1$'s is a random variable.

\vspace{1cm}

Example 2.  If $S$ is the set of all rolls of two dice. \\
            The function that adds the values of the dice is a random variable.

\vspace{1cm}

Example 3.  Suppose we throw $m$ balls into $n$ bins randomly. \\
            Let $X$ be the number of empty bins.

\vspace{1.5cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\begin{definition}
Let $S$ be a sample space and $X$ a random variable on $S$. Let $x$ be a value from the range of $X$. The probability of $x$, denoted by $$Pr(X=x)$$ is the sum of the probabilities of all outcomes $s$ of $S$ such that $X(s)=x$.
\end{definition}


\bigskip

Example 1 (cont.) \\
Let $X(s)$ be the number of 1 bits in a binary string with $n=4$ bits. \\
Here $r(X) = \{0,1,2,3,4\}$



\bigskip
Pr( X = 0 ) =

\medskip
Pr( X = 1 ) =

\medskip
Pr( X = 2 ) =

\medskip
Pr( X = 3 ) =

\medskip
Pr( X = 4 ) = 

\bigskip
\medskip
Pr( X = k ) = 

\vspace*{1cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\begin{definition}
The \textbf{expected value} of a random variable $X$ on a sample 
space $S$ is defined by
$$E(X) = \sum_{x \in r(X)} xPr(X=x) = \sum_{s\in S} X(s)Pr(s).$$
\end{definition}

\bigskip
Example 1 (cont.) \quad 
\begin{tabular}{c|ccccc}
$x$       &  0   &   1  &  2   &  3  &  4 \\ \hline
$Pr(X=x)$ & $\ds \frac{1}{16}$ & $\ds \frac{4}{16}$ & $\ds \frac{6}{16}$ & $\ds \frac{4}{16}$ & $\ds \frac{1}{16}$ 
\end{tabular}

\bigskip
{ $\ds E[X] = \sum_{x \in r(X)} x Pr(X=x) =$ }

\vspace{5cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{The Geometric Distribution}
Reference Example 9.18 on page 428 of Grimaldi

\medskip
Example 4.
On average, how many times must we roll a fair die before we get a 6?

\vspace{12cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Example 4 cont.

\vspace{12cm}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

Example 4 cont.

\vspace{7.5cm}

 Summary:  We say $T$ is geometrically distributed with parameter $p$ \\
 and $\Pr( T=k ) = p (1-p)^{k-1}$ for $k \ge 1$ and $E(T) = 1/p.$

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{The Binomial Distribution}

Example 5.  Suppose we toss a biased coin $n$ times.  \\
Let the probability of getting heads be $p=0.7$ and tails be $q=0.3$. \\
Let $H$ be the number of heads.  What is $\Pr(H=k)$ and $E(H)$?


\vspace{5.8cm}

 Summary:  We say $X$ is binomially distributed with parameters $p$ and $n$ \\
 and $\Pr( X=k ) = {n \choose k} p^k (1-p)^{n-k}$ for $0 \le k \le n$ and $E(X) = np.$

\end{frame}

