Missing observed varialbe in posterior_predictive

I have a model with two observed varialbes, Fz_obs and RPM_obs. After sampling the model, I try to run posterior predictive checks as follows

with Fz_model:

However, when I run this, I get the following error message

KeyError                                  Traceback (most recent call last)
File ~/.cache/pypoetry/virtualenvs/tool-insight-HtaDeJzl-py3.10/lib/python3.10/site-packages/arviz/utils.py:71, in _var_names(var_names, data, filter_vars)
     70 try:
---> 71     var_names = _subset_list(var_names, all_vars, filter_items=filter_vars, warn=False)
     72 except KeyError as err:

File ~/.cache/pypoetry/virtualenvs/tool-insight-HtaDeJzl-py3.10/lib/python3.10/site-packages/arviz/utils.py:149, in _subset_list(subset, whole_list, filter_items, warn)
    148     if not np.all(existing_items):
--> 149         raise KeyError(f"{np.array(subset)[~existing_items]} are not present")
    151 return subset

KeyError: "['RPM_obs'] are not present"

Examining the posterior_predictive section of idata, it does indeed appear that the posterior predictive distribution has only been generated for Fz_obs and not for RPM_obs. Why has this happened and what can I do about it?

Answering my own question here. Restarting the notebook and rerunning has solved the problem. I had copied and pasted a lot of code from another notebook, so that cell originally read var_names='['Fz_obs'], I must have run it before adding RPM_obs to the option, and subsequent invocations with a corrected option did not overwrite the existing posterior_predictive.

1 Like