Title: | Mitigating Spatial Bias Through Geographical Complexity |
---|---|
Description: | The geographical complexity of individual variables can be characterized by the differences in local attribute variables, while the common geographical complexity of multiple variables can be represented by fluctuations in the similarity of vectors composed of multiple variables. In spatial regression tasks, the goodness of fit can be improved by incorporating a geographical complexity representation vector during modeling, using a geographical complexity-weighted spatial weight matrix, or employing local geographical complexity kernel density. Similarly, in spatial sampling tasks, samples can be selected more effectively by using a method that weights based on geographical complexity. By optimizing performance in spatial regression and spatial sampling tasks, the spatial bias of the model can be effectively reduced. |
Authors: | Wenbo Lv [aut, cre, cph] , Yongze Song [aut] , Zehua Zhang [aut] |
Maintainer: | Wenbo Lv <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2024-11-25 15:10:19 UTC |
Source: | CRAN |
This function calculates geocomplexity for spatial raster data based on spatial dependence.
geocd_raster(r, order = 1, normalize = TRUE, method = "moran")
geocd_raster(r, order = 1, normalize = TRUE, method = "moran")
r |
|
order |
(optional) The order of the adjacency object. Default is |
normalize |
(optional) Whether to further normalizes the calculated geocomplexity.
Default is |
method |
(optional) In instances where the method is |
A SpatRaster
object
In contrast to the geocd_vector()
function, the geocd_raster()
performs operations
internally on raster data based on neighborhood operations(focal) without providing
additional wt object.
Zehua Zhang, Yongze Song, Peng Luo & Peng Wu (2023) Geocomplexity explains spatial errors, International Journal of Geographical Information Science, 37:7, 1449-1469, DOI: 10.1080/13658816.2023.2203212
Anselin, L. (2019). A local indicator of multivariate spatial association: Extending geary’s c. Geographical Analysis, 51(2), 133–150. https://doi.org/10.1111/gean.12164
library(terra) m = matrix(c(3,3,3,3,1,3, 3,3,3,2,1,2, 3,3,3,1,2,1, 1,3,2,2,2,2, 2,2,2,1,1,2, 1,2,1,1,1,1), nrow = 6, byrow = TRUE) m = rast(m) names(m) = 'sim' plot(m, col = c("#d2eaac", "#a3dae1", "#8cc1e1")) gc1 = geocd_raster(m,1) gc2 = geocd_raster(m,2) gc1 plot(gc1) gc2 plot(gc2)
library(terra) m = matrix(c(3,3,3,3,1,3, 3,3,3,2,1,2, 3,3,3,1,2,1, 1,3,2,2,2,2, 2,2,2,1,1,2, 1,2,1,1,1,1), nrow = 6, byrow = TRUE) m = rast(m) names(m) = 'sim' plot(m, col = c("#d2eaac", "#a3dae1", "#8cc1e1")) gc1 = geocd_raster(m,1) gc2 = geocd_raster(m,2) gc1 plot(gc1) gc2 plot(gc2)
constructing spatial weight matrix based on geocomplexity with spatial dependence
geocd_swm(sfj, wt = NULL, style = "B", ...)
geocd_swm(sfj, wt = NULL, style = "B", ...)
sfj |
An |
wt |
(optional) Spatial weight matrix based on spatial adjacency or spatial distance relationships. |
style |
(optional) A character that can be |
... |
(optional) Other parameters passed to |
A matrix
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) wt_gc = geocd_swm(econineq) wt_gc[1:5,1:5]
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) wt_gc = geocd_swm(econineq) wt_gc[1:5,1:5]
This function calculates geocomplexity for spatial vector data based on spatial dependence.
geocd_vector( sfj, wt = NULL, method = "moran", normalize = TRUE, returnsf = TRUE )
geocd_vector( sfj, wt = NULL, method = "moran", normalize = TRUE, returnsf = TRUE )
sfj |
An |
wt |
(optional) Spatial weight matrix. Must be a |
method |
(optional) In instances where the method is |
normalize |
(optional) Whether to further normalizes the calculated geocomplexity.
Default is |
returnsf |
(optional) When |
A tibble
(returnsf
is FALSE
) or an sf
object (returnsf
is TRUE
)
If wt
is not provided, for polygon vector data, geocomplexity
will use a first-order queen
adjacency binary matrix; for point vector data, the six nearest points are used as adjacency
objects to generate an adjacency binary matrix.
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) gc = geocd_vector(econineq) gc library(ggplot2) library(viridis) ggplot(gc) + geom_sf(aes(fill = GC_Gini)) + scale_fill_viridis(option = "mako", direction = -1) + theme_bw()
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) gc = geocd_vector(econineq) gc library(ggplot2) library(viridis) ggplot(gc) + geom_sf(aes(fill = GC_Gini)) + scale_fill_viridis(option = "mako", direction = -1) + theme_bw()
This function calculates geocomplexity for spatial raster data based on geographical similarity.
geocs_raster(r, order = 1, normalize = TRUE, similarity = 1, method = "spvar")
geocs_raster(r, order = 1, normalize = TRUE, similarity = 1, method = "spvar")
r |
|
order |
(optional) The order of the adjacency object. Default is |
normalize |
(optional) Whether to further normalizes the calculated geocomplexity.
Default is |
similarity |
(optional) When |
method |
(optional) When |
A SpatRaster
object
In contrast to the geocs_vector()
function, the geocs_raster()
performs operations
internally on raster data without providing additional wt object.
library(terra) m1 = matrix(c(3,3,3,3,1,3, 3,3,3,2,1,2, 3,3,3,1,2,1, 1,3,2,2,2,2, 2,2,2,1,1,2, 1,2,1,1,1,1), nrow = 6, byrow = TRUE) m1 = rast(m1) names(m1) = 'sim1' m2 = m1 set.seed(123456789) values(m2) = values(m1) + runif(ncell(m1),-1,1) names(m2) = 'sim2' m = c(m1,m2) gc1 = geocs_raster(m,1) gc2 = geocs_raster(m,2) gc1 plot(gc1) gc2 plot(gc2)
library(terra) m1 = matrix(c(3,3,3,3,1,3, 3,3,3,2,1,2, 3,3,3,1,2,1, 1,3,2,2,2,2, 2,2,2,1,1,2, 1,2,1,1,1,1), nrow = 6, byrow = TRUE) m1 = rast(m1) names(m1) = 'sim1' m2 = m1 set.seed(123456789) values(m2) = values(m1) + runif(ncell(m1),-1,1) names(m2) = 'sim2' m = c(m1,m2) gc1 = geocs_raster(m,1) gc2 = geocs_raster(m,2) gc1 plot(gc1) gc2 plot(gc2)
constructing spatial weight matrix based on geocomplexity with similar geographical configurations
geocs_swm(sfj, wt = NULL, style = "B", ...)
geocs_swm(sfj, wt = NULL, style = "B", ...)
sfj |
An |
wt |
(optional) Spatial weight matrix based on spatial adjacency or spatial distance relationships. |
style |
(optional) A character that can be |
... |
(optional) Other parameters passed to |
A matrix
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) wt_gc = geocs_swm(econineq) wt_gc[1:5,1:5]
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) wt_gc = geocs_swm(econineq) wt_gc[1:5,1:5]
This function calculates geocomplexity for in spatial vector data based on geographical similarity.
geocs_vector( sfj, wt = NULL, method = "spvar", similarity = 1, normalize = TRUE, returnsf = TRUE )
geocs_vector( sfj, wt = NULL, method = "spvar", similarity = 1, normalize = TRUE, returnsf = TRUE )
sfj |
An |
wt |
(optional) Spatial weight matrix. Must be a |
method |
(optional) When |
similarity |
(optional) When |
normalize |
(optional) Whether to further normalizes the calculated geocomplexity.
Default is |
returnsf |
(optional) When |
A tibble
(returnsf
is FALSE
) or an sf
object (returnsf
is TRUE
)
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) gc = geocs_vector(dplyr::select(econineq,-Gini)) gc library(ggplot2) library(viridis) ggplot(gc) + geom_sf(aes(fill = GC)) + scale_fill_viridis(option = "mako", direction = -1) + theme_bw()
econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) gc = geocs_vector(dplyr::select(econineq,-Gini)) gc library(ggplot2) library(viridis) ggplot(gc) + geom_sf(aes(fill = GC)) + scale_fill_viridis(option = "mako", direction = -1) + theme_bw()
geographical complexity-geographically weighted regression
gwr_geoc( formula, data, gcs = NULL, alpha = seq(0.05, 1, 0.05), bw = "RMSE", adaptive = TRUE, kernel = "gaussian" )
gwr_geoc( formula, data, gcs = NULL, alpha = seq(0.05, 1, 0.05), bw = "RMSE", adaptive = TRUE, kernel = "gaussian" )
formula |
A formula of |
data |
An |
gcs |
(optional) The geocomplexity matrix corresponding to each variable, which is calculated
by default using |
alpha |
(optional) Balancing the weights of attribute similarity matrix and geographic distance matrix. |
bw |
(optional) The bandwidth used in selecting models. The optimal bandwidth can be selected using one
of three methods: |
adaptive |
(optional) Whether the bandwidth value is adaptive or not. Default is |
kernel |
(optional) Kernel function. Default is |
A list with GCGWR results.
SDF
an sf tibble with coefficients, standard errors and t values
diagnostic
goodness of fit indicators
args
some key parameters
## The following code takes a long time to run: econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) g = gwr_geoc(formula = Gini ~ ., data = econineq, alpha = 0.5, bw = "AIC", adaptive = TRUE) g
## The following code takes a long time to run: econineq = sf::read_sf(system.file('extdata/econineq.gpkg',package = 'geocomplexity')) g = gwr_geoc(formula = Gini ~ ., data = econineq, alpha = 0.5, bw = "AIC", adaptive = TRUE) g