Error in inla.check.location, Locations are too close

464 views
Skip to first unread message

eby

unread,
Aug 10, 2018, 7:15:23 AM8/10/18
to R-inla discussion group
Dear INLA users,

I am trying to fit an additive regression model (using the reproducible example below)

y_i ~ Poisson(mu_i), where mu_i = exp(alpha), alpha = {f1(x1) + f2(x2) + f3(x3)}/6
 
but gets the following error

Error in inla.check.location(location[[r]], term = gp$random.spec[[r]]$term,  :
  Locations are too close for f(x1, model="rw2", ...):  min(diff(sort(x)))/diff(range(x)) = 7.453e-09 < 1e-03
  You can fix this by some kind of binning, see ?inla.group
  If you want/need to bypass this check at your own risk, do
    > m = get("inla.models", INLA:::inla.get.inlaEnv())
    > m$latent$rw2$min.diff = NULL
    > assign("inla.models", m, INLA:::inla.get.inlaEnv())

The same error occurs also for exponential and binary distributions, and also if I try any of the predictors x1, x2 or x3. I've tried the code anyway by bypassing the check, it kept running all night long and I had to stop it after 10 hours (such simple models and sizes of data shouldn't take so long). Any idea whether it is a bug or numerical instabilities came into play?

PS: other libraries were able to fit the same models and data.

Many thanks!



Reproducible example

library(INLA)

## smooth functions
f1 <- function(x){ return(0.2 * x^11 * (10 * (1 - x))^6 + 10 * (10 * x)^3 * (1 - x)^10) }
f2 <- function(x){ return(2 * sin(pi * x)) }
f3 <- function(x){ return(exp(2*x)) }

n <- 1e+04
x1 <- runif(n)
x2 <- runif(n)
x3 <- runif(n)
dat <- data.frame(x1, x2, x3)
mu <- exp( (f1(dat$x1) + f2(dat$x2) + f3(dat$x3))/6)
dat$y <- rpois(n, mu)
#dat$y <- rexp(n, mu)
#mu <- binomial()$linkinv( (f1(dat$x1) + f2(dat$x2) + f3(dat$x3) -5)/6)
#dat$y <- rbinom(n, 1, mu)

fINLA <- inla( y ~ f(x1, model="rw2") + f(x2, model="rw2") + f(x3, model="rw2"),
              data=dat,
              verbose=FALSE,
              family="poisson",
              #family="exponential",
              #family="binomial", Ntrials=n,
              num.threads=4,
              control.predictor=list(compute=TRUE),
              control.compute = list(config=TRUE)
)

Finn Lindgren

unread,
Aug 10, 2018, 7:44:49 AM8/10/18
to eby, R-inla discussion group
As the error says, some of the values are tightly clustered. The gives unstable numerics, and also likely a much much larger model than needed, since each distinct value becomes a node in the model.
Have you tried the suggested inla.group method?

(Inla.group isn’t my favorite way to deal with this, but it’s the easiest...)

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 post to this group, send email to r-inla-disc...@googlegroups.com.
Visit this group at https://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.

Yousra El Bachir

unread,
Aug 10, 2018, 8:53:21 AM8/10/18
to Finn Lindgren, R-inla discussion group
It worked with inla.group(). Thank you!

To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsubscr...@googlegroups.com.
To post to this group, send email to r-inla-discussion-group@googlegroups.com.

Clément Lopez

unread,
May 2, 2020, 10:03:50 AM5/2/20
to R-inla discussion group
Hi,

I have the same problem as you before. I see that you were able to solve it.
Could you provide the changes added to your code using inla.group, please?

Thanls in advance.

Regards,
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.
To post to this group, send email to r-inla-disc...@googlegroups.com.

Helpdesk

unread,
May 2, 2020, 11:50:55 AM5/2/20
to Clément Lopez, R-inla discussion group
see ?inla.group for further options.

replace f(x,model="rw2",...) f.ex, with
f(inla.group(x),model="rw2",...)

use scale.model=TRUE

its due to values of x that is to close to each other creating unstable
numerics.

you can bypass this test as described in the error message if you think
it will go fine still

H
Håvard Rue
Helpdesk
he...@r-inla.org

Clément Lopez

unread,
May 5, 2020, 4:58:40 AM5/5/20
to R-inla discussion group
It worked.

Thank you very much for your help.

Yalda

unread,
Aug 12, 2024, 1:25:31 PM8/12/24
to R-inla discussion group
Hello,

I hope you are well.

I had a question about your comment -  (Inla.group isn’t my favorite way to deal with this, but it’s the easiest...) - what other ways do you recommend dealing with this issue?

Many thanks,
Yalda

Finn Lindgren

unread,
Aug 12, 2024, 3:34:31 PM8/12/24
to Yalda, R-inla discussion group
Hi,
The question&answer you’re replying to are now very old, so I won’t try to answer in that specific context, but nowadays I would specify models with the help of interpolating or smoothing mappers in inlabru. E.g. for rw1 model, by specifying what values the model should be explicitly defined for as knots in a piecewise linear spline from fm_mesh_1d(), which then leads to linear interpolation between those knots. This is similar to the _effect_ of using inla.group, but with interpolation instead of rounding, and with more precise control over the model definition.

(One _can_ also do the above in plain inla() with A-matrices and inla.stack(), but inlabru exists partly so the need for explaining such complex user-side code can be eliminated.)

Finn

On 12 Aug 2024, at 18:25, Yalda <yjaf...@gmail.com> wrote:

Hello,
Reply all
Reply to author
Forward
0 new messages