Skip to content

Commit

Permalink
Added empty notebooks for Chapter 4 Linear models
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanistheone committed Feb 2, 2024
1 parent 622b4e0 commit 88abd93
Show file tree
Hide file tree
Showing 7 changed files with 614 additions and 5 deletions.
19 changes: 16 additions & 3 deletions notebooks/40_LINEAR_MODELS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Chapter 4 — Linear models

The notebooks for Chapter 4 are still WIP,
but you can check out the [Chapter 4 outline](https://docs.google.com/document/d/1fwep23-95U-w1QMPU31nOvUnUXE2X3s_Dbk5JuLlKAY/edit#heading=h.9etj7aw4al9w)
in the meantime to know what will be covered.
See the [Chapter 4 outline](https://docs.google.com/document/d/1fwep23-95U-w1QMPU31nOvUnUXE2X3s_Dbk5JuLlKAY/edit#heading=h.9etj7aw4al9w)
for an overview of what is covered in the book


## Notebooks

Each notebook contains the code examples from corresponding section in book.
If you're reading the book, you should follow along by running the commands in the these notebooks,
to check all the probability calculations for yourself.

- Simple linear regression [41_simple_linear_regression.ipynb](./41_simple_linear_regression.ipynb)
- Multiple linear regression [42_multiple_linear_regression.ipynb](./42_multiple_linear_regression.ipynb)
- Regression with categorical predictors [43_regression_with_categorical_predictors.ipynb](./43_regression_with_categorical_predictors.ipynb)
- Interpreting linear models [44_interpreting_linear_models.ipynb](./44_interpreting_linear_models.ipynb)
- Generalized linear models [45_generalized_linear_models.ipynb](./45_generalized_linear_models.ipynb)

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,115 @@
"cells": [
{
"cell_type": "markdown",
"id": "26c16732-ec02-44de-a151-004fbf636f01",
"id": "20494dde-6150-4220-9a0e-804415d7b5c6",
"metadata": {
"tags": []
},
"source": [
"# Section 4.1 — Simple linear regression\n",
"\n",
"This notebook contains the code examples from [Section 4.1 Simple linear regression]() from the **No Bullshit Guide to Statistics**."
]
},
{
"cell_type": "markdown",
"id": "f1aec2b4-6686-4991-8aa4-7d510c1b7564",
"metadata": {
"tags": []
},
"source": [
"#### Notebook setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "0003a9e7-21c7-47a5-bdec-3bd3ca2a79f4",
"metadata": {},
"outputs": [],
"source": [
"# Introduction to linear models"
"# load Python modules\n",
"import os\n",
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8e67e0e7-4f48-4c48-a49d-3cdf22cbd014",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 640x480 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Figures setup\n",
"plt.clf() # needed otherwise `sns.set_theme` doesn't work\n",
"from plot_helpers import RCPARAMS\n",
"# RCPARAMS.update({'figure.figsize': (10, 3)}) # good for screen\n",
"RCPARAMS.update({'figure.figsize': (5, 1.6)}) # good for print\n",
"sns.set_theme(\n",
" context=\"paper\",\n",
" style=\"whitegrid\",\n",
" palette=\"colorblind\",\n",
" rc=RCPARAMS,\n",
")\n",
"\n",
"# High-resolution please\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Where to store figures\n",
"DESTDIR = \"figures/lm/simple\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "efc0e89b-72bf-4658-8f8a-a3d85bee00b6",
"metadata": {},
"outputs": [],
"source": [
"# set random seed for repeatability\n",
"np.random.seed(42)"
]
},
{
"cell_type": "markdown",
"id": "6347dbe9-60ad-4baa-9163-1175d8fef2e0",
"metadata": {},
"source": [
"$\\def\\stderr#1{\\mathbf{se}_{#1}}$\n",
"$\\def\\stderrhat#1{\\hat{\\mathbf{se}}_{#1}}$\n",
"$\\newcommand{\\Mean}{\\textbf{Mean}}$\n",
"$\\newcommand{\\Var}{\\textbf{Var}}$\n",
"$\\newcommand{\\Std}{\\textbf{Std}}$\n",
"$\\newcommand{\\Freq}{\\textbf{Freq}}$\n",
"$\\newcommand{\\RelFreq}{\\textbf{RelFreq}}$\n",
"$\\newcommand{\\DMeans}{\\textbf{DMeans}}$\n",
"$\\newcommand{\\Prop}{\\textbf{Prop}}$\n",
"$\\newcommand{\\DProps}{\\textbf{DProps}}$\n",
"\n",
"$$\n",
"\\newcommand{\\CI}[1]{\\textbf{CI}_{#1}}\n",
"\\newcommand{\\CIL}[1]{\\textbf{L}_{#1}}\n",
"\\newcommand{\\CIU}[1]{\\textbf{U}_{#1}}\n",
"\\newcommand{\\ci}[1]{\\textbf{ci}_{#1}}\n",
"\\newcommand{\\cil}[1]{\\textbf{l}_{#1}}\n",
"\\newcommand{\\ciu}[1]{\\textbf{u}_{#1}}\n",
"$$\n",
"\n",
"\n",
"(this cell contains the macro definitions like $\\stderr{\\overline{\\mathbf{x}}}$, $\\stderrhat{}$, $\\Mean$, ...)"
]
},
{
Expand Down
117 changes: 117 additions & 0 deletions notebooks/42_multiple_linear_regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3ec95fa0-da20-41dc-820e-2f33f262f4e2",
"metadata": {
"tags": []
},
"source": [
"# Section 4.2 — Multiple linear regression\n",
"\n",
"This notebook contains the code examples from [Section 4.2 Multiple linear regression]() from the **No Bullshit Guide to Statistics**."
]
},
{
"cell_type": "markdown",
"id": "eb4d1856-22a1-4634-87d7-5fc091d93e12",
"metadata": {
"tags": []
},
"source": [
"#### Notebook setup"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0003a9e7-21c7-47a5-bdec-3bd3ca2a79f4",
"metadata": {},
"outputs": [],
"source": [
"# load Python modules\n",
"import os\n",
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8e67e0e7-4f48-4c48-a49d-3cdf22cbd014",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 500x160 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Figures setup\n",
"plt.clf() # needed otherwise `sns.set_theme` doesn't work\n",
"from plot_helpers import RCPARAMS\n",
"# RCPARAMS.update({'figure.figsize': (10, 3)}) # good for screen\n",
"RCPARAMS.update({'figure.figsize': (5, 1.6)}) # good for print\n",
"sns.set_theme(\n",
" context=\"paper\",\n",
" style=\"whitegrid\",\n",
" palette=\"colorblind\",\n",
" rc=RCPARAMS,\n",
")\n",
"\n",
"# High-resolution please\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Where to store figures\n",
"DESTDIR = \"figures/lm/multiple\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "efc0e89b-72bf-4658-8f8a-a3d85bee00b6",
"metadata": {},
"outputs": [],
"source": [
"# set random seed for repeatability\n",
"np.random.seed(42)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d67690c-bc4c-400c-9d49-cb7b3d31c894",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
117 changes: 117 additions & 0 deletions notebooks/43_regression_with_categorical_predictors.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3ec95fa0-da20-41dc-820e-2f33f262f4e2",
"metadata": {
"tags": []
},
"source": [
"# Section 4.3 — Regression with categorical predictors\n",
"\n",
"This notebook contains the code examples from [Section 4.3 Regression with categorical predictors]() from the **No Bullshit Guide to Statistics**."
]
},
{
"cell_type": "markdown",
"id": "eb4d1856-22a1-4634-87d7-5fc091d93e12",
"metadata": {
"tags": []
},
"source": [
"#### Notebook setup"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0003a9e7-21c7-47a5-bdec-3bd3ca2a79f4",
"metadata": {},
"outputs": [],
"source": [
"# load Python modules\n",
"import os\n",
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8e67e0e7-4f48-4c48-a49d-3cdf22cbd014",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 500x160 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Figures setup\n",
"plt.clf() # needed otherwise `sns.set_theme` doesn't work\n",
"from plot_helpers import RCPARAMS\n",
"# RCPARAMS.update({'figure.figsize': (10, 3)}) # good for screen\n",
"RCPARAMS.update({'figure.figsize': (5, 1.6)}) # good for print\n",
"sns.set_theme(\n",
" context=\"paper\",\n",
" style=\"whitegrid\",\n",
" palette=\"colorblind\",\n",
" rc=RCPARAMS,\n",
")\n",
"\n",
"# High-resolution please\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Where to store figures\n",
"DESTDIR = \"figures/lm/categorical\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "efc0e89b-72bf-4658-8f8a-a3d85bee00b6",
"metadata": {},
"outputs": [],
"source": [
"# set random seed for repeatability\n",
"np.random.seed(42)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d67690c-bc4c-400c-9d49-cb7b3d31c894",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 88abd93

Please sign in to comment.