地理加权回归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 | 样本量与自变量个数 |
| S | GWR 的帽子矩阵 |
| ȳ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})}
\]
参考文献
- Brunsdon, C., Fotheringham, A. S., & Charlton, M. E. (1996). Geographically weighted regression: A method for exploring spatial nonstationarity. Geographical Analysis, 28(4), 281–298.
- Fotheringham, A. S., Brunsdon, C., & Charlton, M. (2002). Geographically Weighted Regression: The Analysis of Spatially Varying Relationships. Wiley.
算法参数
| 参数 | 取值 | 默认 | 影响 |
|---|---|---|---|
| 核函数 | 双平方 / 高斯 | 双平方 | 双平方为截断核,高斯为衰减核;改变邻域权重。 |
| 带宽 | 正数;留空自动 | 留空(AICc 搜索) | 自适应时为最近邻个数,固定时为距离;带宽越小局部性越强。 |
| 自适应带宽 | 是 / 否 | 是 | 选「是」用最近邻个数,选「否」用固定距离。 |
验证报告
数据与 R 包
提示词
以 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)
对比结果
| 指标 | SPSSAU | R | 差值 |
|---|---|---|---|
| AICc | 452.3806103687 | 452.3806012198 | 9.15e−6 |
| R² | 0.9776299957 | 0.9776300012 | 5.5e−9 |
| 截距局部均值 | 10.5502732639 | 10.5502732772 | 1.33e−8 |
| X1 局部均值 | 12.4419022461 | 12.4419021372 | 1.09e−7 |
| X2 局部均值 | 10.0024497284 | 10.0024498516 | 1.23e−7 |
| X1 局部标准差 | 3.1033996864 | 3.1033999717 | 2.85e−7 |
| X2 局部标准差 | 5.6075778172 | 5.6075780039 | 1.87e−7 |
| 全局 OLS 的 X1 系数 | 14.8476171265 | 14.8476171265 | 1.69e−11 |
| 全局 OLS 的 X2 系数 | 8.4378533199 | 8.4378533199 | 4.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.