inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

SPDE coordinate issue #48

Closed davidbolin closed 3 years ago

davidbolin commented 5 years ago

The code below gives the following error, which seems to be caused by the name "s" for the coordinates.

Error in (function (data, model, stackmaker, n = 10, result = NULL, family, : INLA returned message: object 'pde2' not found In addition: Warning message: In INLA::f(field, model = pde2) : object 'pde2' not found

library(inlabru) seed <- 1 obs.loc <- 10 * cbind(runif(100), runif(100)) Y <- as.vector(rnorm(100)) df <- data.frame(Y=Y,x=obs.loc) x <- seq(from = 0, to = 10, length.out = 30) mesh <- inla.mesh.create(lattice = inla.mesh.lattice(x = x, y = x), extend = FALSE, refine = FALSE) spde2 <- inla.spde2.pcmatern(mesh, prior.range=c(1, 0.01), prior.sigma=c(10, 0.01))

comp <- Y ~ field(map = s, model = spde2) + Intercept

fit <- bru(comp, df, family = "gaussian")

finnlindgren commented 3 years ago

This has been fixed at some point in the past. The syntax has also changed slightly (map is now main, and doesn't need to be named). Modified code below now tends to crash INLA instead, due to the flat field leading to large range and tiny variance, and non-positive-definit precision.

library(inlabru)
seed <- 1
obs.loc <- 10 * cbind(runif(100), runif(100))
Y <- as.vector(rnorm(100))
df <- data.frame(Y = Y, x = obs.loc)
x <- seq(from = 0, to = 10, length.out = 20)
mesh <- INLA::inla.mesh.create(
  lattice = INLA::inla.mesh.lattice(x = x, y = x),
  extend = FALSE,
  refine = FALSE
)
spde2 <- INLA::inla.spde2.pcmatern(
  mesh,
  prior.range = c(1, 0.01),
  prior.sigma = c(10, 0.01)
)

comp <- Y ~ field(s, model = spde2) + Intercept(1)

fit <- bru(comp, data = df, family = "gaussian")