1
$\begingroup$

I have three raster layers, two coarse resolution and one fine resolution. My goal is to extract GWR's coefficients (intercept and slope) and apply them to my fine resolution raster.

I can do this easily when I perform simple linear regression. For example:

library(terra)
library(sp)

ntl = rast("path/ntl.tif") # coarse res raster
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") # coarse res raster
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
pop = rast("path/pop.tif") # fine res raster
lm_pred010 = 19.0540153 + 0.2797187 * pop

I can do this under the assumption of scale-invariance. But when I run GWR, the slope and intercept are not just two numbers (like in linear model) but it's a range. For example, below are the results of the 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

My question is how can extract GWR model parameters (intercept and slope) and apply them to my fine resolution raster? In the end I would like to do the same thing as I did with the linear model, that is, GWR_intercept + GWR_slope * fine resolution raster.

Here is the code of 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
$\endgroup$
0

1 Answer 1

0
$\begingroup$

The solution was to use the regression.point argument in the gwr.basic function.

The code:

library(GWmodel)
library(sp)

tirs000 = raster("path/tirs.tif") # high resolution raster
regpoints <- as(tirs, "SpatialPoints")

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

coordinates(block.data) <- c("x", "y")
proj4string(block.data) <- "EPSG:27700"

eq1 <- ntl ~ tirs000 # tirs000 is the coarse version of the high res raster

dist = GWmodel::gw.dist(dp.locat = coordinates(block.data), rp.locat = coordinates(regpoints), focus = 0, p = 2, theta = 0, longlat = FALSE)

abw = bw.gwr(eq1, 
                 data = block.data, 
                 approach = "AIC", 
                 kernel = "gaussian",
                 adaptive = TRUE, 
                 p = 2,
                 parallel.method = "omp",
                 parallel.arg = "omp")

ab_gwr = gwr.predict(eq1, 
        data = block.data, 
        predictdata = regpoints, 
        bw = abw, 
        kernel = "gaussian", 
        adaptive = TRUE, 
        p = 2,
        theta = 0, 
        longlat = FALSE, 
        dMat1 = dist)

sp <- ab_gwr$SDF
sf <- st_as_sf(sp)

# export prediction
gwr_pred = as.data.frame(sf$prediction)
gwr_pred = SpatialPointsDataFrame(data = gwr_pred, coords = regpoints)
gridded(gwr_pred) <- TRUE
gwr_pred <- raster(gwr_pred)
raster::crs(gwr_pred) <- provoliko

gwr_pred[gwr_pred <= 0] <- 0

writeRaster(gwr_pred, 
            paste0(wd, "ntl_gwr.tif"), 
            overwrite = TRUE)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.