Hi there, I am beginning level leaner of pymc. I tried to build the following model to learn Prior and Posterior Predictive Checks. I ran the code to plot the predicted relationship. However, I got the error (TypeError: Dimension mismatch for x: (500, 1) and hdi: (1, 500, 2). Check the dimensions of y andhdi_kwargs to make sure they are compatible)
I checked the shape of posterior_predictive[‘y’]. It shows (4, 1000, 1, 500). It looks different from the example in Posterior Predictive Checks. I can’t figure out what went wrong. Can someone help me?
X = (df1[["temp_actual"]]).values
obs = (df1[['rides']]).values.T
with pm.Model() as model_1:
# Intercepts Priors
intercept = pm.Normal("intercept", mu=3000, sigma=1500)
# Slope Priors
slope = pm.Normal("slope", mu=100, sigma=40)
# Expected value
mu = intercept + slope.dot(X.T)
sigma = pm.Exponential("sigma", 0.0008)
# Data likelihood
y = pm.Normal('y', mu=mu, sigma=sigma, observed=obs)
idata_1 = pm.sample_prior_predictive(samples=100)
idata_1.extend(pm.sample(1000, tune=2000))
pm.sample_posterior_predictive(idata_1, extend_inferencedata=True)
# Plot the predicted relationship
post = idata_1.posterior
mu_pp = post["intercept"] + post["slope"] * xr.DataArray(df1['temp_actual'].values)
_, ax = plt.subplots()
ax.plot(
X, mu_pp.mean(("chain", "draw")), label="Mean outcome", color="C1", alpha=0.6
)
ax.scatter(X, idata_1.observed_data["y"])
az.plot_hdi(X, idata_1.posterior_predictive["y"])
ax.set_xlabel("Temp Actual")
ax.set_ylabel("Rides");