首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将地理加权回归模型参数应用于更精细的空间尺度

将地理加权回归模型参数应用于更精细的空间尺度
EN

Stack Overflow用户
提问于 2022-12-03 18:00:56
回答 1查看 35关注 0票数 0

我有两个光栅层,一个粗分辨率和一个精细分辨率。我的目标是提取GWR的系数(拦截和斜率),并将它们应用到我的精细分辨率光栅中。

当我执行简单的线性回归时,我可以很容易地做到这一点。例如:

代码语言:javascript
复制
library(terra)
library(sp)

# focal terra
tirs = rast("path/tirs.tif") # fine res raster
ntl = rast("path/ntl.tif") # coarse res raster
    
# fill null values
tirs = focal(tirs, 
             w = 9, 
             fun = mean, 
             na.policy = "only", 
             na.rm = TRUE)
  
gf <- focalMat(tirs, 0.10*400, "Gauss", 11)
r_gf <- focal(tirs, w = gf, na.rm = TRUE)
  
r_gf = resample(r_gf, ntl, method = "bilinear")

s = c(ntl, r_gf)
names(s) = c('ntl', 'r_gf')

model <- lm(formula = ntl ~ tirs, data = s)

# apply the lm coefficients to the fine res raster
lm_pred = model$coefficients[1] + model$coefficients[2] * tirs

但是当我运行GWR时,斜率和截距不仅仅是两个数字(就像线性模型中的那样),而是一个范围。例如,下面是GWR的结果

GWR系数估计综述:

代码语言:javascript
复制
                Min.     1st Qu.      Median     3rd Qu.     Max.

Intercept -1632.61196   -55.79680   -15.99683    15.01596 1133.299

tirs20      -42.43020     0.43446     1.80026     3.75802   70.987

我的问题是如何提取GWR模型参数(拦截和斜率)并将它们应用到我的精细分辨率光栅中?最后,我想做和线性模型一样的事情,即GWR_intercept + GWR_slope *精细分辨率光栅。

这是GWR的代码

代码语言:javascript
复制
library(GWmodel)
library(raster)

block.data = read.csv(file = "path/block.data00.csv")

#create mararate df for the x & y coords
x = as.data.frame(block.data$x)
y = as.data.frame(block.data$y)
sint = as.matrix(cbind(x, y))

#convert the data to spatialPointsdf and then to spatialPixelsdf
coordinates(block.data) = c("x", "y")
#gridded(block.data) <- TRUE

# specify a model equation
eq1 <- ntl ~ tirs

dist = GWmodel::gw.dist(dp.locat = sint, focus = 0, longlat = FALSE)

abw = bw.gwr(eq1, 
       data = block.data, 
       approach = "AIC", 
       kernel = "tricube",
       adaptive = TRUE, 
       p = 2, 
       longlat = F, 
       dMat = dist,
       parallel.method = "omp",
       parallel.arg = "omp")

ab_gwr = gwr.basic(eq1, 
          data = block.data, 
          bw = abw, 
          kernel = "tricube",
          adaptive = TRUE, 
          p = 2,
          longlat = FALSE, 
          dMat = dist,
          F123.test = FALSE,
          cv = FALSE,
          parallel.method = "omp",
          parallel.arg = "omp")

ab_gwr

您可以从csv下载这里。我用的光栅:

代码语言:javascript
复制
ntl = rast(ncols=101, nrows=85, nlyrs=1, xmin=509634.6325, xmax=550034.6325, ymin=161598.158, ymax=195598.158, names=c('ntl'), crs='EPSG:27700')

tirs = rast(ncols=407, nrows=342, nlyrs=1, xmin=509600, xmax=550300, ymin=161800, ymax=196000, names=c('tirs'), crs='EPSG:27700')
EN

回答 1

Stack Overflow用户

发布于 2022-12-04 06:52:23

这就是如何进行全局回归和预测到更高的分辨率(降级)。

代码语言:javascript
复制
library(terra)
r <- rast(system.file("ex/logo.tif", package="terra"))
a <- aggregate(r, 10, mean)

model <- lm(formula = red ~ green, data=a)
p <- predict(r, model)

代码语言:javascript
复制
d <- as.data.frame(a[[1:2]], xy=TRUE)

也许这有助于在你的问题中写出一个更好的例子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74669285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档