Current version: GD v1.10
Recommendation: Understanding Spatial Stratified Heterogeneity Using R
GD
To cite GD
R package in publications, please use:
Song, Y., Wang, J., Ge, Y. & Xu, C. (2020) “An optimal parameters-based geographical detector model enhances geographic characteristics of explanatory variables for spatial heterogeneity analysis: Cases with different types of spatial data”, GIScience & Remote Sensing. 57(5), 593-610. doi: 10.1080/15481603.2020.1760434.
GD
packageExplore potential factors or explanatory variables from a spatial perspective.
Explore potential interactive impacts of geogrpahical variables.
Identify high-risk or low-risk regions from potential explanatory variables.
GD
package makes following steps fast and easy:It contains both supervised and unsupervised spatial data discretization methods, and the optimal spatial discretization method for continuous variables;
It contains four primary functions of geographical detectors, including factor detector, risk detector, interaction detector and ecological detector;
It can be used to compare size effects of spatial unit;
It provides diverse visualizations of spatial analysis results;
It contains detailed significance tests for spatial analysis in each step of geographical detectors.
gdm
(Highly Recommended)The pacakge provides a one-step function for performing optimal discretization and geographical detectors at the same time.
The output contains all data and visualization results.
## install and library the pacakge
install.packages("GD")
library("GD")
## Example 1
## NDVI: ndvi_40
## set optional parameters of optimal discretization
## optional methods: equal, natural, quantile, geometric, sd and manual
<- c("equal","natural","quantile")
discmethod <- c(4:6)
discitv ## "gdm" function
## In this case, Climatezone and Mining are categorical variables,
## and Tempchange and GDP are continuous variables.
<- gdm(NDVIchange ~ Climatezone + Mining + Tempchange + GDP,
ndvigdm continuous_variable = c("Tempchange", "GDP"),
data = ndvi_40,
discmethod = discmethod, discitv = discitv) # ~3s
ndvigdmplot(ndvigdm)
## Example 2
## H1N1: h1n1_100
## set optional parameters of optimal discretization
<- c("equal","natural","quantile","geometric","sd")
discmethod <- c(3:7)
discitv <- colnames(h1n1_100)[-c(1,11)]
continuous_variable ## "gdm" function
<- gdm(H1N1 ~ .,
h1n1gdm continuous_variable = continuous_variable,
data = h1n1_100,
discmethod = discmethod, discitv = discitv)
h1n1gdmplot(h1n1gdm)
Spatial stratified heterogeneity can be measured using geographical detectors (Wang et al. 2010, Wang et al. 2016).
Power of determinants is computed using a \(Q\)-statistic:
\[Q=1-\displaystyle \frac{\sum_{j=1}^{M} N_{j} \sigma_{j}^2}{N \sigma^2} \]
where \(N\) and \(\sigma^2\) are the number and population variance of observations within the whole study area, and \(N_{j}\) and \(\sigma_{j}^2\) are the number and population variance of observations within the \(j\) th (\(j\)=1,…,\(M\)) sub-region of an explantory variable.
Please note that in R
environment, sd
and var
functions are used for computing sample standard deviation and sample variance. If sample variance is used in the computation, the equation of \(Q\)-statistic can be converted to:
\[Q=1-\displaystyle \frac{\sum_{j=1}^{M} (N_{j}-1) s_{j}^2}{(N-1) s^2} \]
where \(s^2\) and \(s_{j}^2\) are sample variance of observations in the whole study area and in the \(j\) th sub-region.
Further information can be found on the manual of GD package.
More applications of geographical detectors are listed on Geodetector website.
Categorical variables are required for geographical detectors, so continuous variables should be discretized before modelling. GD package provides two options: discretization with given parameters, including discretization methods and numbers of intervals, and optimal discretization with a series of optional parameter combinations. Dataset ndvi_40
is used as an example for explanation.
install.packages("GD")
library("GD")
## This is GD 1.10.
##
## To cite GD in publications, please use:
##
## Song, Y., Wang, J., Ge, Y. & Xu, C. (2020) An optimal parameters-based geographical detector model enhances geographic characteristics of explanatory variables for spatial heterogeneity analysis: Cases with different types of spatial data, GIScience & Remote Sensing, 57(5), 593-610. doi: 10.1080/15481603.2020.1760434.
##
data("ndvi_40")
head(ndvi_40)[1:3,]
## NDVIchange Climatezone Mining Tempchange Precipitation GDP Popdensity
## 1 0.11599 Bwk low 0.25598 236.54 12.55 1.44957
## 2 0.01783 Bwk low 0.27341 213.55 2.69 0.80124
## 3 0.13817 Bsk low 0.30247 448.88 20.06 11.49432
disc
## discretization methods: equal, natural, quantile (default), geometric, sd and manual
<- disc(ndvi_40$Tempchange, 4)
ds1
ds1plot(ds1)
Further information can be found on the manual of GD package.
optidisc
## set optional discretization methods and numbers of intervals
<- c("equal","natural","quantile","geometric","sd")
discmethod <- c(4:7)
discitv ## optimal discretization
<- optidisc(NDVIchange ~ Tempchange, data = ndvi_40,
odc1
discmethod, discitv)
odc1plot(odc1)
GD package provides two options for geographical detectors modelling:
four functions are performed step by step: gd
for factor detector, riskmean
and gdrisk
for risk detector, gdinteract
for interaction detector and gdeco
for ecological detector;
optimal discretization and geographical detectors are performed using a one-step function gdm
.
gd
## a categorical explanatory variable
<- gd(NDVIchange ~ Climatezone, data = ndvi_40)
g1
g1
## multiple categorical explanatory variables
<- gd(NDVIchange ~ ., data = ndvi_40[,1:3])
g2
g2plot(g2)
## multiple variables including continuous variables
<- c("equal","natural","quantile","geometric","sd")
discmethod <- c(3:7)
discitv <- ndvi_40
data.ndvi
<- data.ndvi[, c(1, 4:7)]
data.continuous <- optidisc(NDVIchange ~ ., data = data.continuous, discmethod, discitv) # ~14s
odc1 <- do.call(cbind, lapply(1:4, function(x)
data.continuous data.frame(cut(data.continuous[, -1][, x], unique(odc1[[x]]$itv), include.lowest = TRUE))))
# add stratified data to explanatory variables
4:7] <- data.continuous
data.ndvi[,
<- gd(NDVIchange ~ ., data = data.ndvi)
g3
g3plot(g3)
riskmean
and gdrisk
Risk mean values by variables:
## categorical explanatory variables
<- riskmean(NDVIchange ~ Climatezone + Mining, data = ndvi_40)
rm1
rm1plot(rm1)
## multiple variables inclusing continuous variables
<- riskmean(NDVIchange ~ ., data = data.ndvi)
rm2
rm2plot(rm2)
Risk matrix:
## categorical explanatory variables
<- gdrisk(NDVIchange ~ Climatezone + Mining, data = ndvi_40)
gr1
gr1plot(gr1)
## multiple variables inclusing continuous variables
<- gdrisk(NDVIchange ~ ., data = data.ndvi)
gr2
gr2plot(gr2)
gdinteract
## categorical explanatory variables
<- gdinteract(NDVIchange ~ Climatezone + Mining, data = ndvi_40)
gi1
gi1## multiple variables inclusing continuous variables
<- gdinteract(NDVIchange ~ ., data = data.ndvi)
gi2
gi2plot(gi2)
gdeco
## categorical explanatory variables
<- gdeco(NDVIchange ~ Climatezone + Mining, data = ndvi_40)
ge1
ge1## multiple variables inclusing continuous variables
<- gdeco(NDVIchange ~ ., data = data.ndvi)
gd3
gd3plot(gd3)
<- list(ndvi_20, ndvi_30, ndvi_40, ndvi_50)
ndvilist <- c(20,30,40,50) ## sizes of spatial units
su ## "gdm" function
<- lapply(ndvilist, function(x){
gdlist gdm(NDVIchange ~ Climatezone + Mining + Tempchange + GDP,
continuous_variable = c("Tempchange", "GDP"),
data = x, discmethod = "quantile", discitv = 6)
})sesu(gdlist, su) ## size effects of spatial units
Song Y, Wang J, Ge Y and Xu C (2020) “An optimal parameters-based geographical detector model enhances geographic characteristics of explanatory variables for spatial heterogeneity analysis: Cases with different types of spatial data.” GIScience & Remote Sensing, 57(5), pp. 593-610. doi: 10.1080/15481603.2020.1760434.
Song Y, Wright G, Wu P, Thatcher D, McHugh T, Li Q, Li SJ and Wang X (2018). “Segment-Based Spatial Analysis for Assessing Road Infrastructure Performance Using Monitoring Observations and Remote Sensing Data”. Remote Sensing, 10(11), pp. 1696. doi: 10.3390/rs10111696.
Song Y, Wu P, Gilmore D and Li Q (2020). “A Spatial Heterogeneity-Based Segmentation Model for Analyzing Road Deterioration Network Data in Multi-Scale Infrastructure Systems.” IEEE Transactions on Intelligent Transportation Systems. doi: 10.1109/TITS.2020.3001193.
Wang J, Li X, Christakos G, Liao Y, Zhang T, Gu X and Zheng X (2010). “Geographical Detectors-Based Health Risk Assessment and its Application in the Neural Tube Defects Study of the Heshun Region, China.” International Journal of Geographical Information Science, 24(1), pp. 107-127. doi: 10.1080/13658810802443457.
Wang J, Zhang T and Fu B (2016). “A measure of spatial stratified heterogeneity.” Ecological Indicators, 67, pp. 250-256. doi: 10.1016/j.ecolind.2016.02.052.