返回 R 中地理加权回归 (GWR) 的全局 R2

标签 r geospatial gwr spgwr

我已经使用 spgwr 库在 R 中运行了地理加权回归 (GWR),现在我想返回准全局 R2(适合模型)。我已经使用 summary(gwr_model) 深入研究了结果,但我还没有找到提取此值的方法。有什么想法吗?

可重现的例子

library(spgwr)

# load data
  data(columbus)

# calculate Optimal kernel bandwidth 
  col.bw <- gwr.sel(crime ~ income + housing, data=columbus, coords=cbind(columbus$x, columbus$y))
# run GWR
  gwr_model <- gwr(crime ~ income + housing, data=columbus,
                   coords=cbind(columbus$x, columbus$y), bandwidth=col.bw, hatmatrix=TRUE)

# get global coefficients
  gwr_model$lm$coefficients


# print results. It shows the Quasi-global R2: 0.9071
  gwr_model

  #> Call:
  #>   gwr(formula = crime ~ income + housing, data = columbus, coords = cbind(columbus$x, 
  #>                                                                           columbus$y), bandwidth = col.bw, hatmatrix = TRUE)
  #> Kernel function: gwr.Gauss 
  #> Fixed bandwidth: 2.275 
  #> Summary of GWR coefficient estimates at data points:
  #>   Min. 1st Qu.  Median 3rd Qu.    Max. Global
  #> X.Intercept. 23.2332 54.1252 63.9024 68.7564 80.9009  68.62
  #> income       -3.1307 -1.9129 -0.9844 -0.3686  1.2911  -1.60
  #> housing      -1.0528 -0.3767 -0.0974  0.0301  0.7946  -0.27
  #> Number of data points: 49 
  #> Effective number of parameters (residual: 2traceS - traceS'S): 29.62 
  #> Effective degrees of freedom (residual: 2traceS - traceS'S): 19.38 
  #> Sigma (residual: 2traceS - traceS'S): 8.027 
  #> Effective number of parameters (model: traceS): 23.93 
  #> Effective degrees of freedom (model: traceS): 25.07 
  #> Sigma (model: traceS): 7.058 
  #> Sigma (ML): 5.049 
  #> AICc (GWR p. 61, eq 2.33; p. 96, eq. 4.21): 403.6 
  #> AIC (GWR p. 96, eq. 4.22): 321.7 
  #> Residual sum of squares: 1249 
  #> Quasi-global R2: 0.9071 

最佳答案

如果您想要的是获得“准全局 R2”,则 source code表明至少可以计算它。

qGlobalR2 <- (1 - (gwr_model$results$rss/gwr_model$gTSS))

关于返回 R 中地理加权回归 (GWR) 的全局 R2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43927662/

相关文章:

R Markdown 演示 : How to continue a numbered list across a slide?

r - 在运行时在 lapply 包装器中打印消息

R - 在回归中仅与一个因子水平相互作用

mysql - 如何存储MySQL的结果以便以后排序

按距离以外的其他方式对 MongoDB GeoNear 结果进行排序?

c# - System.Data.Spatial 或 System.Data.Entity.Spatial

r - 在 R 中编写多种族类别