spatial_model

spatial_model(
    data,
    y,
    x,
    year=None,
    *,
    model='durbin',
    method='ml',
    w=None,
    fixed_effects=None,
    impacts=True,
    n_draws=10000,
    seed=12345,
    title=None,
    gdf=None,
    ref=None,
)

A spatial regression for one year, with direct, indirect (spillover) and total impacts.

Parameters

Name Type Description Default
data A dataset id, or a panel with geo_id (and year), e.g. from load or combine required
y str The outcome column required
x The regressors: a column or a list of columns required
year The year to model (default: the last with data for y and every regressor) None
model str "ols" (no spatial term), "lag" (neighbours’ outcome), "error" (spatially correlated errors), "slx" (neighbours’ regressors), "durbin" (neighbours’ outcome and regressors) or "durbin_error" (neighbours’ regressors and spatially correlated errors) 'durbin'
method str "ml" (maximum likelihood) or "gm" (generalized method of moments; not for "durbin_error") 'ml'
w Spatial weights from weights (default: queen contiguity among the units with data) None
fixed_effects str | None A column or a coarser scale, added as dummies None
impacts bool Compute the direct, indirect and total impacts where the model has them True
n_draws int Simulation draws behind the standard errors of the impacts 10000
seed int | None Makes the draws reproducible 12345
title str | None The title of the table None
gdf Boundaries to use instead of the project’s (a GeoDataFrame with geo_id) None

Returns

Name Type Description
result object A result with .df (tidy coefficients: variable, the column name, with const for the intercept and W_<column> for a spatial lag; term, its label; estimate, se, z, p), .gt (the coefficient table), .impacts (one row per regressor: variable, term, direct, indirect, total and their standard errors; None for "ols" and "error"), the spatial parameters .rho (lag) and .lam (error), .r2, .aic, .log_likelihood, .n_obs, .model_obj (the fitted spreg model) and .interpret().

Example

!pip install -q geo4bolivia
import geo4bolivia as geo

res = geo.spatial_model("sdg", "index_sdg", "urbanization", model="durbin")
print(res.interpret())
res.gt

A spatial Durbin (SDM) model of Sustainable Development Index, IDS (0-100) was estimated by ML on 343 units (weights: queen contiguity (1 island(s) attached to nearest neighbor), row-standardized, n=343).

The spatial autoregressive parameter is ρ = 0.668 (statistically significant at the 1% level): outcomes move together with neighbors’ outcomes, so any local difference is amplified through the neighborhood multiplier 1/(1-ρ) ≈ 3.02 rather than staying put.

For Urbanization rate (% of population), a one-unit higher value is associated with a direct change of 0.0908 in the same unit’s Sustainable Development Index, IDS (0-100) and an indirect (spillover) change of 0.0512 summed across its neighbors — a total association of 0.142 (statistically significant at the 1% level).

Model fit: (pseudo-)R² = 0.598, AIC = 1849 (compare AIC across specifications estimated on the same sample).

These are associations, not causal effects. A causal reading needs a research design.

Spatial durbin (sdm) model of Sustainable Development Index, IDS (0-100)
ML estimates | n = 343 | R² = 0.598 | AIC = 1849.0
Estimate Std. Error z p
CONSTANT 18.6471*** (2.8139) 6.63 0.0000
Urbanization rate (% of population) 0.0802*** (0.0066) 12.07 0.0000
W_Urbanization rate (% of population) -0.0332*** (0.0123) -2.69 0.0072
W_Sustainable Development Index, IDS (0-100) 0.6684*** (0.0492) 13.59 0.0000
*** p<0.01, ** p<0.05, * p<0.10 (z-based)
W: queen contiguity (1 island(s) attached to nearest neighbor), row-standardized, n=343