learn_spatial_autocorrelation
learn_spatial_autocorrelation(
side=12,
rho=0.6,
n_sims=10,
permutations=199,
seed=0,
)See what spatial autocorrelation looks like — and how Moran’s I tracks it.
Simulates fields y = (I - rho W)^-1 eps on a side x side lattice with row-standardized queen weights, sweeping the planted dependence ρ over a grid that includes the focal rho. The figure pairs the focal simulated field (left) with the Moran’s I recovered at each planted ρ (right): at ρ = 0 the statistic sits at its null expectation E[I] = -1/(n-1); as ρ rises, neighbors look alike and I climbs.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| side | int | Lattice side length (n = side²). | 12 |
| rho | float | The focal planted spatial dependence, |ρ| < 1. The left panel draws a field at this value and the sweep curve highlights it. | 0.6 |
| n_sims | int | Simulated fields per ρ (the faint markers behind the mean curve). | 10 |
| permutations | int | Conditional permutations behind each Moran’s I pseudo p-value. | 199 |
| seed | int | Random seed. | 0 |
Returns
| Name | Type | Description |
|---|---|---|
| SandboxResult | df (one row per ρ and simulation), fig, summary, topic and the focal simulated field in data. |
Examples
The knob variation is the lesson — compare no dependence with strong dependence:
import geometrics as gm
gm.learn_spatial_autocorrelation(rho=0.0).fig
gm.learn_spatial_autocorrelation(rho=0.8).fig