Plot predictions by category in a model with multiple categories

Dear Bayesians,

for learning purposes, I created a simple bambi model with two categorical “predictors” with a “conversion rate” as target variable:

model = bmb.Model(
    "conversion ~ (1|age_group) + (1|zip_code)",
    family="bernoulli",
    data=data
)

Bambi creates the following model:

There are 4 combinations in my toy data for age groups and zip codes:

age_groups = [“26-30”, “31-35”]
zip_codes = [“65”, “75”]

Conversion rates are such that 31-35 has higher conversion than the other age group and zip code “75” has higher conversion than the other. I.e., the model should find different conversion rates for the 4 combinations.

The posterior plot show exactly this:

Now, as you can see in this plot, the parameter space is not in probabilities, but in logits. I guess this is for numerical stability. However, what I finally want to see is the “posterior predictive” distributions for the 4 groups.

However, after calling

model.predict(results, kind="pps")

the posterior_predictive group just spits out predictions, which I cannot separate by the different age groups and zip codes:

Also, the

az.plot_ppc(results)

function does not give me a good view on the 4 groups:

Is there an easy way to see the distributions for the 4 combinations of age groups and zip codes in the data space?

Thanks in advance for any help!

Best regards
Matthias

1 Like

Hi!

You may want to have a look at plot_predictions from the interpret sub-package

In your case, you could run

bmb.interpret.plot_predictions(model, results, ["age_group", "zip_code"]);

See the full example at Plot Conditional Adjusted Predictions – Bambi

2 Likes