Error with BYM2 in inlabru marked LGCP

22 views
Skip to first unread message

Morgane Declerck

unread,
May 4, 2026, 10:50:33 AM (9 days ago) May 4
to R-inla discussion group

Dear INLA Discussion Group,

I am fitting a marked LGCP using inlabru + INLA (Cox process + binomial mark model).

The model runs successfully when using a cyclic generic0 effect for tide-varying slopes (based on a custom precision matrix). However, when I replace this with a BYM2 model, the fit fails with the following error:

*** Please (re-)consider your model, priors, confounding, etc.

***[0] thread_num[0] warning *** iterative process seems to diverge, 'vb.correction' is aborted
(repeated several times)

Error in `data.frame()`:
! arguments imply differing number of rows: 1, 0

Backtrace:
base::system.time(...)
inlabru::bru(...)
inlabru::iinla(...)
base::data.frame(...)

Model setup: BYM2 version that fails  

# ============================================================
# 6) BYM2 CYCLIC TIDE GRAPH
# ============================================================
# Tide groups are treated as cyclic neighbours:
#   1 -- 2 -- 3 -- 4 -- 1
make_tide_graph <- function() {
  graph_file <- tempfile(fileext = ".adj")

  cat(
    "4\n",
    "1 2 2 4\n",
    "2 2 1 3\n",
    "3 2 2 4\n",
    "4 2 3 1\n",
    file = graph_file,
    sep = ""
  )

  INLA::inla.read.graph(graph_file)
}
tide_graph <- make_tide_graph()

# ------------------------------------------------------------
# Outer boundary (km units)
# ------------------------------------------------------------
outer_boundary <- fm_nonconvex_hull(domain_km2, 40)

# ------------------------------------------------------------
# HEXAGONAL LATTICE MESH
# ------------------------------------------------------------
mesh <- fm_mesh_2d_inla(
  loc = fm_hexagon_lattice(domain_km2, edge_len = 80),
  boundary = list(domain_km2, outer_boundary),
  max.edge = c(90, 150),
  cutoff   = 70,
  crs      = crs_km
)

spde <- inla.spde2.pcmatern(mesh = mesh,
  prior.range = c(150, 0.5),
  prior.sigma = c(1, 0.05)
)

cmp <- ~ -1 +
  point_field(geometry, model = spde) +

  log_PEA(
    tide_group_id,log_PEA_z,model = "bym2",
    graph = tide_graph,
    scale.model = TRUE,
    constr = TRUE
  ) +

  log_surface_chla(tide_group_id, log_surface_chla_z,
    model = "bym2",
    graph = tide_graph,
    scale.model = TRUE,
    constr = TRUE
  ) +

  sst_effect(tide_group_id,sst_z,
    model = "bym2",
    graph = tide_graph,
    scale.model = TRUE,
    constr = TRUE
  ) +

  sal_effect(tide_group_id,sal_depth_int_z,
    model = "bym2",
    graph = tide_graph,
    scale.model = TRUE,
    constr = TRUE
  ) +
  Inter_point(1) +
  Inter_mark(1) +

  beta_link(
    main = 1,
    model = "linear",
    mean.linear = 0,
    prec.linear = 1,
    n = 1,
    values = 1
  ) +

  log_dist_col_m_z + indiv(UniqueID, model = "iid") +

  mark_field_tide(geometry, model = spde, replicate = tide_group_id)

obs_points <- bru_obs(geometry ~ Inter_point + point_field,
  family   = "cp",
  data     = gan_km,
  domain   = list(geometry = mesh),
  samplers = list(geometry = domain_km2),
  tag      = "points"
)

mark_formula <- mark ~
  Inter_mark + log_PEA +log_surface_chla +sst_effect +sal_effect +log_dist_col_m_z + indiv +
  point_field * beta_link +
  mark_field_tide

obs_marks <- bru_obs(mark_formula,family = "binomial",data   = gan_km,tag    = "marks")


  fit <- bru(
    components = cmp,obs_points, obs_marks,
    options = list(
      control.compute = list(
        dic = TRUE,
        waic = TRUE,
        cpo = TRUE,
        config = FALSE
      ),
      control.predictor = list(compute = TRUE),
      control.inla = list(
        strategy = "simplified.laplace",
        int.strategy = "auto"
      ),
      bru_verbose = TRUE
    )
  )

Any guidance on how to resolve this error would be greatly appreciated.

The variable tide_group_id has 4 levels with cyclic adjacency (1–2–3–4–1).

Is BYM2 appropriate for such a small graph (4 nodes)?
Would generic0 be more suitable for cyclic effects with few levels?

Thank you in advance for any help.

Morgane

Helpdesk (Haavard Rue)

unread,
May 4, 2026, 10:59:07 AM (9 days ago) May 4
to Morgane Declerck, R-inla discussion group

do you have a copy of data as well that can be checked against ?
> --
> 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/CACHvASYkKm4_K8mZWBiELB19sGcoOWSsAh2%3D%2BO%2BUQ%2B-v7rxaTw%40mail.gmail.com
> .

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

Finn Lindgren

unread,
May 4, 2026, 11:44:56 AM (9 days ago) May 4
to Morgane Declerck, R-inla discussion group
The traceback() reveals that there may also be an error triggered by the inlabru interface; we'll need test data that reproduces the issue to investigate.
This may just be a side-effect of a problem noticed by inla(), but in that case inlabru should be able to exit more cleanly.

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, visit https://groups.google.com/d/msgid/r-inla-discussion-group/CACHvASYkKm4_K8mZWBiELB19sGcoOWSsAh2%3D%2BO%2BUQ%2B-v7rxaTw%40mail.gmail.com.


--
Finn Lindgren
email: finn.l...@gmail.com
Reply all
Reply to author
Forward
0 new messages