# "log\_likelihood" not found in InferenceData

**URL:** <https://discourse.pymc.io/t/log-likelihood-not-found-in-inferencedata/8169>\
**Category:** Questions\
**Created:** [October 13, 2021, 8:18pm UTC](https://discourse.pymc.io/t/log-likelihood-not-found-in-inferencedata/8169 "2021-10-13T20:18:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [October 15, 2021, 4:31pm UTC](https://discourse.pymc.io/t/log-likelihood-not-found-in-inferencedata/8169/3 "2021-10-15T16:31:53Z")

</div>

which versions of pymc and arviz are you using?

> [@karthur](#):
>
> The [arviz documentation](https://arviz-devs.github.io/arviz/user_guide/pymc3_refitting_xr_lik.html) suggests that PyMC3 should be storing a log-likelihood with the InferenceData when “log\_likelihood = True” is one of the `idata\_kwargs.

Yes, when converting to InferenceData the log likelihood data is automatically computed and included in the resulting InferenceData _if possible_. I think there should be a warning printed if that fails, but I might be wrong. You can see that this works in most of the example notebooks, for example: [https://pymc-examples.readthedocs.io/en/latest/diagnostics\_and\_criticism/model\_comparison.html](https://pymc-examples.readthedocs.io/en/latest/diagnostics_and_criticism/model_comparison.html)

That being the default also means that using `idata_kwargs={"log_likelihood": True}` is equivalent to not using any arguments.

> [@karthur](#):
>
> So, thankfully, there is a way to:
> 
> - [Save the model log-likelihood during sampling](https://discourse.pymc.io/t/frequently-asked-questions/74/7), explicitly, using `pm.Deterministic` ;
> - [Recover the model log-likelihood after sampling](https://stackoverflow.com/questions/45548275/how-to-evaluate-the-log-posterior-in-pymc3);

If either of these options has worked, then it seems like the auto conversion should work too, _provided you have relatively new versions of both pymc and arviz_. If so, could you share a minimal example in which it fails?

> [@karthur](#):
>
> From the PyMC3 trunk, it’s apparent that:
> 
> - [`to_inference_data()` doesn’t take any keyword arguments…](https://github.com/pymc-devs/pymc/blob/9dcd216a64e50081a59b041b7f752dcfd68a40b7/pymc/backends/arviz.py#L510)
> - […and, yet, it is called with `idata_kwargs` anyway.](https://github.com/pymc-devs/pymc/blob/595e1643f035943c6ee91958716ceba627b7813c/pymc/sampling.py#L642)

Here you are wrong, which is not strange given the actual change and large updates happening to the codebase as version 4.x approaches.

The `to_inference_data` you mention is a method of the converter class, not a function. The function that is actually called from the `sample` method in the 2nd link you provided is a few lines below that. And it does have keyword arguments. However, those are only used for \>=4 versions, which you’ll only have if you have installed from github as it has not been released yet. You can also see how in the methods above there is code similar to the answers you shared above that automatically store pointwise log likelihood values.

If you are using pymc3 installed from pip or from conda, the conversion is then being done with an ArviZ function instead of with this one, which is why you originally found that info in the ArviZ docs. Both are similar and both store log likelihood by default, but there are some important differences.

---

_[View the full topic](https://discourse.pymc.io/t/log-likelihood-not-found-in-inferencedata/8169)._
