Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ea1528e
Ported pymc3 model to pymc v5
fonnesbeck Aug 10, 2024
ba67fe7
Output files
fonnesbeck Aug 12, 2024
ddedde9
Removed PyMC3 version
fonnesbeck Aug 12, 2024
10ece3b
Deleted data json
fonnesbeck Aug 12, 2024
d1f0241
Zip draws json
fonnesbeck Aug 12, 2024
80cd5cd
Remove accidental zip commit
fonnesbeck Aug 12, 2024
5cf8fe3
Add zipped draws
fonnesbeck Aug 12, 2024
cb2dac5
Remove unzipped posterior draws
fonnesbeck Aug 12, 2024
8cee381
Add posterior info file
fonnesbeck Aug 12, 2024
18da16f
Add summary stats file
fonnesbeck Aug 12, 2024
d74ad54
Add `GLM_Poisson_model` PyMC implementation.
PellelNitram Aug 12, 2024
a9a01ff
Move GLM Poisson model to correct folder.
PellelNitram Aug 12, 2024
c1c9036
M0 model draft
fonnesbeck Aug 12, 2024
d534bef
Update `GLM_Poisson_model.info.json` with PyMC model implementation.
PellelNitram Aug 12, 2024
91f6954
Fixes
MansMeg Oct 15, 2023
43ad7ad
Ignore jupyter checkpoints
ricardoV94 Aug 12, 2024
66b5949
Implement Binomial GLM in PyMC
ricardoV94 Aug 12, 2024
f1f6416
Add notes on how to sample PyMC models
ricardoV94 Aug 12, 2024
e3eb292
Remove raw data file
fonnesbeck Aug 12, 2024
bf34cfc
Non-empty model file!
fonnesbeck Aug 12, 2024
9f5f250
Added imports
fonnesbeck Aug 12, 2024
557d6f3
Update formatting of `GLM_Poisson_model.py`.
PellelNitram Aug 12, 2024
221352a
implement earnings-height model in pymc
jessegrabowski Aug 12, 2024
49a3ad6
Add the arma11 model
Aug 13, 2024
905f984
Adding reference data for arma
Aug 14, 2024
c5b25e4
fixing typos
JTorgander Apr 11, 2025
1fb539c
Fixing beta2 prior upper bound
JTorgander Apr 11, 2025
0d1e8ce
Merge pull request #276 from JTorgander/glmm-poisson-prior-fix
MansMeg Apr 18, 2025
bd68ea7
Merge pull request #275 from JTorgander/typo-fix
MansMeg Apr 18, 2025
157c9f3
Update citation in README
avehtari Apr 24, 2025
4d9a16e
Merge branch 'development' into avehtari-patch-1
JTorgander Apr 24, 2025
39b4703
Merge pull request #280 from stan-dev/avehtari-patch-1
JTorgander Apr 24, 2025
03216eb
Merge pull request #282 from JTorgander/CI-update
MansMeg Apr 28, 2025
4c543a7
Updated CITATION information
MansMeg Apr 30, 2025
92d844f
adding rate1 model
JTorgander May 19, 2025
48168e4
adding rate3 model
JTorgander May 19, 2025
675fbe2
adding dogs-hierarchical model
JTorgander May 19, 2025
6a7dc4b
Updating posterior info files
JTorgander May 26, 2025
5a0d7a5
Fix argument type
avehtari Jun 4, 2025
006bee7
fix argument type in two other irt models
avehtari Jun 4, 2025
ecc083d
Merge pull request #296 from stan-dev/master
MansMeg Jun 4, 2025
36e2a91
Merge pull request #295 from stan-dev/avehtari-patch-2
MansMeg Jun 4, 2025
9653aea
Merge pull request #291 from stan-dev/ref-draws
MansMeg Aug 12, 2025
f47439f
Adds ref. draws for nes_logit_data model
JTorgander Aug 15, 2025
9929436
Adds ref. draws for wells_data model
JTorgander Aug 15, 2025
f19ff76
Adds ref. draws for wells_dist100 model
JTorgander Aug 15, 2025
a817467
Adds ref. draws for dogs-dogs model
JTorgander Aug 15, 2025
fbee043
Merge pull request #302 from stan-dev/ref-draws
MansMeg Aug 15, 2025
f3fc5bc
Revert "Adding ref draws round 2"
JTorgander Aug 22, 2025
ca01e30
Merge pull request #304 from stan-dev/revert-302-ref-draws
JTorgander Aug 22, 2025
6e01d8c
Adding ref. draws and info files for nes_logit_data
JTorgander Aug 22, 2025
2c2da89
Adds ref. draws and info files for wells_data model
JTorgander Aug 22, 2025
0819720
Adds ref. draws and info files for wells_dist100 model
JTorgander Aug 22, 2025
8500e4c
Adding ref. draws and info files for dogs-dogs model
JTorgander Aug 22, 2025
c2a4eb5
Merge pull request #305 from stan-dev/ref-draws
MansMeg Aug 22, 2025
ffcdda1
Adds ref. draws and info files for radon_all-radon_pooled model
JTorgander Aug 29, 2025
33ae738
Adds ref. draws and info files for radon_mn-radon_pooled model
JTorgander Aug 29, 2025
ac942c6
Adds ref. draws and info files for Rate_2_data_Rate_2_model model
JTorgander Aug 29, 2025
e79096f
Add ref. draws and info files for Rate_5_data-Rate_5_model model
JTorgander Aug 29, 2025
1a1edf4
Merge pull request #306 from stan-dev/ref-draws
MansMeg Aug 29, 2025
38c8085
Updates prior and likelihood definition
JTorgander Dec 1, 2025
4bf714b
Removing extra files
JTorgander Jan 16, 2026
04ca691
Removing extra files
JTorgander Jan 16, 2026
d271c4f
Removing data dependence and sampling from model object
JTorgander Jan 16, 2026
7cac3c5
Removing extra files
JTorgander Jan 16, 2026
0f2a109
Removes extra file
JTorgander Jan 16, 2026
d13ec18
Restoring pymc3 folder
JTorgander Jan 16, 2026
370d0b8
Splitting beta parameter to individual components
JTorgander Jan 16, 2026
cd00dda
Removing extra files
JTorgander Jan 16, 2026
473d1bd
Updating prior definition
JTorgander Jan 16, 2026
54c58fe
Removing pymc ref draws
JTorgander Jan 16, 2026
3b3ab83
adding marginalized model version
JTorgander Jan 23, 2026
102599d
removing ref draws
JTorgander Jan 23, 2026
b06f4a3
small fix
JTorgander Jan 23, 2026
562776e
Merge pull request #270 from Ch0ronomato/arma11_pymc
MansMeg Feb 3, 2026
69d76dc
Merge pull request #265 from ricardoV94/binomial_model_pymc
MansMeg Feb 3, 2026
dfe4277
Merge pull request #267 from PellelNitram/pymc_poisson_glm
MansMeg Feb 3, 2026
56a1f07
renaming pymc model file
JTorgander Feb 9, 2026
4889455
Updates model info file
JTorgander Feb 9, 2026
7a1fbc1
Adds pymc version info
JTorgander Feb 9, 2026
03c98a8
Fixes model info typo
JTorgander Feb 9, 2026
d1819ff
Merge pull request #314 from stan-dev/typo_fix
MansMeg Feb 9, 2026
666c698
Merge pull request #269 from jessegrabowski/earn-height-pymc
JTorgander Feb 13, 2026
0fe01bf
Merge pull request #264 from fonnesbeck/eight_schools_nc_pymc
JTorgander Feb 13, 2026
6055179
Set reference_posterior_name to null
JTorgander Feb 13, 2026
d3c948f
Retrigger PR checks
JTorgander Mar 23, 2026
12dc6b9
Merge pull request #266 from fonnesbeck/M0_pymc
JTorgander Mar 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ message: "If you use posteriordb, please cite it as below."
authors:
- family-names: Magnusson
given-names: Måns
- family-names: Torgander
given-names: Jakob
- family-names: Bürkner
given-names: Paul
- family-names: Zhang
given-names: Lu
- family-names: Carpenter
given-names: Bob
- family-names: Vehtari
given-names: Aki
title: "posteriordb: a set of posteriors for Bayesian inference and probabilistic programming"
version: 0.5
date-released: 2023-10-15
title: "posteriordb: Testing, Benchmarking and Developing Bayesian Inference Algorithms"
version: 1.0
date-released: 2025-04-29
10 changes: 9 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ Most model code are using the the same BSD-3 licence. Although, some models and
To simplify the use of `posteriordb`, there are convenience functions both in Python and in R. To use R, see the [posteriordb-r](https://github.com/stan-dev/posteriordb-r) repository, and to use Python, see the [posteriordb-python](https://github.com/stan-dev/posteriordb-python) repository.

## Citing `posteriordb`
Developing and maintaining open-source software is an important yet often underappreciated contribution to scientific progress. Thus, please make sure to cite it appropriately so that developers get credit for their work. Information on how to cite `posteriordb` can be found in the [CITATION.cff](https://github.com/stan-dev/posteriordb/blob/master/CITATION.cff) file. Use the "cite this repository" button under "About" to get a simple BibTeX or APA snippet.
Developing and maintaining open-source software is an important yet often underappreciated contribution to scientific progress. Thus, please make sure to cite it appropriately so that developers get credit for their work.

To cite the actual posterior database on github, information can be found in the [CITATION.cff](https://github.com/stan-dev/posteriordb/blob/master/CITATION.cff) file. Use the "cite this repository" button under "About" to get a simple BibTeX or APA snippet.

We have also released a paper describing `posteriordb` that we encourage to cite when using `posteriordb`:

Magnusson, M., Torgander, J., Bürkner, P., Zhang, L., Carpenter, B., Vehtari, A.. (2025). posteriordb: Testing, Benchmarking and Developing Bayesian Inference Algorithms. *Proceedings of The 28th International Conference on Artificial Intelligence and Statistics*, in *Proceedings of Machine Learning Research* 258:1198-1206 Available from (https://proceedings.mlr.press/v258/magnusson25a.html)[https://proceedings.mlr.press/v258/magnusson25a.html].

If you do extensive testing of individual posterior, also please consider citing the paper that introduced the posterior by citing the origin of the posterior. This information can be found in the meta data associated with the posterior, data an/or model.

As `posteriordb` rely heavily on Stan, so please consider also to cite Stan:

Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,29 @@ repository.
Developing and maintaining open-source software is an important yet
often underappreciated contribution to scientific progress. Thus, please
make sure to cite it appropriately so that developers get credit for
their work. Information on how to cite `posteriordb` can be found in the
their work.

To cite the actual posterior database on github, information can be
found in the
[CITATION.cff](https://github.com/stan-dev/posteriordb/blob/master/CITATION.cff)
file. Use the “cite this repository” button under “About” to get a
simple BibTeX or APA snippet.

We have also released a paper describing `posteriordb` that we encourage
to cite when using `posteriordb`:

Magnusson, M., Torgander, J., Bürkner, P., Zhang, L., Carpenter, B.,
Vehtari, A.. (2025). posteriordb: Testing, Benchmarking and Developing
Bayesian Inference Algorithms. *Proceedings of The 28th International
Conference on Artificial Intelligence and Statistics*, in *Proceedings
of Machine Learning Research* 258:1198-1206 Available from
(<https://proceedings.mlr.press/v258/magnusson25a.html>)\[<https://proceedings.mlr.press/v258/magnusson25a.html>\].

If you do extensive testing of individual posterior, also please
consider citing the paper that introduced the posterior by citing the
origin of the posterior. This information can be found in the meta data
associated with the posterior, data an/or model.

As `posteriordb` rely heavily on Stan, so please consider also to cite
Stan:

Expand Down
4 changes: 4 additions & 0 deletions posterior_database/models/info/GLM_Binomial_model.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"stan": {
"model_code": "models/stan/GLM_Binomial_model.stan",
"stan_version": ">=2.26.0"
},
"pymc": {
"model_code": "models/pymc/GLM_Binomial_model.py",
"pymc_version": ">=5.16.2"
}
},
"licence": "BSD3"
Expand Down
4 changes: 4 additions & 0 deletions posterior_database/models/info/GLM_Poisson_model.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"stan": {
"model_code": "models/stan/GLM_Poisson_model.stan",
"stan_version": ">=2.26.0"
},
"pymc": {
"model_code": "models/pymc/GLM_Poisson_model.py",
"pymc_version": ">=5.16.2"
}
},
"licence": "BSD3"
Expand Down
4 changes: 4 additions & 0 deletions posterior_database/models/info/M0_model.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"stan": {
"model_code": "models/stan/M0_model.stan",
"stan_version": ">=2.26.0"
},
"pymc": {
"model_code": "models/pymc/M0_model.py",
"pymc_version": ">=5.16.0"
}
},
"licence": "BSD3"
Expand Down
16 changes: 16 additions & 0 deletions posterior_database/models/info/M0_model_discrete.info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "M0_model_discrete",
"keywords": ["BPA", "Ch.6", "Population", "Capture", "Recapture", "Individual", "Constant", "Discrete"],
"title": "Inferring population size with constant detection probability",
"description": "Detection probability of an individual is assumed constant over individuals and over time periods",
"urls": "https://github.com/stan-dev/example-models/blob/master/BPA/Ch.06",
"references": "kery2011population",
"added_by": "Chris Fonnesbeck",
"added_date": "2021-06-24",
"model_implementations": {
"pymc": {
"model_code": "models/pymc/M0_model_discrete.py",
"pymc_version": ">=5.16.0"
}
}
}
4 changes: 4 additions & 0 deletions posterior_database/models/info/earn_height.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"stan": {
"model_code": "models/stan/earn_height.stan",
"stan_version": ">=2.26.0"
},
"pymc": {
"model_code": "models/pymc/earn_height.py",
"pymc_version": ">=5.16.2"
}
},
"references": "gelman2006data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"model_code": "models/stan/eight_schools_noncentered.stan",
"stan_version": ">=2.26.0"
},
"pymc3": {
"model_code": "models/pymc3/eight_schools_noncentered.py"
"pymc": {
"model_code": "models/pymc/eight_schools_noncentered.py",
"pymc_version": ">=5.16.2"
}
},
"added_by": "Mans Magnusson",
Expand Down
4 changes: 2 additions & 2 deletions posterior_database/models/info/rats_model.info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rats_model",
"keywords": ["Heirarchical", "Normal", "Rats", "Random Effects", "Linear Growth", "Linear"],
"title": "Normal Heirarchical Model to Model Rats' Weight Over Time",
"keywords": ["Hierarchical", "Normal", "Rats", "Random Effects", "Linear Growth", "Linear"],
"title": "Normal Hierarchical Model to Model Rats' Weight Over Time",
"description": "The model is essentially a random effects linear growth curve.",
"urls": "https://github.com/stan-dev/example-models/tree/master/bugs_examples/vol1/rats",
"references": "gelfand1990illustration",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "seeds_centered_model",
"keywords": ["Random", "Effect", "Logistic", "Regression", "Stanified", "Centered"],
"title": "Normal Heirarchical Model to Model Rats' Weight Over Time",
"title": "Random Effect Logistic Regression for Seed Germination Proportion",
"description": "The model is essentially a random effects logistic,\n allowing for over-dispersion. Models the proportion of germination\n of different seeds in different root extracts. 'Stanified' & centered:\n tau replaced by sigma, direct estimation using \n narrower semi-informative priors, coefficients are centered",
"urls": "http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf",
"references": "crowder1978beta",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "seeds_stanified_model",
"keywords": ["Random", "Effect", "Logistic", "Regression", "Stanified"],
"title": "Normal Heirarchical Model to Model Rats' Weight Over Time",
"title": "Random Effect Logistic Regression for Seed Germination Proportion",
"description": "The model is essentially a random effects logistic,\n allowing for over-dispersion. Models the proportion of germination\n of different seeds in different root extracts. 'Stanified':\n tau replaced by sigma, direct estimation using \n narrower semi-informative priors",
"urls": "http://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol1.pdf",
"references": "crowder1978beta",
Expand Down
21 changes: 21 additions & 0 deletions posterior_database/models/pymc/GLM_Binomial_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import pymc as pm

def model(data):

with pm.Model(coords={"year": range(40)}) as pymc_model:
year = pm.Data("year_data", np.array(data["year"]), dims="year")
N = pm.Data("N_data", np.array(data["N"]), dims="year")
C = pm.Data("C_data", np.array(data["C"]), dims="year")

alpha = pm.Normal("alpha", mu=0, sigma=100)
beta1 = pm.Normal("beta1", mu=0, sigma=100)
beta2 = pm.Normal("beta2", mu=0, sigma=100)

year_squared = year ** 2
logit_p = alpha + beta1 * year + beta2 * year_squared
pm.Binomial("C", n=N, logit_p=logit_p, observed=C, dims="year")

p = pm.Deterministic("p", pm.math.invlogit(logit_p), dims="year")

return pymc_model
36 changes: 36 additions & 0 deletions posterior_database/models/pymc/GLM_Poisson_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import pymc as pm
import pytensor.tensor as pt

def model(data):
years_data = np.array(data["year"])
counts_data = np.array(data["C"])
number_observations = data["n"]
coords = {
"features": ["years", "years**2", "years**3"],
"observation": np.arange(number_observations),
}
with pm.Model(coords=coords) as pymc_model:
alpha = pm.Uniform("alpha", -20, +20)
beta1 = pm.Uniform("beta1", -10, +10)
beta2 = pm.Uniform("beta2", -10, +10)
beta3 = pm.Uniform("beta3", -10, +10)

X = pm.Data(
"X",
np.column_stack([years_data, years_data**2, years_data**3]),
dims=["observation", "feature"],
)
y = pm.Data("y", counts_data, dims="observation")

beta = pm.Deterministic("beta", pt.stack([beta1, beta2, beta3]), dims = "feature")

log_lambda = pm.Deterministic(
"log_lambda", alpha + X @ beta, dims="observation"
)

counts = pm.Poisson(
"counts", mu=pm.math.exp(log_lambda), observed=y, dims="observation"
)

return pymc_model
35 changes: 35 additions & 0 deletions posterior_database/models/pymc/M0_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
import pymc as pm

def model(data):
y = np.array(data["y"]) # capture history matrix
T = np.array(data["T"]) # time periods

coords = {"individual": np.arange(data["M"]),
"capture_period": np.arange(data["T"])}
with pm.Model(coords=coords) as pymc_model:
y_data = pm.Data("y", y, dims=("individual", "capture_period"))
s = pm.Deterministic("s", y_data.sum(axis=1), dims="individual")
is_observed = s > 0

# Inclusion probability
omega = pm.Uniform("omega", 0, 1)
# Capture probability
p = pm.Uniform("p", 0, 1)

# Defining bernoulli and binomial components
binom = pm.Binomial.dist(n=T, p=p)
log_omega = pm.math.log(omega)
log_one_minus_omega = pm.math.log(1-omega)
log_one_minus_p = pm.math.log(1-p)

# Computing marginalization mixture
logp_if_obs = log_omega + pm.logp(binom, s)
logp_zero_single = pm.math.logaddexp(log_omega + T * log_one_minus_p , log_one_minus_omega)
logp_each = pm.math.switch(is_observed, logp_if_obs, logp_zero_single)

pm.Potential("likelihood", logp_each.sum())

omega_nd = pm.Deterministic("omega_nd", (omega * (1 -p)**T) / (omega * (1 - p)**T + (1 - omega)))

return pymc_model
25 changes: 25 additions & 0 deletions posterior_database/models/pymc/M0_model_discrete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import pymc as pm

def model(data):
y = np.array(data["y"]) # capture history matrix
T = np.array(data["T"]) # time periods
coords = {"individual": np.arange(data["M"]),
"capture_period": np.arange(data["T"])}
with pm.Model(coords=coords) as pymc_model:

# Inclusion probability
omega = pm.Uniform("omega", 0, 1)
# Capture probability
p = pm.Uniform("p", 0, 1)

# Inclusion indicator
z = pm.Bernoulli("z", p=omega, dims="individual")

y_obs = pm.Bernoulli("y_obs", p=z[:, None]*p, observed=y, dims=("individual", "capture_period"))

N = pm.Deterministic("N", pm.math.sum(z))

omega_nd = pm.Deterministic("omega_nd", (omega * (1 -p)**T) / (omega * (1 - p)**T + (1 - omega)))

return pymc_model
43 changes: 43 additions & 0 deletions posterior_database/models/pymc/arma11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pymc as pm
import pytensor
import pytensor.tensor as pt
def model(data):
y_obs = data["y"] # Observed series
up_to = data["T"] # Timesteps
with pm.Model() as pymc_model:
mu = pm.Normal(
"mu", mu=0, sigma=10
) # mean coefficient
phi = pm.Normal(
"phi", mu=0, sigma=2
) # autoregressive coef
theta = pm.Normal(
"theta", mu=0, sigma=2
) # moving average
sigma = pm.HalfCauchy(
"sigma", beta=2.5
) # noise scale

# scan variables
y = pt.as_tensor_variable(y_obs)
y_hat0 = mu + phi * mu
err0 = y[0] - y_hat0
outputs_info = [y_hat0, err0, y[0]]

def step(curr_obs, prev_pred, prev_err, prev_obs, mu, phi, theta):
y_hat = mu + phi * prev_obs + theta * prev_err
new_err = curr_obs - y_hat
return [y_hat, new_err, curr_obs]

[predictions, _, _] , _ = pytensor.scan(fn=step,
outputs_info=outputs_info,
sequences=y[1:],
non_sequences=[mu, phi, theta])

# concatenating predictions
y_hat0_vec = y_hat0.dimshuffle("x")
final_predictions = pt.concatenate([y_hat0_vec, predictions])

pm.Normal("y", mu=final_predictions, sigma=sigma, observed=y)

return pymc_model
23 changes: 23 additions & 0 deletions posterior_database/models/pymc/earn_height.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
import pymc as pm

def model(data):

# Define PyMC Model
coords = {
'obs_idx': np.arange(data["N"]),
'feature': ['intercept', 'height']
}

with pm.Model(coords=coords) as earn_height:
N = pm.Data("N", data["N"])
earn = pm.Data('earn', data['earn'], dims=['obs_idx'])
height = pm.Data('height', data['height'], dims=['obs_idx'])

beta = pm.Flat('beta', dims=['feature'])
mu = beta[0] + beta[1] * height

sigma = pm.HalfFlat('sigma')
earn_hat = pm.Normal('earn_hat', mu=mu, sigma=sigma, observed=earn, dims=['obs_idx'])

return earn_height
18 changes: 18 additions & 0 deletions posterior_database/models/pymc/eight_schools_noncentered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import pymc as pm


def model(data):
y_obs = np.array(data["y"]) # estimated treatment
sigma = np.array(data["sigma"]) # std of estimated effect
coords = {"school": np.arange(data["J"])}
with pm.Model(coords=coords) as pymc_model:

mu = pm.Normal(
"mu", mu=0, sigma=5
) # hyper-parameter of mean, non-informative prior
tau = pm.HalfCauchy("tau", beta=5) # hyper-parameter of sigma
theta_trans = pm.Normal("theta_trans", mu=0, sigma=1, dims="school")
theta = mu + tau * theta_trans
y = pm.Normal("y", mu=theta, sigma=sigma, observed=y_obs)
return pymc_model
Loading
Loading