PIPELINE FOR BUILD BARRIER INLA MODELS - PROBLEMS WITH COMPUTING BARRIERS

13 views
Skip to first unread message

Lola Riesgo Torres

unread,
Dec 23, 2025, 7:51:34 AM (yesterday) Dec 23
to R-inla discussion group

Hi everyone,
I am trying to build a spatial model accounting for barriers. However, I do not fully understand the pipeline (workflow) we are supposed to follow. I have only found three available tutorials on implementing a barrier model, but I am confused about why they differ. The tutorials are:

  1. https://eliaskrainski.github.io/INLAspacetime/articles/web/barrierExample.html#abstract

  2. https://haakonbakkagit.github.io/btopic128.html#6_Implementation_(Models) (obsolete)

  3. https://becarioprecario.bitbucket.io/spde-gitbook/ch-nonstationarity.html#ch:barrier

What I don’t understand is how they create the s.index after defining the SPDE. In a model without barriers, the steps are:

A) Define the mesh
B) Define the SPDE (inla.spde2.pcmatern) and create the s-index (inla.spde.make.index)

spde <- inla.spde2.pcmatern(mesh, prior.range = c(1, 0.01), prior.sigma = c(1, 0.01))
s.index <- inla.spde.make.index(name = "spatial.field", n.spde = spde$n.spde)
C) Define the projection matrix A (inla.spde.make.A)
D) Define the stack (here you introduce the s.index)  
For example:
stack.1 <- inla.stack(
  data   = list(y = df$pres),
  A      = list(A, 1),
  effects = list(
    s.index,  
    df %>% transmute(
      intercept = 1,
      temp_s, time, bathy_s, length_cm_s
    )
  ),
  tag = "fit"
)
E) Define the formula and fit the model  
For example: 
f.1 <- y ~ -1 +intercept + bathy_s + temp_s + f(spatial.field, model = spde)

mod.1 <- inla(
  f.1,
  data              = inla.stack.data(stack.1),
  family            = "binomial",
  control.predictor = list(
    A       = inla.stack.A(stack.1),
    compute = TRUE
  ),
  control.compute   = list(dic = TRUE, waic = TRUE, cpo = TRUE),
  verbose           = TRUE
)

However, in the barrier model the workflow seems different. In the tutorials, they do not define a s.index. The workflow is:

A) Define the mesh accounting for the boundary (water polygon)
B) Identify the triangles inside the polygon (fmesher::fm_contains)
C) Create a SPDE with the barrier (inla.barrier.pcmatern) – here no s.index is define

For example: 

water.tri <- fmesher::fm_contains(
  ocean_poly,
  y = mesh,
  type = "centroid"
)

water.tri.idx <- water.tri[[1]]
length(water.tri.idx)  
num.tri <- nrow(mesh$graph$tv)
barrier.tri <- setdiff(1:num.tri, water.tri.idx)

poly.barrier <- inla.barrier.polygon(
  mesh,
  barrier.triangles = barrier.tri
)

spde_barrier <- inla.barrier.pcmatern(
  mesh = mesh,
  barrier.triangles = barrier.tri,
  prior.range = c(100000, 0.5),
  prior.sigma = c(1, 0.01)
)

D) Build the projection matrix A
E) Define the stack – where in the previous method you have s.index, here the code uses s = 1:mesh$n. For example:

stack.1 <- inla.stack(
  data   = list(y = df$presence),
  A      = list(A, 1),
  effects = list(
    s= 1:mesh$n,  
    df %>% transmute(
      intercept = 1,
      Depth_s, BotTemp_s, year_f, mean_len_s
    )
  ),
  tag = "fit"
)

F) Define the formula and fit the model with INLA

The problem is that when I apply this workflow, the spatial effect does not seem to be used. My question is: do I need to define SPDE indices (s.index) in a barrier model? If not, why does INLA not seem to include the spatial effect?  

Thank you so much for the information and help. 

Kind regards, 

Lola R


Elias T. Krainski

unread,
Dec 23, 2025, 8:56:59 AM (yesterday) Dec 23
to R-inla discussion group
Dear Lola, 

The first link uses the current recommended implementation, while the others use an old one. Additionally, it uses inlabru, which is why the 's.index' creation is not necessary, as the interface with inla has become easier. 

Best regards, 
Elias

--
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, visit https://groups.google.com/d/msgid/r-inla-discussion-group/ca27513e-678a-4629-aeab-46ab1179b8afn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages