Hi Friends,
I am trying to fix several models with Bambi and then compare them with Arviz.compare function. I have seen lots of examples of using az.compare directly with PyMC, but none with Bambi. Unfortunately, it does not work as expected with Bambi:
“TypeError: log likelihood not found in inference data object”
I found this thread, which looks like it might apply. I tried to follow that thread, but ran into trouble and I wasn’t even sure I was on the right track.
Here is a minimal example. The Bambi models fit fine, but then az.compare fails. What am I missing???
My versions are:
My error is:
My code is:
import numpy as np
import pandas as pd
import arviz as az
import bambi as bmb
import pymc as pm
import sys
sys.version
az.__version__
bmb.__version__
pm.__version__
penguins = pd.read_csv("../data/penguins.csv")
missing_data = penguins.isnull()[
["bill_length_mm", "flipper_length_mm", "sex", "body_mass_g"]
].any(axis=1)
penguins = penguins.loc[~missing_data].reset_index(drop=True)
print(penguins.shape)
penguins.sample(5)
species_model = bmb.Model("body_mass_g ~ 0 + species", penguins)
species_model.build()
species_model_results = species_model.fit()
species_model.predict(species_model_results, kind='pps', inplace=True)
species_model_results
species_one_covariate_model = bmb.Model("body_mass_g ~ 0 + species + flipper_length_mm", penguins)
species_one_covariate_model.build()
species_one_covariate_results = species_one_covariate_model.fit()
species_one_covariate_model.predict(species_one_covariate_results, kind='pps', inplace=True)
species_one_covariate_results
compare_dict = {
'model_one':species_model_results,
'model_two':species_one_covariate_results
}
compare_dict
az.compare(compare_dict)