Calculating the Posterior Predictive Density

356 views
Skip to first unread message

Noah Silverman

unread,
Sep 14, 2022, 12:14:19 AM9/14/22
to R-inla discussion group
As noted in my previous posts, I'm looking for ways to evaluate goodness-of-fit for out-of-sample testing data.

The CPO and PIT are great, but impossible to evaluate for NA values in INLA.

Reading through an old paper "Posterior and Cross-validatory Predictive Checks: A Comparison of MCMC and INLA", the authors discuss model criticism and comparison.

On page 94 (5th page of actual PDF), the authors describe the Posterior Predictive Density.

Screen Shot 2022-09-14 at 12.06.32.png

Intuitively this makes sense.  Instead of just comparing the center of predicted values to the observed values, we can compare at the entire predictive distribution to the observed value.

However, I'm a bit stuck on  how to actually calculate this in R. 

I can't figure out how to calculate the first term of the left hand side
Screen Shot 2022-09-14 at 12.08.52.png

The dnorm() command in R requires both a mean and standard deviation.  INLA supplies 48 points from the marginal fitted distribution.  How do I calculate the above values with those points? 

Alternately:  Perhaps I'm going about this the "long way", when there may be existing tools or function in R.  Any suggestions would be very welcome.


Thank You,






Helpdesk (Haavard Rue)

unread,
Sep 14, 2022, 3:08:16 AM9/14/22
to Noah Silverman, R-inla discussion group
this

\pi( y_i | y)

is 'po' and is computed if you request it.

> r=inla(y ~ 1, data=data.frame(y=1:2), control.compute=list(po=TRUE))
> r$po$po
[1] 0.4086249594 0.4086249594



On Tue, 2022-09-13 at 21:14 -0700, Noah Silverman wrote:
> As noted in my previous posts, I'm looking for ways to evaluate
> goodness-of-fit for out-of-sample testing data.
>
> The CPO and PIT are great, but impossible to evaluate for NA values in
> INLA.
>
> Reading through an old paper "Posterior and Cross-validatory
> Predictive Checks: A Comparison of MCMC and INLA", the authors discuss
> model criticism and comparison.
>
> On page 94 (5th page of actual PDF), the authors describe the
> Posterior Predictive Density.
>
> Screen Shot 2022-09-14 at 12.06.32.png
>
> Intuitively this makes sense.  Instead of just comparing the center of
> predicted values to the observed values, we can compare at the entire
> predictive distribution to the observed value.
>
> However, I'm a bit stuck on  how to actually calculate this in R. 
>
> I can't figure out how to calculate the first term of the left hand
> side
> Screen Shot 2022-09-14 at 12.08.52.png
>
> The dnorm() command in R requires both a mean and standard deviation. 
> INLA supplies 48 points from the marginal fitted distribution.  How do
> I calculate the above values with those points? 
>
> Alternately:  Perhaps I'm going about this the "long way", when there
> may be existing tools or function in R.  Any suggestions would be very
> welcome.
>
>
> Thank You,
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "R-inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to r-inla-discussion...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/49d33947-413e-487a-a6f1-67e181f0eb10n%40googlegroups.com
> .

Noah Silverman

unread,
Sep 14, 2022, 6:55:14 AM9/14/22
to R-inla discussion group
Thank You!

Is this the same as inla.dmarginal(y_i,  m1$marginals.fitted.values[[i]]) ??

Helpdesk (Haavard Rue)

unread,
Sep 14, 2022, 10:15:02 AM9/14/22
to Noah Silverman, R-inla discussion group

Noah Silverman

unread,
Sep 14, 2022, 12:26:29 PM9/14/22
to R-inla discussion group
Got it.  Thank you so much!

Out of curiousity, is that a simple function somewhere in the INLA code?  Might help me a bit to see how it is actually constructed.

Thanks!!!

Helpdesk (Haavard Rue)

unread,
Sep 14, 2022, 12:51:43 PM9/14/22
to Noah Silverman, R-inla discussion group

this part is done in C. you can also use the 'posterior.sample' apprach
as suggested by Finn; see the post 'CPO and PIT for predictions'
> https://groups.google.com/d/msgid/r-inla-discussion-group/1abcd89d-aeed-4b51-8543-984d19c08030n%40googlegroups.com
> .

Reply all
Reply to author
Forward
0 new messages