fbesag
A non-stationary spatial model: neighbours can be more alike in one part of the map than in another.
Idea
Each area is pulled towards its neighbours. How strongly is set by a precision $\tau_k$ that differs between sub-regions: high where the map is smooth, low where it is rough. With one sub-region the precision is the same everywhere (the Besag model), so comparing the two tests whether the map is non-stationary. When the sub-regions do not differ, the estimates are the same as with one precision (see the check).
Sub-regions are chosen before seeing the data. They need not be contiguous, and the graph can be a time line.
Model
where $k(i)$ is the sub-region of area $i$. The structure is scaled so that, with all $\tau_k = 1$, the geometric mean of the marginal variances is 1 (Sørbye and Rue, 2014), with a sum-to-zero constraint per connected part of two or more areas. pyinla reports $\theta_k = \log\tau_k$ as Theta1, …, ThetaP.
Prior
A PC prior (Simpson et al., 2017) on the common level $\bar\theta$, and a normal prior on the deviations $\gamma_k$. As $\sigma_\gamma \to 0$, all $\tau_k$ become equal.
| argument | default | meaning |
|---|---|---|
param | {'p1': 1, 'p2': 1e-5} | $P(\text{common sd} > 1) = 10^{-5}$ |
sd_gamma | 0.2 | with five sub-regions, each $\tau_k$ within a factor of about 1.4 of the common level (two sd); with 1, about 6 |
Example: dengue in Brazil
Dengue cases in April in the 558 microregions of Brazil (Lowe et al., 2021), with the five regions as sub-regions. Data: brazil_558_microregions.csv, brazil_558_microregions.graph, brazil_558_microregions.geojson.


import numpy as np
import pandas as pd
from pyinla import pyinla
from pyinla.gmrfs import fbesag
areas = pd.read_csv("brazil_558_microregions.csv") # idx, region, Y and E of April
graph = "brazil_558_microregions.graph"
region = areas["region_code"].to_numpy() # 1 North, 2 Northeast, 3 Southeast, 4 South, 5 Centre-West
m_besag = fbesag("idx", graph, np.ones(558, int)) # one precision: besag
m_regions = fbesag("idx", graph, region) # one precision per region
def fit(m):
return pyinla(model={"response": "Y", "fixed": ["1"], "random": [m]},
family="poisson", data=areas, E=areas["E"].to_numpy())
fit_besag, fit_regions = fit(m_besag), fit(m_regions)
print(fit_regions.summary_hyperpar[["mean", "0.025quant", "0.975quant"]].round(2))
print(fit_regions.mlik.iloc[1] - fit_besag.mlik.iloc[1]) # log Bayes factor for the regions
mean 0.025quant 0.975quant
Theta1 for idx -1.06 -1.38 -0.75
Theta2 for idx -1.08 -1.28 -0.88
Theta3 for idx -1.66 -1.87 -1.46
Theta4 for idx -1.12 -1.47 -0.77
Theta5 for idx -1.02 -1.35 -0.70
10.60895681735974

The Southeast is rougher than the other regions.
Precision of each area
import geopandas as gpd
tau = np.exp(fit_regions.summary_hyperpar["mean"].to_numpy())[region - 1] # tau of each area's region
lines = open(graph).read().split("\n")[1:559]
nbs = [np.array(line.split()[2:], dtype=int) - 1 for line in lines] # the neighbours, 0-based
n_i = np.array([len(nb) for nb in nbs])
map_df = gpd.read_file("brazil_558_microregions.geojson").sort_values("idx").reset_index(drop=True)
map_df["log_tau"] = np.log((n_i * tau + np.array([tau[nb].sum() for nb in nbs])) / (2 * n_i))
map_df.plot("log_tau", linewidth=0, legend=True)

Maps
from matplotlib.colors import ListedColormap
x_regions = fit_regions.summary_random["idx"]["mean"].to_numpy()
x_besag = fit_besag.summary_random["idx"]["mean"].to_numpy()
# observed over expected, relative to the whole country
map_df["smr"] = (areas["Y"] / areas["E"]) / (areas["Y"].sum() / areas["E"].sum())
map_df["rr"] = np.exp(x_regions)
map_df["diff"] = x_regions - x_besag
brks = [0, 0.2, 0.5, 1, 2, 5, np.inf]
cols = ListedColormap(["#2c7bb6", "#abd9e9", "#e0f3f8", "#fee090", "#fdae61", "#d7191c"])
map_df.assign(rr=pd.cut(map_df["rr"], brks, right=False)).plot("rr", cmap=cols, linewidth=0, legend=True)
lim = map_df["diff"].abs().max()
map_df.plot("diff", cmap="RdBu_r", vmin=-lim, vmax=lim, linewidth=0, legend=True)
# the largest difference in each region
region_names = ["North", "Northeast", "Southeast", "South", "Centre-West"]
print(map_df["diff"].abs().groupby(region).max().set_axis(region_names).round(2).to_string())
North 0.22
Northeast 0.18
Southeast 0.31
South 0.29
Centre-West 0.13


Testing for non-stationarity
Compare with fbesag with one sub-region, not besag, whose default prior is different.
| $\sigma_\gamma = 0.2$ | $\sigma_\gamma = 1$ | |
|---|---|---|
| log BF, April | 10.6 | 10.4 |
fbesag has no noise term, so a rough region can also be noise. fbym2, which has one, also finds the Southeast rougher in April ($d = -0.48$, 95% interval $-0.69$ to $-0.26$; log BF 10.0).
Simulated check
20 data sets per setting on the same map, with the expected counts of April (simulated and fitted with the R package gmrfs, which gives the same fits):
| truth | $\sigma_\gamma$ | log BF, median (range) | log BF > 0 | $\theta$ Southeast, mean | interval covers truth |
|---|---|---|---|---|---|
| stationary, all $-1.3$ | 0.2 | −0.9 (−1.7 to 0.6) | 4 of 20 | −1.29 | 19 of 20 |
| 1 | −5.8 (−7.0 to −2.8) | 0 of 20 | −1.31 | 19 of 20 | |
| Southeast $-1.8$, others $-1.0$ | 0.2 | 13.1 (3.9 to 19.3) | 20 of 20 | −1.60 | 8 of 20 |
| 1 | 13.4 (0.7 to 21.1) | 20 of 20 | −1.75 | 17 of 20 |
The default $\sigma_\gamma$ pulls the Southeast towards the others; $\sigma_\gamma = 1$ recovers it.
With no difference between the regions (stationary truth), the estimates and intervals of $x_i$ are the same as with one precision:
| model | RMSE, Southeast | RMSE, other regions | coverage, Southeast | coverage, other regions |
|---|---|---|---|---|
| one precision | 0.170 | 0.204 | 0.947 | 0.949 |
| fbesag, $\sigma_\gamma = 0.2$ | 0.170 | 0.203 | 0.948 | 0.949 |
| fbesag, $\sigma_\gamma = 1$ | 0.170 | 0.203 | 0.949 | 0.949 |
References
- Abdul-Fattah, E., Krainski, E., Van Niekerk, J. and Rue, H. (2024). Non-stationary Bayesian spatial model for disease mapping based on sub-regions. Statistical Methods in Medical Research, 33(6), 1093–1111. doi:10.1177/09622802241244613
- Besag, J., York, J. and Mollié, A. (1991). Bayesian image restoration, with two applications in spatial statistics. Annals of the Institute of Statistical Mathematics, 43, 1–20.
- Lowe, R., Lee, S. A., O’Reilly, K. M. et al. (2021). Combined effects of hydrometeorological hazards and urbanisation on dengue risk in Brazil: a spatiotemporal modelling study. The Lancet Planetary Health, 5, e209–e219.
- Simpson, D., Rue, H., Riebler, A., Martins, T. G. and Sørbye, S. H. (2017). Penalising model component complexity: a principled, practical approach to constructing priors. Statistical Science, 32, 1–28.
- Sørbye, S. H. and Rue, H. (2014). Scaling intrinsic Gaussian Markov random field priors in spatial modelling. Spatial Statistics, 8, 39–51.