Predictions from smooth terms using INLA

187 views
Skip to first unread message

Shauhin Alavi

unread,
Dec 14, 2021, 10:14:08 AM12/14/21
to R-inla discussion group
Hi all,

I'm wondering what is the best way to get posterior predictions from smooth terms using INLA. 

I have the following model, with two terms modeled as splines

  formula.random <-y ~ f(x1, model = "rw1")+f(x2 model = "rw1",hyper=prec.prior)+x3+x4+
    f(ID = "iid",hyper=prec.prior) +
    f(SP, model="iid",hyper=prec.prior) +
    f(M, model="iid",hyper=prec.prior2) #+
 
 
  r.inla.band1 <- inla(formula.random,
                       family ="beta",
                       data=data2,
                       verbose=TRUE,
                       control.compute=list(dic=TRUE, cpo=TRUE, waic=TRUE),
                       control.family=list(link='logit'),
                       control.predictor=list(link=1, compute=TRUE))


The model ran without issue. What I want to do now is calculate the first derivative across each spline and look for areas where a rate of change of 0 is excluded from the credible interval. In other modeling platforms I would make posterior predictions from the spline and use the method of finite differences to calculate the derivative. I'm not sure how to implement this using INLA. 

Any advice is much appreciated! 
Shauhin

Finn Lindgren

unread,
Dec 14, 2021, 10:40:33 AM12/14/21
to Shauhin Alavi, R-inla discussion group
Hi Shauhin,

the rw1 process is non-differentiable, so it would only make sense to do this with e.g. rw2 models, where the derivative is well defined.
Even though the posterior mean might look smooth, the joint distribution reveals that the realisations themselves aren't, and if you were to compute the finite difference "derivative estimate" posteriors you'd see that their variance will go to infinity the shorter the delta-value is.  This is in stark contrast to frequentist penalised spline point estimates, that have more in common with the posterior mean (or mode) than the actual posterior process distributions.

That said, you can use the same approach as in other systems (if you have rw2 models). Likely easiest to use posterior sampling with inla.posterior.sample and calculate the finite differences for each sampled process.

Finn

--
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/348ff4a2-2a1f-4c7a-8045-0add9d6c5645n%40googlegroups.com.


--
Finn Lindgren
email: finn.l...@gmail.com

Tafere Tilahun

unread,
Jan 23, 2023, 5:44:19 AM1/23/23
to R-inla discussion group
Hi Finn

While I was going through some points from the discussion group, I find your comment on finding first derivative estimates of smooth function using inla.posterior.sample and then calculate differences for each sampled process. Could you give us some example with artificial data. 

Regards
Tafere

Reply all
Reply to author
Forward
0 new messages