Multiscale Geographically Weighted Regression (GWRMultiscale)¶
Mathematical Foundation¶
Multiscale GWR (MGWR) extends basic GWR by allowing each independent variable to have its own bandwidth. Different spatial processes may operate at different spatial scales — the influence of some variables may be highly local (small bandwidth), while others may have regional or global scale (large bandwidth).
The MGWR model form is the same as basic GWR:
However, each coefficient \(\beta_{ik}\) is estimated using its own bandwidth \(b_k\). Bandwidth calibration is carried out via the backfitting algorithm [1]:
Initialisation: Compute initial coefficient estimates \(\boldsymbol{\beta}^{(0)}\) using standard GWR with an initial spatial weighting configuration.
Backfitting: For each iteration \(t = 1, 2, \dots\):
For each variable \(k\):
Fix the coefficients of all other variables and compute the residual of the dependent variable for the current variable.
Select the optimal bandwidth \(b_k\) for variable \(k\) (golden section search with CV/AIC criterion).
Fit new coefficients for variable \(k\) using \(b_k\).
Update the residuals.
Check the convergence criterion (CVR or dCVR); stop if satisfied.
Diagnostics: Compute RSS, AICc, ENP, EDF, R², and other diagnostic metrics.
Convergence Criteria¶
CVR (Change in RSS):
\[\text{CVR} = |RSS_t - RSS_{t-1}|\]dCVR (relative Change in RSS, default):
\[\text{dCVR} = \sqrt{\frac{|RSS_t - RSS_{t-1}|}{RSS_t}}\]
Key Parameters¶
Parameter |
Description |
Default |
|---|---|---|
|
A list of bandwidth weights, one per variable (including intercept) |
Required |
|
The distance metric shared by all variables |
|
|
Whether to include an intercept term |
|
|
Bandwidth initialisation type per variable |
All |
|
Bandwidth selection criterion per variable |
All |
|
Whether to centre each predictor before fitting |
All |
|
Backfitting convergence criterion type |
|
|
Maximum number of iterations |
|
|
Convergence threshold |
|
|
Whether to compute the hat matrix (for diagnostics) |
|
|
Lower bound on neighbour count for adaptive bandwidth selection |
|
Bandwidth Initialisation Types¶
Type |
Meaning |
|---|---|
|
Not specified; auto-select via golden section search during backfitting |
|
User-specified; skip bandwidth selection and use the fixed value from |
|
Initially optimised; may still be adjusted in later backfitting iterations |
Code Examples¶
Basic Usage (Auto-Select Bandwidths)¶
from pygwmodel import GWRMultiscale, BandwidthWeight, CRSDistance
n_var = 4 # intercept + 3 independent variables
weights = [BandwidthWeight(36.0, adaptive=True) for _ in range(n_var)]
algorithm = GWRMultiscale(
data,
depen_var="PURCHASE",
indep_vars=["FLOORSZ", "UNEMPLOY", "PROF"],
weights=weights,
distance=CRSDistance()
).fit()
# Diagnostic information
print(algorithm.diagnostic)
# Optimised bandwidths per variable
for w in algorithm.weights:
print(f"bandwidth={w.bandwidth}, adaptive={w.adaptive}")
# Result layer
result = algorithm.result_layer
print(result.columns)
# Intercept, FLOORSZ, UNEMPLOY, PROF,
# Intercept_SE, FLOORSZ_SE, ..., Intercept_TV, ..., fitted
Specified Bandwidths¶
from pygwmodel import GWRMultiscale
n_var = 4
spec = GWRMultiscale.BandwidthInitilizeType.Specified
cv = GWRMultiscale.BandwidthSelectionCriterionType.CV
algorithm = GWRMultiscale(
data, y, x,
weights=[BandwidthWeight(36.0, adaptive=True) for _ in range(n_var)],
bandwidth_initilize=[spec] * n_var,
bandwidth_selection_approach=[cv] * n_var
).fit()
Note: when bandwidth_initilize is set to Specified, the bandwidths
remain fixed; otherwise they are iteratively optimised during backfitting.
Adjusting Convergence¶
algorithm = GWRMultiscale(data, y, x, weights)
algorithm.criterion_type = GWRMultiscale.BackFittingCriterionType.CVR
algorithm.criterion_threshold = 1e-4
algorithm.max_iteration = 100
algorithm.fit()
References¶
Yu, H., Fotheringham, A. S., Li, Z., Oshan, T., Kang, W., & Wolf, L. J. (2020). Inference in multiscale geographically weighted regression. Geographical Analysis, 52(1), 87-106.