Prior and Posterior Predictive Checks — PyMC 4.4.0 documentation
I am a novice starting pymc4. can you help with the following what would be considered a simple example from the pymc docs for learners.
Running the following introductory code for learning about pymc 4 generates an error:
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
import xarray as xr
from scipy.special import expit as logistic
print(f"Runing on PyMC v{pm.version}")
Runing on PyMC v4.3.0
RANDOM_SEED = 58
rng = np.random.default_rng(RANDOM_SEED)
def standardize(series):
“”“Standardize a pandas series”“”
return (series - series.mean()) / series.std()
Generate some sample data:
N = 100
true_a, true_b, predictor = 0.5, 3.0, rng.normal(loc=2, scale=6, size=N)
true_mu = true_a + true_b * predictor
true_sd = 2.0
outcome = rng.normal(loc=true_mu, scale=true_sd, size=N)
f"{predictor.mean():.2f}, {predictor.std():.2f}, {outcome.mean():.2f}, {outcome.std():.2f}"
predictor_scaled = standardize(predictor)
outcome_scaled = standardize(outcome)
f"{predictor_scaled.mean():.2f}, {predictor_scaled.std():.2f}, {outcome_scaled.mean():.2f}, {outcome_scaled.std():.2f}"
with pm.Model() as model_1:
a = pm.Normal(“a”, 0.0, 0.5)
b = pm.Normal(“b”, 0.0, 1.0)
mu = a + b * predictor_scaled
sigma = pm.Exponential("sigma", 1.0)
pm.Normal("obs", mu=mu, sigma=sigma, observed=outcome_scaled)
pm.sample(1000, tune=2000, random_seed=rng)
az.plot_trace(idata);
pm.model_to_graphviz(model_1)
with model_1:
pm.sample_posterior_predictive(idata)
Generates the following error:
“different number of dimensions on data and dims: 3 vs 2”
Runs with pymc3 but gives above error on pymc4.
why is the error occurring and what exactly in simple terms does it mean?
Is there an easy way to correct dimensions/data conflict in pymc4?
Thanks in advance for your help.
DD