Skip to content

Commit f3594b5

Browse files
authored
notebook: GLM Poisson regression, update header and footer (#462)
* nb: GLM poisson regression, update header/footer * adding myst file * nb: GLM poisson regression, notebook name * add myst file * GLM poisson nb: update * adding myst file
1 parent fed95b2 commit f3594b5

File tree

2 files changed

+201
-162
lines changed

2 files changed

+201
-162
lines changed

examples/generalized_linear_models/GLM-poisson-regression.ipynb

Lines changed: 167 additions & 143 deletions
Large diffs are not rendered by default.

myst_nbs/generalized_linear_models/GLM-poisson-regression.myst.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,40 @@ jupytext:
66
format_version: 0.13
77
jupytext_version: 1.13.7
88
kernelspec:
9-
display_name: pymc_env
9+
display_name: pymc-ex
1010
language: python
11-
name: pymc_env
11+
name: pymc-ex
1212
---
1313

1414
+++ {"papermill": {"duration": 0.043172, "end_time": "2021-02-23T11:26:55.064791", "exception": false, "start_time": "2021-02-23T11:26:55.021619", "status": "completed"}, "tags": []}
1515

16+
(GLM-poisson-regression)=
1617
# GLM: Poisson Regression
1718

19+
:::{post} November 30, 2022
20+
:tags: regression, poisson
21+
:category: intermediate
22+
:author: Jonathan Sedar, Benjamin Vincent
23+
:::
24+
25+
+++ {"papermill": {"duration": 0.069202, "end_time": "2021-02-23T11:27:01.489628", "exception": false, "start_time": "2021-02-23T11:27:01.420426", "status": "completed"}, "tags": []}
26+
27+
This is a minimal reproducible example of Poisson regression to predict counts using dummy data.
28+
29+
This Notebook is basically an excuse to demo Poisson regression using PyMC, both manually and using `bambi` to demo interactions using the `formulae` library. We will create some dummy data, Poisson distributed according to a linear model, and try to recover the coefficients of that linear model through inference.
30+
31+
For more statistical detail see:
32+
33+
+ Basic info on [Wikipedia](https://en.wikipedia.org/wiki/Poisson_regression)
34+
+ GLMs: Poisson regression, exposure, and overdispersion in Chapter 6.2 of [ARM, Gelmann & Hill 2006](http://www.stat.columbia.edu/%7Egelman/arm/)
35+
+ This worked example from ARM 6.2 by [Clay Ford](http://www.clayford.net/statistics/poisson-regression-ch-6-of-gelman-and-hill/)
36+
37+
This very basic model is inspired by [a project by Ian Osvald](http://ianozsvald.com/2016/05/07/statistically-solving-sneezes-and-sniffles-a-work-in-progress-report-at-pydatalondon-2016/), which is concerned with understanding the various effects of external environmental factors upon the allergic sneezing of a test subject.
38+
39+
```{code-cell} ipython3
40+
#!pip install seaborn
41+
```
42+
1843
```{code-cell} ipython3
1944
---
2045
papermill:
@@ -53,20 +78,6 @@ rng = np.random.default_rng(RANDOM_SEED)
5378
az.style.use("arviz-darkgrid")
5479
```
5580

56-
+++ {"papermill": {"duration": 0.069202, "end_time": "2021-02-23T11:27:01.489628", "exception": false, "start_time": "2021-02-23T11:27:01.420426", "status": "completed"}, "tags": []}
57-
58-
This is a minimal reproducible example of Poisson regression to predict counts using dummy data.
59-
60-
This Notebook is basically an excuse to demo Poisson regression using PyMC3, both manually and using `bambi` to demo interactions using the `formulae` library. We will create some dummy data, Poisson distributed according to a linear model, and try to recover the coefficients of that linear model through inference.
61-
62-
For more statistical detail see:
63-
64-
+ Basic info on [Wikipedia](https://en.wikipedia.org/wiki/Poisson_regression)
65-
+ GLMs: Poisson regression, exposure, and overdispersion in Chapter 6.2 of [ARM, Gelmann & Hill 2006](http://www.stat.columbia.edu/%7Egelman/arm/)
66-
+ This worked example from ARM 6.2 by [Clay Ford](http://www.clayford.net/statistics/poisson-regression-ch-6-of-gelman-and-hill/)
67-
68-
This very basic model is inspired by [a project by Ian Osvald](http://ianozsvald.com/2016/05/07/statistically-solving-sneezes-and-sniffles-a-work-in-progress-report-at-pydatalondon-2016/), which is concerned with understanding the various effects of external environmental factors upon the allergic sneezing of a test subject.
69-
7081
+++ {"papermill": {"duration": 0.06268, "end_time": "2021-02-23T11:27:01.615645", "exception": false, "start_time": "2021-02-23T11:27:01.552965", "status": "completed"}, "tags": []}
7182

7283
## Local Functions
@@ -77,7 +88,7 @@ This very basic model is inspired by [a project by Ian Osvald](http://ianozsvald
7788

7889
+++ {"papermill": {"duration": 0.060542, "end_time": "2021-02-23T11:27:01.884617", "exception": false, "start_time": "2021-02-23T11:27:01.824075", "status": "completed"}, "tags": []}
7990

80-
This dummy dataset is created to emulate some data created as part of a study into quantified self, and the real data is more complicated than this. Ask Ian Osvald if you'd like to know more https://twitter.com/ianozsvald
91+
This dummy dataset is created to emulate some data created as part of a study into quantified self, and the real data is more complicated than this. Ask Ian Osvald if you'd like to know more [@ianozvald](https://twitter.com/ianozsvald).
8192

8293

8394
### Assumptions:
@@ -489,7 +500,7 @@ posterior_predictive = model.predict(inf_fish_alt, kind="pps")
489500

490501
We can use `az.plot_ppc()` to check that the posterior predictive samples are similar to the observed data.
491502

492-
For more information on posterior predictive checks, we can refer to https://docs.pymc.io/notebooks/posterior_predictive.html.
503+
For more information on posterior predictive checks, we can refer to {ref}`pymc:posterior_predictive`.
493504

494505
```{code-cell} ipython3
495506
az.plot_ppc(inf_fish_alt);
@@ -498,8 +509,9 @@ az.plot_ppc(inf_fish_alt);
498509
+++ {"papermill": {"duration": 0.106366, "end_time": "2021-02-23T11:31:34.956844", "exception": false, "start_time": "2021-02-23T11:31:34.850478", "status": "completed"}, "tags": []}
499510

500511
## Authors
501-
- Example originally contributed by Jonathan Sedar 2016-05-15 [github.com/jonsedar](https://github.com/jonsedar)
512+
- Example originally contributed by [Jonathan Sedar](https://github.com/jonsedar) 2016-05-15.
502513
- Updated to PyMC v4 by [Benjamin Vincent](https://github.com/drbenvincent) May 2022.
514+
- Notebook header and footer updated November 2022.
503515

504516
+++
505517

@@ -518,3 +530,6 @@ tags: []
518530
%load_ext watermark
519531
%watermark -n -u -v -iv -w -p aesara,aeppl
520532
```
533+
534+
:::{include} ../page_footer.md
535+
:::

0 commit comments

Comments
 (0)