【发布时间】:2022-12-03 06:25:45
【问题描述】:
我有三个栅格图层,两个粗分辨率和一个精细分辨率。我使用粗分辨率栅格执行简单的线性回归,然后提取回归系数(斜率和截距),并将它们与我的高分辨率栅格一起使用。到目前为止,我是通过在控制台中绘制系数来手动执行此操作的。有什么方法可以自动执行此操作(以某种方式使用系数而无需打印它们并复制粘贴它们,因为我有 10-20 个光栅来执行此操作)。
到目前为止,这是我正在做的事情:
library(terra)
library(sp)
ntl = rast("path/ntl.tif")
vals_ntl <- as.data.frame(values(ntl))
ntl_coords = as.data.frame(xyFromCell(ntl, 1:ncell(ntl)))
combine <- as.data.frame(cbind(ntl_coords,vals_ntl))
ebbi = rast("path/tirs010.tif")
ebbi <- resample(ebbi, ntl, method="bilinear")
vals_ebbi <- as.data.frame(values(ebbi))
s = c(ntl, ebbi)
names(s) = c('ntl', 'ebbi')
block.data <- as.data.frame(cbind(combine, vals_ebbi))
names(block.data)[3] <- "ntl"
names(block.data)[4] <- "ebbi"
block.data <- na.omit(block.data)
model <- lm(formula = ntl ~ ebbi, data = block.data)
#predict to a raster
summary(model)
model$coefficients # here I plot the coefficients into the console and then manually I use them below
pop = rast("path/pop.tif")
lm_pred010 = 19.0540153 + 0.2797187 * pop
plot(lm_pred010)
res(lm_pred010)
writeRaster(lm_pred010,
filename = "path/lm_pred010.tif",
overwrite = T)
我正在使用的栅格:
ntl = rast(ncols=101, nrows=84, nlyrs=1, xmin=509634.6325, xmax=550034.6325, ymin=161998.158, ymax=195598.158, names=c('ntl'), crs='EPSG:27700')
ebbi = rast(ncols=101, nrows=84, nlyrs=1, xmin=509634.6325, xmax=550034.6325, ymin=161998.158, ymax=195598.158, names=c('focal_sum'), crs='EPSG:27700')
pop = rast(ncols=407, nrows=343, nlyrs=1, xmin=509615.9028, xmax=550315.9028, ymin=161743.6035, ymax=196043.6035, names=c('pop'), crs='EPSG:27700')
【问题讨论】:
标签: r linear-regression raster coefficients