Sampling from glm posterior


I’ve fit a GLM to some data I have and would now like to same the posterior predictive distribution conditioned on some covariates. This would be equivalent to me predicting on new data.

Here is some code:

fml = ‘n_affected ~ success’

with pm.Model() as model:
    pm.glm.GLM.from_formula(formula=fml, data=df, family=pm.glm.families.NegativeBinomial())

    trace = pm.sample(5000, tune = 2000)

Here, success is a binary variable, and I am interested in sampling when success==1. Given I have set up my GLM in this manner, how can I sample from the posterior conditioned so that success == 1?


I would do normal sample_ppc, and then index to the ppc sample using the df to get the cases where success==1.