In this case, I would say yes. More globally, it just uses the generative nature of any Bayesian model:
- You can infer parameters from the data, as we do classically – I like to call this “going upstream” and this is done with
pm.samplein PyMC3. - But you can also go the other way around (“downstream”) and simulate data from the parameters you inferred in the first step. That way, you’re checking the internal consistency of your model and see if the data it simulates are not completely off.
This is done withpm.sample_posterior_predictivebut you can always do it by hand, as long as you know what the model is. Here for instance, I think you can do:
p_post = scipy.special.expit(trace_11_4["a"][new_actor_id] + trace_11_4["b"][new_treat_id]))
If you do the manual computation of p_post I did above, I think your statement is true. When using sample_posterior_predictive, I think it’s not though: IIRC, this function samples from the inferred posterior instead of directly using the posterior samples in the trace – in which case there is random sampling happening.
This makes sense though: there is uncertainty in the values of a and b compatible with the data and the model, so there is uncertainty in p (and, downstream, in the Bernoulli trials), so it makes sense that the simulated p samples won’t always be the same.
Hope this is clear enough ![]()