10  Geographically Weighted Regression

10.1 Geographically Weighted Regression

Simple linear regression assumes the relationship between variables is constant everywhere. But in spatial data, relationships often change across space.

For example:

  • income may strongly affect housing prices in cities, but less in rural areas
  • rainfall may strongly influence vegetation in one region, but weakly in another
  • temperature may affect crop growth differently across climate zones

This means the relationship itself varies by location.

A Geographically Weighted Regression (GWR) models this by allowing regression coefficients to change across space.

In GWR, every location gets its own local regression equation.

GWR is useful when:

  • relationships vary across space
  • one global regression does not fit everywhere
  • regional differences are important
  • you want to understand where relationships are stronger or weaker

10.2 GWR Formula

The equation for Geographically Weighted Regression is:

\[ y_i = \beta_0(u_i,v_i) + \sum_k \beta_k(u_i,v_i)x_{ik} + \varepsilon_i \]

where:

  • (yi) = response at location (i)
  • (xik) = predictor variable(s) at location (i)
  • (beta(ui,vi)) = local coefficient estimated at coordinates ((ui,vi))
  • (ui,vi) = spatial location of observation (i)
  • (epsilon) = random error term

10.3 Step 1: Define a Neighborhood


10.4 Step 2: Create Spatial Weights


10.5 Step 3: Fit Local Regressions

Instead of fitting one regression for the entire dataset, GWR fits one regression at every location.

Each local model uses:

  • nearby observations
  • distance-based weights
  • local predictor-response relationships

This produces local coefficients for every point.


10.6 Fitting GWR

A GWR model can be fit using Python:

import numpy as np
from mgwr.gwr import GWR
from mgwr.sel_bw import Sel_BW

coords = list(zip(df["x_coord"], df["y_coord"]))
X = df[["x1", "x2"]].values
y = df["y"].values.reshape((-1,1))

# choose bandwidth
bw = Sel_BW(coords, y, X).search()

# fit model
gwr_model = GWR(coords, y, X, bw)
results = gwr_model.fit()

print(results.summary())

The output estimates:

  • local coefficients
  • local intercepts
  • local R squared values

10.7 Mapping Coefficients

One major strength of GWR is that coefficients can be mapped.

For example, mapping the coefficient for rainfall may show:

strong positive effect in one region weak effect in another negative effect elsewhere

This reveals:

where relationships are strongest/weakest


10.8 Strengths and Limitationss

Strengths

  • captures spatially varying relationships
  • reveals local patterns
  • produces mappable coefficients

Limitations

  • sensitive to bandwidth choice
  • can overfit data