learn_omitted_spatial_lag

learn_omitted_spatial_lag(side=10, beta=1.0, rho=0.7, noise=0.5, seed=0)

Show why ignoring spatial dependence biases OLS — and how SAR repairs it.

Simulates y = (I - rho W)^-1 (beta x + eps): outcomes spill over through the spatial multiplier, so OLS on y ~ x (which omits the spatial lag Wy) absorbs the feedback into its slope and overstates β. The ML spatial-lag (SAR) estimator models the dependence and recovers both β and ρ.

Parameters

Name Type Description Default
side int Lattice side length (n = side²). 10
beta float Planted coefficient on x. 1.0
rho float Planted spatial-lag parameter, |ρ| < 1 (drives the OLS bias). 0.7
noise float Standard deviation of the innovation. 0.5
seed int Random seed. 0

Returns

Name Type Description
SandboxResult df (OLS vs SAR vs true coefficient), fig, summary, topic and the simulated cross-section in data.

Examples

import geometrics as gm

res = gm.learn_omitted_spatial_lag(rho=0.7)
print(res.summary["ols_coef"], res.summary["sar_beta"])