Skip to contents

The Local Geary is a local adaptation of Geary's C statistic of spatial autocorrelation. The Local Geary uses squared differences to measure dissimilarity unlike the Local Moran. Low values of the Local Geary indicate positive spatial autocorrelation and large refers to negative spatial autocorrelation.

Inference for the Local Geary is based on a permutation approach which compares the observed value to the reference distribution under spatial randomness. localC_perm() returns a pseudo p-value. This is not an analytical p-value and is based on the number of permutations and as such should be used with care.

Usage

localC(x, ..., zero.policy=NULL)

# Default S3 method
localC(x, listw, ..., zero.policy=attr(listw, "zero.policy"))

# S3 method for class 'formula'
localC(formula, data, listw, ..., zero.policy=attr(listw, "zero.policy"))

# S3 method for class 'list'
localC(x, listw, ..., zero.policy=attr(listw, "zero.policy"))

# S3 method for class 'matrix'
localC(x, listw, ..., zero.policy=attr(listw, "zero.policy"))

# S3 method for class 'data.frame'
localC(x, listw, ..., zero.policy=attr(listw, "zero.policy"))

localC_perm(x, ..., zero.policy=NULL, iseed=NULL, no_repeat_in_row=FALSE)

# Default S3 method
localC_perm(x, listw, nsim = 499, alternative = "two.sided", ...,
 zero.policy=attr(listw, "zero.policy"), iseed=NULL, no_repeat_in_row=FALSE)

# S3 method for class 'formula'
localC_perm(formula, data, listw, nsim = 499,
 alternative = "two.sided", ..., zero.policy=attr(listw, "zero.policy"), iseed=NULL,
 no_repeat_in_row=FALSE)

Arguments

x

a numeric vector, numeric matrix, or list. See details for more.

formula

A one-sided formula determining which variables to be used.

listw

a listw object created for example by nb2listw.

data

Used when a formula is provided. A matrix or data frame containing the variables in the formula formula.

nsim

The number of simulations to be used for permutation test.

alternative

A character defining the alternative hypothesis. Must be one of "two.sided", "less" or "greater".

...

other arguments passed to methods.

zero.policy

default attr(listw, "zero.policy") as set when listw was created, if attribute not set, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE assign NA.

iseed

default NULL, used to set the seed;the output will only be reproducible if the count of CPU cores across which computation is distributed is the same

no_repeat_in_row

default FALSE, if TRUE, sample conditionally in each row without replacements to avoid duplicate values, https://github.com/r-spatial/spdep/issues/124

Details

The Local Geary can be extended to a multivariate context. When x is a numeric vector, the univariate Local Geary will be calculated. To calculate the multivariate Local Moran provide either a list or a matrix. When x is a list, each element must be a numeric vector of the same length and of the same length as the neighbours in listw. In the case that x is a matrix the number of rows must be the same as the length of the neighbours in listw.

While not required in the univariate context, the standardized Local Geary is calculated. The multivariate Local Geary is always standardized.

The univariate Local Geary is calculated as \(c_i = \sum_j w_{ij}(x_i - x_j)^2\) and the multivariate Local Geary is calculated as \(c_{k,i} = \sum_{v=1}^{k} c_{v,i}\) as described in Anselin (2019).

Value

A numeric vector containing Local Geary statistic with attribute pseudo-p when localC_perm() is used. pseudo-p is an 8 column matrix containing

E.Ci

expectation of the Local Geary statistic based on permutation sample

Var.Ci

variance of Local Geary based on permutation sample

Z.Ci

standard deviate of Local Geary based on permutation sample

Pr()

p-value of Local Geary statistic using pnorm() using standard deviates based on permutation sample means and standard deviations

Pr() Sim

rank() and punif() of observed statistic rank for [0, 1] p-values using alternative=

Pr(folded) Sim

the simulation folded [0, 0.5] range ranked p-value (based on https://github.com/pysal/esda/blob/4a63e0b5df1e754b17b5f1205b8cadcbecc5e061/esda/crand.py#L211-L213)

Skewness

the output of e1071::skewness() for the permutation samples underlying the standard deviates

Kurtosis

the output of e1071::kurtosis() for the permutation samples underlying the standard deviates

References

Anselin, L. (1995), Local Indicators of Spatial Association—LISA. Geographical Analysis, 27: 93-115. doi:10.1111/j.1538-4632.1995.tb00338.x

Anselin, L. (2019), A Local Indicator of Multivariate Spatial Association: Extending Gearys c. Geogr Anal, 51: 133-150. doi:10.1111/gean.12164

Author

Josiah Parry josiah.parry@gmail.com and Roger Bivand

Examples

orig <- spData::africa.rook.nb
listw <- nb2listw(orig)
x <- spData::afcon$totcon

(A <- localC(x, listw))
#>  [1] 0.39025457 0.50460439 0.15303047 2.90814878 3.40006901 0.17103368
#>  [7] 0.29947832 0.72444806 2.30617282 5.70252541 2.23161263 0.17833029
#> [13] 0.18420002 0.18680408 0.37851643 0.11056720 0.14814835 0.17257920
#> [19] 0.03254150 0.18992772 0.08749322 3.71970760 0.09566918 0.26112918
#> [25] 0.09505331 2.99934478 1.17465032 1.64868780 0.87901004 0.05909537
#> [31] 2.54591475 3.85570655 2.99413462 0.96084992 0.80678832 1.56869350
#> [37] 0.86422915 0.38817470 0.23425755 1.26191610 1.34455327 1.80707481
listw1 <- nb2listw(droplinks(sym.attr.nb(orig), 3, sym=TRUE), zero.policy=TRUE)
#> Warning: some observations have no neighbours
#> Warning: neighbour object has 2 sub-graphs
(A1 <- localC(x, listw1, zero.policy=FALSE))
#>  [1] 0.39025457 0.57491918         NA 2.90814878 3.40006901 0.17103368
#>  [7] 0.29947832 0.72444806 2.30617282 5.70252541 2.23161263 0.17833029
#> [13] 0.18420002 0.18680408 0.37851643 0.11056720 0.14814835 0.17257920
#> [19] 0.03254150 0.18992772 0.08749322 3.71970760 0.09566918 0.26112918
#> [25] 0.09505331 2.99934478 1.17465032 1.64868780 0.87901004 0.05909537
#> [31] 2.54591475 3.85570655 2.99413462 0.96084992 0.80678832 1.56869350
#> [37] 0.86422915 0.38817470 0.23425755 1.26191610 1.34455327 1.80707481
(A2 <- localC(x, listw1, zero.policy=TRUE))
#>  [1] 0.39025457 0.57491918 0.00000000 2.90814878 3.40006901 0.17103368
#>  [7] 0.29947832 0.72444806 2.30617282 5.70252541 2.23161263 0.17833029
#> [13] 0.18420002 0.18680408 0.37851643 0.11056720 0.14814835 0.17257920
#> [19] 0.03254150 0.18992772 0.08749322 3.71970760 0.09566918 0.26112918
#> [25] 0.09505331 2.99934478 1.17465032 1.64868780 0.87901004 0.05909537
#> [31] 2.54591475 3.85570655 2.99413462 0.96084992 0.80678832 1.56869350
#> [37] 0.86422915 0.38817470 0.23425755 1.26191610 1.34455327 1.80707481


if (FALSE) { # \dontrun{
library(reticulate)
use_python("/usr/bin/python", required = TRUE)
gp <- import("geopandas")
ps <- import("libpysal")
W <- listw2mat(listw)
w <- ps$weights$full2W(W, rownames(W))
w$transform <- "R"
esda <- import("esda")
lM <- esda$Moran_Local(x, w)
all.equal(unname(localmoran(x, listw, mlvar=FALSE)[,1]), c(lM$Is))
# confirm x and w the same
lC <- esda$Geary_Local(connectivity=w)$fit(scale(x))
# np$std missing ddof=1
n <- length(x)
D0 <- spdep:::geary.intern((x - mean(x)) / sqrt(var(x)*(n-1)/n), listw, n=n)
# lC components probably wrongly ordered https://github.com/pysal/esda/issues/192
o <- match(round(D0, 6), round(lC$localG, 6))
all.equal(c(lC$localG)[o], D0)
# simulation order not retained
lC$p_sim[o]
attr(C, "pseudo-p")[,6]
} # }