With a simple linear regression, pymc.sample_posterior_predictive returns error:
shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (100,) and arg 1 with shape (20,).
I used 100 data points as predictor for modeling, and set 20 data points as new predictor for predictions. Why does this happen?
MacOS: BigSur (11.7)
pymc: 4.4.0
Code is something like this:
with pm.Model() as model:
sigma = pm.HalfCauchy('sigma', beta=10)
intercept = pm.Normal('intercept', 80, sigma=50)
beta = pm.Normal('beta', 0, sigma=50)
X = pm.MutableData('X', data['A'], dims='obs_id') # data['A']'s shape is (100,)
mu = intercept + X * beta
pm.Normal('y', mu, sigma=sigma, observed=data['y'])
mcmc_result = pm.sample(
draws=2000,
chains=4,
random_seed=123,
)
new_data = range(11, 31) # this has 20 data points
with model:
model.set_data('X', new_data, coords={'obs_id': range(len(new_data))})
y_pred = pm.sample_posterior_predictive(
mcmc_result,
var_names=['y'],
return_inferencedata=True,
predictions=True,
random_seed=123,
)