# Sample\_posterior\_predictive using prior instead of posterior parameters?

**URL:** <https://discourse.pymc.io/t/sample-posterior-predictive-using-prior-instead-of-posterior-parameters/14978>\
**Category:** v5\
**Tags:** bug, modeling\
**Created:** [August 27, 2024, 4:16pm UTC](https://discourse.pymc.io/t/sample-posterior-predictive-using-prior-instead-of-posterior-parameters/14978 "2024-08-27T16:16:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AFalk](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@AFalk](https://discourse.pymc.io/u/AFalk)\
**Post date:** [August 27, 2024, 4:16pm UTC](https://discourse.pymc.io/t/sample-posterior-predictive-using-prior-instead-of-posterior-parameters/14978/1 "2024-08-27T16:16:01Z")

</div>

Hello all,

I am finding a large discrepancy between the posterior and posterior\_predictive samples. This appears to be a similar issue to [here](https://discourse.pymc.io/t/posterior-predictive-not-similar-to-posterior/10461) where `sample_posterior_predictive` is returning samples from the prior. However, I am unable to resolve the behavior by setting `mutable=True`. Any ideas on how to fix this? I’ve pasted a toy example of my model below in addition to the code I am using to compare the posterior and posterior\_predictive samples.

```auto
def toy_heirarchical_model(group, ind_obs, coords, prior_config):

    with pm.Model(coords=coords) as model:
        group_idx = pm.Data("group_idx", group, dims='obs_id', mutable=True)
        obs = pm.Data("obs", ind_obs, dims='obs_id', mutable=True)

        room_CV = pm.Gamma(
            "room_CV", 
            alpha=prior_config["room_CV_alpha"], 
            beta=prior_config["room_CV_beta"]
        )
        
        group_CV = pm.Gamma("group_CV", mu=room_CV, sigma=0.03, dims="group")

        group_mean = pm.Normal("group_mean", 
                                mu=prior_config['group_means'],
                                sigma=3.2, 
                                dims="group")

        group_sigma = pm.Deterministic("group_sigma", group_mean*group_CV, dims="group")

        y_hat = group_mean[group_idx]
        sigma_hat = group_sigma[group_idx]

        y = pm.Normal("y", mu=y_hat, sigma=sigma_hat, observed=obs, dims="obs_id")

        idata = pm.sample_prior_predictive()
        idata.extend(pm.sample(tune=5000, draws=5000, target_accept=0.95, nuts_sampler='nutpie', progressbar=True))
        idata.extend(pm.sample_posterior_predictive(idata, var_names=['group_mean', 'group_sigma']))

    return idata, model

idata, model = toy_heirarchical_model(condition, prop_obs, coords, prior_config)

print(idata.posterior_predictive['group_mean'].values[0,:,0])
print(idata.posterior['group_mean'].values[0,:,0])

```
