Skip to content

Commit

Permalink
Updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDowney committed Nov 30, 2023
1 parent aa5c2f7 commit 4f241bb
Show file tree
Hide file tree
Showing 8 changed files with 614 additions and 458 deletions.
91 changes: 43 additions & 48 deletions soln/chap01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:08.628591Z",
Expand Down Expand Up @@ -124,7 +124,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:08.634488Z",
Expand Down Expand Up @@ -155,26 +155,19 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>caseid</th>\n",
" <th>year</th>\n",
" <th>age</th>\n",
" <th>sex</th>\n",
" <th>polviews</th>\n",
" <th>partyid</th>\n",
" <th>indus10</th>\n",
" </tr>\n",
" <tr>\n",
" <th>caseid</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>1974</td>\n",
" <td>21.0</td>\n",
" <td>1</td>\n",
Expand All @@ -183,7 +176,8 @@
" <td>4970.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>1974</td>\n",
" <td>41.0</td>\n",
" <td>1</td>\n",
Expand All @@ -192,7 +186,8 @@
" <td>9160.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <th>2</th>\n",
" <td>5</td>\n",
" <td>1974</td>\n",
" <td>58.0</td>\n",
" <td>2</td>\n",
Expand All @@ -201,7 +196,8 @@
" <td>2670.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <th>3</th>\n",
" <td>6</td>\n",
" <td>1974</td>\n",
" <td>30.0</td>\n",
" <td>1</td>\n",
Expand All @@ -210,7 +206,8 @@
" <td>6870.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <th>4</th>\n",
" <td>7</td>\n",
" <td>1974</td>\n",
" <td>48.0</td>\n",
" <td>1</td>\n",
Expand All @@ -223,24 +220,23 @@
"</div>"
],
"text/plain": [
" year age sex polviews partyid indus10\n",
"caseid \n",
"1 1974 21.0 1 4.0 2.0 4970.0\n",
"2 1974 41.0 1 5.0 0.0 9160.0\n",
"5 1974 58.0 2 6.0 1.0 2670.0\n",
"6 1974 30.0 1 5.0 4.0 6870.0\n",
"7 1974 48.0 1 5.0 4.0 7860.0"
" caseid year age sex polviews partyid indus10\n",
"0 1 1974 21.0 1 4.0 2.0 4970.0\n",
"1 2 1974 41.0 1 5.0 0.0 9160.0\n",
"2 5 1974 58.0 2 6.0 1.0 2670.0\n",
"3 6 1974 30.0 1 5.0 4.0 6870.0\n",
"4 7 1974 48.0 1 5.0 4.0 7860.0"
]
},
"execution_count": 2,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"gss = pd.read_csv('gss_bayes.csv', index_col=0)\n",
"gss = pd.read_csv('gss_bayes.csv')\n",
"gss.head()"
]
},
Expand All @@ -252,7 +248,7 @@
"\n",
"The columns are\n",
"\n",
"* `caseid`: Respondent id (which is the index of the table).\n",
"* `caseid`: Respondent identifier.\n",
"\n",
"* `year`: Year when the respondent was surveyed.\n",
"\n",
Expand Down Expand Up @@ -280,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.085579Z",
Expand All @@ -293,16 +289,15 @@
{
"data": {
"text/plain": [
"caseid\n",
"0 False\n",
"1 False\n",
"2 False\n",
"5 False\n",
"6 True\n",
"7 False\n",
"3 True\n",
"4 False\n",
"Name: indus10, dtype: bool"
]
},
"execution_count": 3,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -323,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.100573Z",
Expand All @@ -339,7 +334,7 @@
"728"
]
},
"execution_count": 4,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -359,7 +354,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.108607Z",
Expand All @@ -375,7 +370,7 @@
"0.014769730168391155"
]
},
"execution_count": 5,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -402,7 +397,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 10,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.115436Z",
Expand All @@ -427,7 +422,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 11,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.121943Z",
Expand All @@ -443,7 +438,7 @@
"0.014769730168391155"
]
},
"execution_count": 7,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -469,7 +464,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 12,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.133453Z",
Expand All @@ -492,7 +487,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 13,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.138777Z",
Expand All @@ -508,7 +503,7 @@
"0.5378575776019476"
]
},
"execution_count": 9,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -549,7 +544,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 14,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.144820Z",
Expand All @@ -572,7 +567,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 15,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.150191Z",
Expand All @@ -588,7 +583,7 @@
"0.27374721038750255"
]
},
"execution_count": 11,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -626,7 +621,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 16,
"metadata": {
"execution": {
"iopub.execute_input": "2021-04-16T19:35:09.156357Z",
Expand Down Expand Up @@ -1517,7 +1512,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### The Law of Total Probability\n",
"## The Law of Total Probability\n",
"\n",
"In addition to these three theorems, there's one more thing we'll need to do Bayesian statistics: the law of total probability.\n",
"Here's one form of the law, expressed in mathematical notation:\n",
Expand Down Expand Up @@ -2271,7 +2266,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions soln/chap02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@
"source": [
"I call the result `unnorm` because these values are the \"unnormalized posteriors\". Each of them is the product of a prior and a likelihood:\n",
"\n",
"$$P(B_i)~P(D|B_i)$$\n",
"$$P(H_i)~P(D|H_i)$$\n",
"\n",
"which is the numerator of Bayes's Theorem. \n",
"If we add them up, we have\n",
"\n",
"$$P(B_1)~P(D|B_1) + P(B_2)~P(D|B_2)$$\n",
"$$P(H_1)~P(D|H_1) + P(H_2)~P(D|H_2)$$\n",
"\n",
"which is the denominator of Bayes's Theorem, $P(D)$.\n",
"\n",
Expand Down Expand Up @@ -1703,7 +1703,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1717,7 +1717,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions soln/chap05.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -2101,7 +2101,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
239 changes: 108 additions & 131 deletions soln/chap06.ipynb

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions soln/chap10.ipynb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions soln/chap11.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions soln/chap15.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -4119,7 +4119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down
636 changes: 410 additions & 226 deletions soln/chap17.ipynb

Large diffs are not rendered by default.

0 comments on commit 4f241bb

Please sign in to comment.