我有两个光栅层,一个粗分辨率和一个精细分辨率。我的目标是提取GWR的系数(拦截和斜率),并将它们应用到我的精细分辨率光栅中。
当我执行简单的线性回归时,我可以很容易地做到这一点。例如:
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系数估计综述:
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的代码
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下载这里。我用的光栅:
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')发布于 2022-12-04 06:52:23
这就是如何进行全局回归和预测到更高的分辨率(降级)。
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)和
d <- as.data.frame(a[[1:2]], xy=TRUE)也许这有助于在你的问题中写出一个更好的例子。
https://stackoverflow.com/questions/74669285
复制相似问题