本篇来介绍基于广义线性模型的地理加权模型。广义线性模型包括Logistic模型、泊松模型等系列回归模型,具体内容请查看数学模型专辑的相关系列推文。
广义线性GWR的使用方法与线性GWR类似:
ggwr.sel
:带宽选择函数ggwr
:模型运行函数。
上述两个函数相比于gwr.sel()
和gwr
函数多了一个family
参数,用于指定因变量的概率分布模式,默认值为正态分布(family = gaussian
)。
ggwr()
函数的完整语法结构如下:
ggwr(formula, data = list(),
coords, bandwidth, gweight = gwr.Gauss,
adapt = NULL, fit.points,
family = gaussian, longlat = NULL,
type = c("working", "deviance", "pearson", "response"))
family:广义线性模型对应的指数族分布形式,具体见推文广义线性模型的基本结构及与线性模型的比较
longlat:当矢量数据的坐标形式为经纬度时,需将该参数设置为TRUE;
type:广义线性模型的残差类型;共有4种可选项,具体可查看网页https://www.datascienceblog.net/post/machine-learning/interpreting_generalized_linear_models/。
library(GWmodel)
library(spgwr)
data(LondonHP)
## 模型形式
form <- BATH2 ~ FLOORSZ
## 选择“最优”带宽
bw <- ggwr.sel(formula = form, data = londonhp,
gweight = gwr.Gauss,
family = binomial(),
verbose = F)
## 运行模型
model <- ggwr(form, data = londonhp,
family = binomial(),
bandwidth = bw)
## 查看模型统计量
model
## Call:
## ggwr(formula = form, data = londonhp, bandwidth = bw, family = binomial())
## Kernel function: gwr.Gauss
## Fixed bandwidth: 57238.62
## Summary of GWR coefficient estimates at data points:
## Min. 1st Qu. Median 3rd Qu. Max. Global
## X.Intercept. -5.424175 -5.368707 -5.342054 -5.297893 -5.240940 -5.3364
## FLOORSZ 0.028050 0.028458 0.028771 0.029046 0.029472 0.0288