Duplicate spatial random effects for BYM models?

18 views
Skip to first unread message

jacopo cerri

unread,
Oct 1, 2025, 6:10:16 AM (3 days ago) Oct 1
to R-inla discussion group
Hi you all,

I am fitting a model accounting for spatial correlation, and some spatio-temporal correlations according to Blangiardo and Cameletti (2015) and Zuur and Ieno (2017), which in turn relied on Knorr-Held (2000).
The scope of my model is to predict changes in hunting bags of deer across 234 hunting districts, over 18 years.
The model I selected with CPOs, DIC and WAIC basically has a BYM correlation structure, plus a type III interaction between space and time, allowing for year-specific correlations in hunting bags between neighboring districts, which however do not have any consistent temporal pattern.
Find below the formula, where "year", "year1" and "year2" are years, from 1 to 18 and hg.num is the number of each of the 234 hunting districts:

```
mod <- inla(formula = value ~
                      f(hg.name.num,
                        model = "bym", graph = g,
                        hyper = HyperBYM,
                        adjust.for.con.comp = TRUE,
                        constr = TRUE,
                        scale.model = TRUE) +
                      f(year, model = "rw2", constr = TRUE, scale.model = TRUE) +
                      f(year1, model = "iid") +
                      f(year2, model = "iid", group = hg.name.num1, control.group = list(model =
                         "besag", graph = g)),
                    family = 'zeroinflatednbinomial1',
                    data = roe.df,
                    control.predictor = list(compute = TRUE),
                    control.compute = list(dic = TRUE, waic = TRUE,
                                           cpo = TRUE, #Cross validation values
                                           return.marginals.predictor = TRUE,
                                           config = TRUE), 
                    control.inla = list(cmin = 0),
                    control.family = list(hyper = hypNB))
```
The model looks reasonable, however I would like to plot spatial random effects, or the percentage change in my response due to the structures spatial effect. So, following Zuur and Ieno (2017), I calculated them as:

```
100 * (exp(mod$summary.random$hg.name.num$mean) - 1)
```

The problem is that I obtain 468 values, or basically duplicates of the 234 hunting grounds. I am not sure why this is happening, however if I plotted the first 234 values and values from 235 to 468 these are quite correlated.

Screenshot from 2025-10-01 11-28-10.png

It seems that my model is estimating two types of spatial random effects for each one of my 234 hunting districts.

Do you have any idea on why this might be happening?

Jacopo Cerri
Mammal Research Institute
Polish Academy of Sciences


Helpdesk (Haavard Rue)

unread,
Oct 2, 2025, 6:33:42 AM (yesterday) Oct 2
to jacopo cerri, R-inla discussion group

If you check the documentation

inla.doc("bym")

then you see that internally the model is expanded into a model with size 2*n,
n=size of the graph, and the quantity you're interested in, spatial+iid, is in
index 1:n.

A better option is to use 'bym2' instead of 'bym', as its a better
paramneterisation and priors and do scaling automatically

best
havard
> Screenshot from 2025-10-01 11-28-10.png
>
> It seems that my model is estimating two types of spatial random effects for
> each one of my 234 hunting districts.
>
> Do you have any idea on why this might be happening?
>
> Jacopo Cerri
> Mammal Research Institute
> Polish Academy of Sciences
>
>
> --
> 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/2861002b-452d-49ba-b9c8-e12c417aa401n%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org
Reply all
Reply to author
Forward
0 new messages