pyINLA · fbesag
Sub-regions that are not neighbours
The sub-regions can be any grouping of the areas.
Urban and rural
The 558 microregions of Brazil: 309 more than 70% urban, 249 not.


Example
Simulated: urban rough ($\theta = -0.5$), rural smooth ($\theta = 1.5$), with the expected cases of April scaled to the observed total. Data: fbesag_groups_simulated.csv (true $x_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 fbesag
d = pd.read_csv("fbesag_groups_simulated.csv") # idx, urban (%), true x, y, E
graph = "brazil_558_microregions.graph"
group = np.where(d["urban"] > 70, 1, 2) # 1: more than 70% urban, 2: the rest
m = fbesag("idx", graph, group, 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_besag = fit(fbesag("idx", graph, np.ones(558, int)))
fit_groups = fit(m)
print(fit_groups.summary_hyperpar[["mean", "0.025quant", "0.975quant"]].round(2))
print(fit_groups.mlik.iloc[1] - fit_besag.mlik.iloc[1]) # log Bayes factor for the groups
mean 0.025quant 0.975quant
Theta1 for idx -0.39 -0.60 -0.17
Theta2 for idx 1.45 1.27 1.63
63.923419146250126
Both intervals cover the truth. With the default $\sigma_\gamma = 0.2$ the estimates are pulled together ($-0.17$, $1.26$) and miss it.