算法手册/ 空间计量/ 地理加权回归GWR

地理加权回归GWR

计算公式

符号

符号含义
yi位置 i 的因变量取值
xij位置 i 的第 j 个自变量
ui, vi位置 i 的平面坐标
dij位置 i 与 j 的欧氏距离
hi位置 i 的带宽(自适应带宽时为第 k 近邻的距离)
wij位置 i 对 j 的核权重
βj(ui, vi)位置 i 的第 j 个局部系数
n, p样本量与自变量个数
SGWR 的帽子矩阵
ȳw以位置 i 的核权重加权的因变量均值
σ̂2残差方差估计

核心公式

公式 (1.1):局部加权最小二乘
\[ \hat{\boldsymbol{\beta}}(u_i,v_i)=\left[\mathbf{X}^{\top}\mathbf{W}(u_i,v_i)\mathbf{X}\right]^{-1}\mathbf{X}^{\top}\mathbf{W}(u_i,v_i)\mathbf{y},\qquad \mathbf{W}(u_i,v_i)=\operatorname{diag}\left(w_{i1},\ldots,w_{in}\right) \]
公式 (1.2):自适应双平方核
\[ w_{ij}=\left[1-\left(\frac{d_{ij}}{h_i}\right)^2\right]^2\mathbf{1}\left(d_{ij}\lt h_i\right),\qquad h_i=d_{i,(k)} \]
公式 (1.3):固定高斯核
\[ w_{ij}=\exp\left[-\frac{1}{2}\left(\frac{d_{ij}}{h}\right)^2\right] \]
公式 (1.4):局部拟合优度
\[ R_i^2=1-\frac{\mathbf{e}^{\top}\mathbf{W}(u_i,v_i)\mathbf{e}}{\left(\mathbf{y}-\bar{y}_w\right)^{\top}\mathbf{W}(u_i,v_i)\left(\mathbf{y}-\bar{y}_w\right)} \]
公式 (1.5):AICc
\[ \mathrm{AICc}=2n\ln\hat{\sigma}+n\ln(2\pi)+n\frac{n+\operatorname{tr}(\mathbf{S})}{n-2-\operatorname{tr}(\mathbf{S})} \]

参考文献

  1. Brunsdon, C., Fotheringham, A. S., & Charlton, M. E. (1996). Geographically weighted regression: A method for exploring spatial nonstationarity. Geographical Analysis, 28(4), 281–298.
  2. Fotheringham, A. S., Brunsdon, C., & Charlton, M. (2002). Geographically Weighted Regression: The Analysis of Spatially Varying Relationships. Wiley.

算法参数

参数取值默认影响
核函数 双平方 / 高斯 双平方 双平方为截断核,高斯为衰减核;改变邻域权重。
带宽 正数;留空自动 留空(AICc 搜索) 自适应时为最近邻个数,固定时为距离;带宽越小局部性越强。
自适应带宽 是 / 否 是 选「是」用最近邻个数,选「否」用固定距离。

验证报告

数据与 R 包

数据文件 gwr.csv
样本与变量 N = 80 个位置;Xcoord、Ycoord 为平面公里坐标,X1、X2 为自变量,Y 为因变量
R 包 GWmodel 2.4.1、sp 2.2.4

提示词

以 Xcoord、Ycoord 为平面坐标,Y 为因变量、X1 与 X2 为自变量,拟合自适应双平方核、30 个最近邻带宽的 GWR;报告 AICc、R²、局部系数均值与标准差,并给出全局 OLS 对照。

R 代码

library(GWmodel)
library(sp)
d <- read.csv("gwr.csv")
coordinates(d) <- c("Xcoord", "Ycoord")
proj4string(d) <- CRS("+proj=utm +zone=50 +datum=WGS84")
g <- gwr.basic(Y ~ X1 + X2, data = d, bw = 30, kernel = "bisquare",
               adaptive = TRUE)
s <- as.data.frame(g$SDF)
dg <- g$GW.diagnostic
print(c(AICc = dg$AICc, R2 = dg$gw.R2), digits = 15)
print(cbind(mean = colMeans(s[, c("Intercept", "X1", "X2")]),
            sd = apply(s[, c("Intercept", "X1", "X2")], 2, sd)), digits = 15)
print(coef(lm(Y ~ X1 + X2, data = read.csv("gwr.csv"))), digits = 15)

对比结果

指标SPSSAUR差值
AICc452.3806103687452.38060121989.15e−6
R²0.97762999570.97763000125.5e−9
截距局部均值10.550273263910.55027327721.33e−8
X1 局部均值12.441902246112.44190213721.09e−7
X2 局部均值10.002449728410.00244985161.23e−7
X1 局部标准差3.10339968643.10339997172.85e−7
X2 局部标准差5.60757781725.60757800391.87e−7
全局 OLS 的 X1 系数14.847617126514.84761712651.69e−11
全局 OLS 的 X2 系数8.43785331998.43785331994.98e−11

结论:AICc、R²、局部系数均值与标准差、全局 OLS 系数均与 R 一致(系数差值在 10⁻⁷ 量级,AICc 差值约 9×10⁻⁶),差异来自 mgwr 与 GWmodel 的迭代收敛精度。口径说明:验证固定自适应带宽为 30 个最近邻、双平方核,避免两套自动带宽搜索准则(mgwr 的 AICc 与 GWmodel 的 CV/AICc)带来不可比;坐标按平面欧氏距离计算,Xcoord、Ycoord 已换算为公里,不使用球面距离。局部 R² 的均值不作为对比项:mgwr 与 GWmodel 对局部加权总平方和的取法不同(本数据 SPSSAU 0.9690、R 0.9605),二者都能描述局部拟合优劣,但不能逐位对照;调整 R² 的自由度修正也不同。

操作手册 问题反馈

引用SPSSAU. 地理加权回归GWR:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/spatial/gwr.html.