Tweedie model error when making predictions with inla.group

259 views
Skip to first unread message

Sylvan Benaksas

unread,
Feb 22, 2022, 11:22:18 AM2/22/22
to R-inla discussion group
Hi all,

Thanks for all the support for the INLA package and it's implementation so far.

I am trying to fit a tweedie model using two rw2 smoothers using inla.group(). I am encountering a similar problem I have seen discussed on this board before with several hundred lines of code reading:

GMRFLib_2order_approx: rescue NAN/INF values in logl

INLA appears to recover and fit the model, however, sometimes there are issues with the eigenvalues.

the main issue comes when I am trying to do model predictions, by fitting a prediction stack. There seems to be an issue with inla.group for the rw2 smoothers in the prediction stack, I get the error even though I have already used inla.group function and no matter how large I make the  inla.group spacing (e.g(n=10) ):

Error in inla.check.location(location[[r]], term = gp$random.spec[[r]]$term,  :
  Locations are too close for f(silt_grp, model="rw2", ...):  min(diff(sort(x)))/diff(range(x)) = 1.764e-04 < 1e-03
  You can fix this by some kind of binning, see ?inla.group

I use the suggested bypass:

If you want/need to bypass this check at your own risk, do
        > m = get("inla.models", inla.get.inlaEnv())
        > m$latent$rw2$min.diff = NULL
        > assign("inla.models", m, inla.get.inlaEnv())


however the out of the model do not make sense and are hundreds of thousands time too larger,

can anyone offer any advice?

much appreciated,
Sylvan

Finn Lindgren

unread,
Feb 22, 2022, 11:32:33 AM2/22/22
to Sylvan Benaksas, R-inla discussion group
inla.group operates directly on a single vector, which doesn't work as intended when applying it separately to the model definition and to prediction values, as they will then likely be misaligned.
Better to be more explicit about how you modify the values, or use a 1d mesh set an explicit resolution and interpolate:
Easiest in inlabru, where it just involves setting mapper=bru_mapper(mesh1d), where mesh1d is created with inla.mesh.1d(knots), where knots are the values you want to use for the model definition (can be sort(unique(inla.group(...))) from the estimation data).
In plain INLA, it's messier, involving building the same 1d mesh, using inla.spde.make.A() to construct A-matrices for estimation and prediction data, and set the inputs to the mesh$loc values for both estimation and prediction.

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/8d519e0b-b24d-4944-a20b-453f9fdacdcfn%40googlegroups.com.


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

Sylvan Benaksas

unread,
Feb 22, 2022, 11:48:07 AM2/22/22
to Finn Lindgren, R-inla discussion group
Hi Finn, thank you for your quick reply,

I Forgot to attach example data and code. Do you think this could be causing the error I am getting. I would have thought if I applied inla.group separately to the estimation stack and prediction stack they would be independent?

I have not used inlabru, do you have a link how to fit the 1d mesh as you have said with plain inla?

best wishes,
Sylvan
Tweedie.zip

Finn Lindgren

unread,
Feb 22, 2022, 11:59:24 AM2/22/22
to Sylvan Benaksas, R-inla discussion group
Applying inla.group independently is the likely problem; the aim of inla.group is to discretise the input to a given resolution. If you apply it separately to different parts of the input, there will be no relationship between them, and the whole purpose is lost.

I don't have example code at hand for the plain inla version of running rw2 with an 1d mesh, sorry; inlabru exists partly to avoid having to deal with inla.stack in user-side code, so that's where my effort goes; it's not complicated mathematically to do it; the description I gave includes all the needed steps:
" building the same 1d mesh, using inla.spde.make.A() to construct A-matrices for estimation and prediction data, and set the inputs to the mesh$loc values for both estimation and prediction."

Finn

Sylvan Benaksas

unread,
Feb 24, 2022, 6:35:00 AM2/24/22
to Finn Lindgren, R-inla discussion group
Hi Finn,

Thanks again for the help. I see now the problem with inla.group. Because the covariate data was the same range for estimation and prediction stacks I managed a "hack" by applying inla.group to the estimation stack, and then taking the intervals and subset points and applying them to the prediction stack covariate data. 

However, the issue persists even when I remove rw2 smoothers from the INLa model, there is some issue or mistake I am making while predicting with a tweedie inla model so that the prediction outputs do not make sense (thousands of times too large) while the estimation fitting looks as is should. 

can anyone offer any advice on this, I have attached example script and code

Many thanks,

Sylvan
Tweedie.zip

Sylvan Benaksas

unread,
Aug 4, 2022, 11:08:29 AM8/4/22
to R-inla discussion group
Hi Finn,

I have recently returned to this issue and I am trying the 1d spde mesh as you said. However, the covariate I am building the mesh for has some NA values but these seem to be unacceptable for the inla.mesh.1d function?

Cheers,
Sylvan

Finn Lindgren

unread,
Aug 4, 2022, 2:55:20 PM8/4/22
to Sylvan Benaksas, R-inla discussion group
Yes, you can't have missing values in your covariate.
Finn

Reply all
Reply to author
Forward
0 new messages