@@ -6,9 +6,9 @@ jupytext:
6
6
format_version : 0.13
7
7
jupytext_version : 1.13.7
8
8
kernelspec :
9
- display_name : Python 3
9
+ display_name : pymc_env
10
10
language : python
11
- name : python3
11
+ name : pymc_env
12
12
---
13
13
14
14
+++ {"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": [ ] }
@@ -30,14 +30,10 @@ import bambi as bmb
30
30
import matplotlib.pyplot as plt
31
31
import numpy as np
32
32
import pandas as pd
33
- import pymc3 as pm
33
+ import pymc as pm
34
34
import seaborn as sns
35
- import theano
36
- import xarray as xr
37
35
38
36
from formulae import design_matrices
39
-
40
- print(f"Running on PyMC3 v{pm.__version__}")
41
37
```
42
38
43
39
``` {code-cell} ipython3
@@ -301,10 +297,15 @@ with pm.Model() as mdl_fish:
301
297
b3 = pm.Normal("alcohol:nomeds", mu=0, sigma=10)
302
298
303
299
# define linear model and exp link function
304
- theta = b0 + b1 * mx_ex["alcohol"] + b2 * mx_ex["nomeds"] + b3 * mx_ex["alcohol:nomeds"]
300
+ theta = (
301
+ b0
302
+ + b1 * mx_ex["alcohol"].values
303
+ + b2 * mx_ex["nomeds"].values
304
+ + b3 * mx_ex["alcohol:nomeds"].values
305
+ )
305
306
306
307
## Define Poisson likelihood
307
- y = pm.Poisson("y", mu=np .exp(theta), observed=mx_en["nsneeze"].values)
308
+ y = pm.Poisson("y", mu=pm.math .exp(theta), observed=mx_en["nsneeze"].values)
308
309
```
309
310
310
311
+++ {"papermill": {"duration": 0.049445, "end_time": "2021-02-23T11:27:35.720870", "exception": false, "start_time": "2021-02-23T11:27:35.671425", "status": "completed"}, "tags": [ ] }
@@ -322,7 +323,8 @@ papermill:
322
323
tags: []
323
324
---
324
325
with mdl_fish:
325
- inf_fish = pm.sample(1000, tune=1000, cores=4, return_inferencedata=True)
326
+ inf_fish = pm.sample()
327
+ # inf_fish.extend(pm.sample_posterior_predictive(inf_fish))
326
328
```
327
329
328
330
+++ {"papermill": {"duration": 0.118023, "end_time": "2021-02-23T11:29:24.142987", "exception": false, "start_time": "2021-02-23T11:29:24.024964", "status": "completed"}, "tags": [ ] }
@@ -443,7 +445,7 @@ papermill:
443
445
status: completed
444
446
tags: []
445
447
---
446
- inf_fish_alt = model.fit(draws=2000, tune=2000 )
448
+ inf_fish_alt = model.fit()
447
449
```
448
450
449
451
+++ {"papermill": {"duration": 0.075564, "end_time": "2021-02-23T11:31:30.375433", "exception": false, "start_time": "2021-02-23T11:31:30.299869", "status": "completed"}, "tags": [ ] }
@@ -480,21 +482,28 @@ az.summary(np.exp(inf_fish_alt.posterior), kind="stats")
480
482
+ Note that the posterior predictive samples have an extreme skew
481
483
482
484
``` {code-cell} ipython3
483
- model.posterior_predictive(inf_fish_alt, draws=None)
485
+ :tags: []
486
+
487
+ posterior_predictive = model.predict(inf_fish_alt, kind="pps")
484
488
```
485
489
486
490
We can use ` az.plot_ppc() ` to check that the posterior predictive samples are similar to the observed data.
487
491
488
492
For more information on posterior predictive checks, we can refer to https://docs.pymc.io/notebooks/posterior_predictive.html .
489
493
490
494
``` {code-cell} ipython3
491
- az.plot_ppc(inf_fish_alt, num_pp_samples=200 );
495
+ az.plot_ppc(inf_fish_alt);
492
496
```
493
497
494
498
+++ {"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": [ ] }
495
499
496
- ---
497
- Example originally contributed by Jonathan Sedar 2016-05-15 [ github.com/jonsedar] ( https://github.com/jonsedar )
500
+ ## Authors
501
+ - Example originally contributed by Jonathan Sedar 2016-05-15 [ github.com/jonsedar] ( https://github.com/jonsedar )
502
+ - Updated to PyMC v4 by [ Benjamin Vincent] ( https://github.com/drbenvincent ) May 2022.
503
+
504
+ +++
505
+
506
+ ## Watermark
498
507
499
508
``` {code-cell} ipython3
500
509
---
@@ -507,5 +516,5 @@ papermill:
507
516
tags: []
508
517
---
509
518
%load_ext watermark
510
- %watermark -n -u -v -iv -w
519
+ %watermark -n -u -v -iv -w -p aesara,aeppl
511
520
```
0 commit comments