fbym2
A non-stationary spatial model with noise: a spatial part whose smoothness differs between sub-regions, plus noise of each area.
Idea
The effect of each area is a spatial part, shared with its neighbours, plus noise of its own. The spatial part is an fbesag field, so its smoothness differs between sub-regions. With the same smoothness everywhere it is the BYM2 model (Riebler et al., 2016), with the same priors, so comparing the two tests whether the map is non-stationary. When the sub-regions do not differ, the estimates are almost the same as BYM2's (see the check).
Model
| parameter | meaning |
|---|---|
| $\tau$ | precision of $v_i$ |
| $\phi$ | spatial share of the variance |
| $d_k$ | log precision of the spatial part in sub-region $k$, relative to the map: $d_k > 0$ smoother, $d_k < 0$ rougher |
As in bym2, the latent vector is $(\mathbf v, \mathbf u)$, of length $2n$:
Priors
$\boldsymbol\theta = (\log\tau,\ \text{logit}\,\phi,\ d_1, \dots, d_{P-1})$, reported as Theta1, Theta2, …; $d_P = -(d_1 + \dots + d_{P-1})$.
| parameter | prior | default | meaning |
|---|---|---|---|
| $\tau$ | PC | prec=(1, 0.01) | $P(1/\sqrt\tau > 1) = 0.01$ |
| $\phi$ | PC of BYM2 | phi=(0.5, 0.5) | $P(\phi < 0.5) = 0.5$ |
| $\mathbf d$ | $\mathcal N\big(\mathbf 0, \sigma_\gamma^2 (I - \tfrac1P J)\big)$ | sd_gamma=0.2 | as in fbesag; $\sigma_\gamma \to 0$ gives bym2 |
Example: rough and smooth regions
Simulated on the 558 microregions of Brazil, 5 expected cases each, with $\boldsymbol\theta = (1,\ \text{logit}\,0.8,\ -2,\ -2,\ 2,\ 2)$. Data: fbym2_simulated.csv (true $v_i$ and $y_i$), 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 fbym2
d = pd.read_csv("fbym2_simulated.csv") # idx, region_code, true v, y, E
graph = "brazil_558_microregions.graph"
region = d["region_code"].to_numpy() # 1 North, 2 Northeast, 3 Southeast, 4 South, 5 Centre-West
m_regions = fbym2("idx", graph, region, sd_gamma=1)
def fit(m):
return pyinla(model={"response": "y", "fixed": ["1"], "random": [m]},
family="poisson", data=d, E=d["E"].to_numpy())
fit_regions = fit(m_regions)
fit_bym2 = fit({"id": "idx", "model": "bym2", "graph": graph})
print(fit_regions.summary_hyperpar[["mean", "0.025quant", "0.975quant"]].round(2))
print(fit_regions.mlik.iloc[1] - fit_bym2.mlik.iloc[1]) # log Bayes factor for the regions
mean 0.025quant 0.975quant
Theta1 for idx 0.87 0.52 1.22
Theta2 for idx 1.70 0.64 2.75
Theta3 for idx -1.68 -2.29 -1.07
Theta4 for idx -1.81 -2.29 -1.33
Theta5 for idx 1.52 0.66 2.39
Theta6 for idx 1.64 0.56 2.72
56.71719603300926
Regional deviations
from pyinla import hyperpar_sample
import matplotlib.pyplot as plt
np.random.seed(1)
th = hyperpar_sample(4000, fit_regions, intern=True).to_numpy() # log tau, logit phi, d_1, ..., d_4
dk = np.column_stack([th[:, 2:6], -th[:, 2:6].sum(axis=1)]) # d_5 = -(d_1 + ... + d_4)
region_names = ["North", "Northeast", "Southeast", "South", "Centre-West"]
q = pd.DataFrame(np.quantile(dk, [0.025, 0.5, 0.975], axis=0),
index=["2.5%", "50%", "97.5%"], columns=region_names)
print(q.round(2))
plt.errorbar(q.loc["50%"], region_names, fmt="o",
xerr=[q.loc["50%"] - q.loc["2.5%"], q.loc["97.5%"] - q.loc["50%"]])
plt.axvline(0)
North Northeast Southeast South Centre-West
2.5% -2.30 -2.28 0.67 0.58 -0.40
50% -1.68 -1.81 1.53 1.63 0.33
97.5% -1.06 -1.32 2.37 2.72 1.11

Estimates
import geopandas as gpd
# error of the posterior mean of v, by region (v: the first 558 entries)
def rmse(fit):
v_hat = fit.summary_random["idx"]["mean"].to_numpy()[:558]
return np.sqrt(pd.Series((v_hat - d["v"]) ** 2).groupby(region).mean()).set_axis(region_names)
print(pd.DataFrame({"bym2": rmse(fit_bym2), "fbym2": rmse(fit_regions)}).T.round(2))
map_df = gpd.read_file("brazil_558_microregions.geojson").sort_values("idx").reset_index(drop=True)
map_df["truth"] = d["v"].to_numpy()
map_df["bym2"] = fit_bym2.summary_random["idx"]["mean"].to_numpy()[:558]
map_df["fbym2"] = fit_regions.summary_random["idx"]["mean"].to_numpy()[:558]
map_df.plot("fbym2", cmap="RdBu_r", vmin=-2.5, vmax=2.5, linewidth=0, legend=True)
North Northeast Southeast South Centre-West
bym2 0.72 0.59 0.34 0.35 0.36
fbym2 0.66 0.50 0.25 0.28 0.33

The two estimates differ by 0.11 to 0.16 on average, too little to see on this colour scale. With one spatial precision, bym2 smooths the North more than fbym2 and the Southeast and South less; its error is higher in every region.
Repeated: 20 data sets
20 simulated data sets for each truth (with the R package gmrfs): the example above, and no difference between the regions.

| truth | model | North | Northeast | Southeast | South | Centre-West | |
|---|---|---|---|---|---|---|---|
| regions differ | RMSE | bym2 | 0.527 | 0.495 | 0.328 | 0.345 | 0.331 |
| fbym2 | 0.485 | 0.442 | 0.250 | 0.258 | 0.303 | ||
| coverage | bym2 | 0.886 | 0.889 | 0.977 | 0.973 | 0.968 | |
| fbym2 | 0.928 | 0.946 | 0.959 | 0.953 | 0.937 | ||
| no difference, all $d_k = 0$ | RMSE | bym2 | 0.316 | 0.320 | 0.320 | 0.301 | 0.302 |
| fbym2 | 0.318 | 0.321 | 0.321 | 0.303 | 0.306 | ||
| coverage | bym2 | 0.949 | 0.945 | 0.945 | 0.941 | 0.957 | |
| fbym2 | 0.943 | 0.949 | 0.942 | 0.943 | 0.945 |
When the regions differ, fbym2 has the lower error in 16 to 20 of the 20 data sets in every region, and the log BF favours it in all 20 (38 to 74). When they do not, the two are almost the same (error at most 0.004 higher), and the log BF has median $-2.3$ and is at most 1.4.
Testing for non-stationarity
If you change the priors of fbym2, give bym2 the same hyper.
Beyond $\text{logit}\,\phi = 12$, the bym2 prior is flat (improper) and fbym2's is the exact PC tail. If the posterior of $\phi$ reaches 1, compare with fbym2 with all id_part equal to 1 instead of bym2.
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
- Riebler, A., Sørbye, S. H., Simpson, D. and Rue, H. (2016). An intuitive Bayesian spatial model for disease mapping that accounts for scaling. Statistical Methods in Medical Research, 25, 1145–1165.
- 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.