# Calculating elpd manually for observations with high pareto k diagnostic

**URL:** <https://discourse.mc-stan.org/t/calculating-elpd-manually-for-observations-with-high-pareto-k-diagnostic/25725>\
**Category:** Modeling\
**Tags:** loo\
**Created:** [December 17, 2021, 12:48am UTC](https://discourse.mc-stan.org/t/calculating-elpd-manually-for-observations-with-high-pareto-k-diagnostic/25725 "2021-12-17T00:48:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tagibson](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tagibson](https://discourse.mc-stan.org/u/tagibson)\
**Post date:** [December 17, 2021, 12:48am UTC](https://discourse.mc-stan.org/t/calculating-elpd-manually-for-observations-with-high-pareto-k-diagnostic/25725/1 "2021-12-17T00:48:26Z")

</div>

This is a follow-up post to a previous post: [Using loo\_moment\_matching() with an rjags object](https://discourse.mc-stan.org/t/using-loo-moment-matching-with-an-rjags-object/25698)

Rather than using loo\_moment\_match() as a remedy for high pareto k diagnostics, I want to manually calculate the expected log-predictive density (elpd) for problematic observations. This is because the models are fit in JAGS rather than Stan. I will then combine manually calculated elpd estimates with psis-loo estimates to stack some models.

My question is, do I

1. generate the log-density \log(p(y\_i \vert y\_{-i})) and take the mean, or
2. generate the density p(y\_i \vert y\_{-i}), take its mean as \frac{1}{S}\sum\_{s=1}^S p(y\_i \vert \theta^{(s)}), and then take the log?

I ask because ‘elpd’ sounds like the mean of the log-predictive density, but I have read elsewhere that elpd is instead the log of the mean of the predictive density (which sounds like log-expected predictive density ‘lepd’).

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [December 17, 2021, 6:07pm UTC](https://discourse.mc-stan.org/t/calculating-elpd-manually-for-observations-with-high-pareto-k-diagnostic/25725/2 "2021-12-17T18:07:14Z")

</div>

Does this vignette help [Holdout validation and K-fold cross-validation of Stan programs with the loo package • loo](https://mc-stan.org/loo/articles/loo2-elpd.html) ?

---

<div class="post-metadata">

**Author:** ![tagibson](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tagibson](https://discourse.mc-stan.org/u/tagibson)\
**Post date:** [December 17, 2021, 8:32pm UTC](https://discourse.mc-stan.org/t/calculating-elpd-manually-for-observations-with-high-pareto-k-diagnostic/25725/3 "2021-12-17T20:32:43Z")

</div>

It does! It looks like the answer is (2) in my original post; i.e. calculate the expected predictive density and then take its log. Many thanks!
