-
-
Notifications
You must be signed in to change notification settings - Fork 270
notebook: GLM Poisson regression, update header and footer #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed2a6b9
nb: GLM poisson regression, update header/footer
reshamas 5515287
adding myst file
reshamas e135442
nb: GLM poisson regression, notebook name
reshamas 66c3d39
add myst file
reshamas 83002b0
Merge branch 'main' of github.com:pymc-devs/pymc-examples into nb-poi…
reshamas 09a7d46
GLM poisson nb: update
reshamas 26abf4a
adding myst file
reshamas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
309 changes: 167 additions & 142 deletions
309
examples/generalized_linear_models/GLM-poisson-regression.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,15 +6,40 @@ jupytext: | |||||
format_version: 0.13 | ||||||
jupytext_version: 1.13.7 | ||||||
kernelspec: | ||||||
display_name: pymc_env | ||||||
display_name: pymc-ex | ||||||
language: python | ||||||
name: pymc_env | ||||||
name: pymc-ex | ||||||
--- | ||||||
|
||||||
+++ {"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": []} | ||||||
|
||||||
(GLM-poisson-regression)= | ||||||
# GLM: Poisson Regression | ||||||
|
||||||
:::{post} November 12, 2022 | ||||||
:tags: regression, poisson | ||||||
:category: Intermediate | ||||||
:author: Jonathan Sedar, Benjamin Vincent | ||||||
::: | ||||||
|
||||||
+++ {"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": []} | ||||||
|
||||||
This is a minimal reproducible example of Poisson regression to predict counts using dummy data. | ||||||
|
||||||
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. | ||||||
|
||||||
For more statistical detail see: | ||||||
|
||||||
+ Basic info on [Wikipedia](https://en.wikipedia.org/wiki/Poisson_regression) | ||||||
+ GLMs: Poisson regression, exposure, and overdispersion in Chapter 6.2 of [ARM, Gelmann & Hill 2006](http://www.stat.columbia.edu/%7Egelman/arm/) | ||||||
+ This worked example from ARM 6.2 by [Clay Ford](http://www.clayford.net/statistics/poisson-regression-ch-6-of-gelman-and-hill/) | ||||||
|
||||||
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. | ||||||
|
||||||
```{code-cell} ipython3 | ||||||
#!pip install seaborn | ||||||
``` | ||||||
|
||||||
```{code-cell} ipython3 | ||||||
--- | ||||||
papermill: | ||||||
|
@@ -53,20 +78,6 @@ rng = np.random.default_rng(RANDOM_SEED) | |||||
az.style.use("arviz-darkgrid") | ||||||
``` | ||||||
|
||||||
+++ {"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": []} | ||||||
|
||||||
This is a minimal reproducible example of Poisson regression to predict counts using dummy data. | ||||||
|
||||||
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. | ||||||
|
||||||
For more statistical detail see: | ||||||
|
||||||
+ Basic info on [Wikipedia](https://en.wikipedia.org/wiki/Poisson_regression) | ||||||
+ GLMs: Poisson regression, exposure, and overdispersion in Chapter 6.2 of [ARM, Gelmann & Hill 2006](http://www.stat.columbia.edu/%7Egelman/arm/) | ||||||
+ This worked example from ARM 6.2 by [Clay Ford](http://www.clayford.net/statistics/poisson-regression-ch-6-of-gelman-and-hill/) | ||||||
|
||||||
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. | ||||||
|
||||||
+++ {"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": []} | ||||||
|
||||||
## Local Functions | ||||||
reshamas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -489,7 +500,7 @@ posterior_predictive = model.predict(inf_fish_alt, kind="pps") | |||||
|
||||||
We can use `az.plot_ppc()` to check that the posterior predictive samples are similar to the observed data. | ||||||
|
||||||
For more information on posterior predictive checks, we can refer to https://docs.pymc.io/notebooks/posterior_predictive.html. | ||||||
For more information on posterior predictive checks, we can refer to {class}`pymc.posterior_predictive`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```{code-cell} ipython3 | ||||||
az.plot_ppc(inf_fish_alt); | ||||||
|
@@ -498,8 +509,9 @@ az.plot_ppc(inf_fish_alt); | |||||
+++ {"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": []} | ||||||
|
||||||
## Authors | ||||||
- Example originally contributed by Jonathan Sedar 2016-05-15 [github.com/jonsedar](https://github.com/jonsedar) | ||||||
- Example originally contributed by [Jonathan Sedar](https://github.com/jonsedar) 2016-05-15. | ||||||
- Updated to PyMC v4 by [Benjamin Vincent](https://github.com/drbenvincent) May 2022. | ||||||
- Notebook header and footer updated November 2022. | ||||||
|
||||||
+++ | ||||||
|
||||||
|
@@ -518,3 +530,6 @@ tags: [] | |||||
%load_ext watermark | ||||||
%watermark -n -u -v -iv -w -p aesara,aeppl | ||||||
``` | ||||||
|
||||||
:::{include} ../page_footer.md | ||||||
::: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flying dove in the preview: https://pymcio--462.org.readthedocs.build/projects/examples/en/462/generalized_linear_models/GLM-poisson-regression.html is not green because tagss and categories are case sensitive. it should be everything lowercase.