{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# HIDDEN\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"from datascience import *\n",
"from prob140 import *\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use('fivethirtyeight')\n",
"%matplotlib inline\n",
"from scipy import stats"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exact Distribution of a Sum ##"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We already know how to find the distribution of the sum of any two discrete random variables. \n",
"\n",
"$$\n",
"P(X+Y = k) = \\sum_j P(X=j, Y=k-j)\n",
"$$\n",
"\n",
"If $X$ and $Y$ are independent, this simplifies to become the *discrete convolution formula*:\n",
"\n",
"$$\n",
"P(X+Y = k) = \\sum_j P(X=j)P(Y=k-j)\n",
"$$\n",
"\n",
"By induction, we can extend this to the sum of any finite number of independent variables. \n",
"\n",
"So in principle, we know how to find the distribution of the sum of $n$ independent random variables for $n > 1$. However, this method can be hard to put into practice for large $n$. \n",
"\n",
"In this section we examine another way of approaching the problem of finding the distribution of a sum. It is an abstract mathematical approach that is also easier to automate, though it too comes up against computational barriers eventually."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```{admonition} Quick Check\n",
"$X_1$ and $X_2$ are i.i.d. with distribution given by $P(X_1 = i) = p_i$ for $1 \\le i \\le 3$ and $\\sum_{i=1}^3 p_i = 1$. Find the distribution of $S = X_1+X_2$.\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```{admonition} Answer\n",
":class: dropdown\n",
"$P(S=2) = p_1^2$, $P(S=3) = 2p_1p_2$, $P(S=4) = p_2^2 + 2p_1p_3$, $P(S=5) = 2p_2p_3$, $P(S=6)=p_3^2$\n",
"\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": [
"remove-input",
"hide-output"
]
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"