| Title: | Fast Local Indicators of Spatial Association (LISA) |
|---|---|
| Description: | Computes various Local Indicators of Spatial Association (LISA) statistics, including univariate and bivariate local Moran's I, Empirical Bayes local Moran's I, univariate and multivariate local Geary's C, and Getis-Ord G and G* statistics. The methods follow Anselin (1995), Getis and Ord (1992), and Anselin (2019). Leverages a high-performance, plain-C backend with optional 'OpenMP' multi-core support for fast permutation-based pseudo-p-value calculation. Accepts any 'spdep' listw spatial weight matrix, including custom and non-contiguity weights. Uses sample standardisation (n-1) and 'rgeoda'-style permutation p-values. Output cluster codes match 'rgeoda' conventions, including the Isolated category for observations without neighbours. |
| Authors: | Lizhong Chen [aut, cre] |
| Maintainer: | Lizhong Chen <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.1 |
| Built: | 2026-07-07 08:30:11 UTC |
| Source: | https://github.com/lizhongc/fastlisa |
local_g computes the Getis-Ord local statistic, a Local
Indicator of Spatial Association that detects local clustering of high values
(“hot spots”) and low values (“cold spots”). For observation
, with row-standardised spatial weights and the focal
value excluded from both the lag and the denominator,
A large indicates that is surrounded by high values; a small
indicates a low-value neighbourhood. contains no self term;
see local_gstar for the self-inclusive .
local_g( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_g( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
x |
Numeric vector of length |
listw |
A |
nsim |
Integer; number of permutations. Default |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Inference uses a conditional permutation test: the focal value is held
fixed while the neighbouring values are randomly permuted nsim times. The
pseudo p-value is folded (two-tailed),
where is the number of permutations with
. The standardised score is
,
computed from the permutation mean and variance; Skew.Gi and
Kurt.Gi (when moments = TRUE) follow the e1071 type-3
convention.
Observations with a missing x value are labelled Undefined and
observations with no neighbours are labelled Isolated; both receive
NA for the p-value, Z-score and moments. The C backend re-seeds its
random number generator per observation, so results are identical for any
n.cores; n.cores is ignored when the package is built without
OpenMP.
A numeric matrix of class c("localG", "matrix", "array")
with columns Gi, Z.Gi, and Pr(folded) Sim.
When moments = TRUE, the permutation-moment columns are appended.
It has the following attributes:
A significance-filtered factor with levels
Not significant, High-High, Low-Low,
Undefined and Isolated.
Logical flag set to FALSE indicating local G (not G*).
The matched call.
Getis, A. and Ord, J. K. (1992) The Analysis of Spatial Association by Use of Distance Statistics. Geographical Analysis 24(3), 189–206. doi:10.1111/j.1538-4632.1992.tb00261.x
Ord, J. K. and Getis, A. (1995) Local Spatial Autocorrelation Statistics: Distributional Issues and an Application. Geographical Analysis 27(4), 286–306. doi:10.1111/j.1538-4632.1995.tb00912.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_g(x, lw, nsim = 99L, n.cores = 1L) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_g(x, lw, nsim = 99L, n.cores = 1L) head(res)
local_geary computes the univariate local Geary's , a
squared-difference Local Indicator of Spatial Association that measures how much a
unit differs from its neighbours. On the sample () standardised variable
(when scale = TRUE) with row-standardised weights ,
A small means resembles its neighbours (positive spatial
association); a large means it differs from them (negative association,
a spatial outlier).
local_geary( x, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_geary( x, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
x |
Numeric vector of length |
listw |
A |
nsim |
Integer; number of permutations. Default |
scale |
Logical; if |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Inference uses a one-tailed conditional permutation test (nsim reps): the
observed is compared with the permutation mean to select the tail, and
where counts permuted statistics in that tail. The standardised score is
;
Skew.Ci/Kurt.Ci (when moments = TRUE) follow the e1071
type-3 convention. The cluster factor splits significant positive
association into High-High/Low-Low/Other Positive and labels
significant dissimilarity Negative.
Observations with a missing x value are labelled Undefined and
observations with no neighbours are labelled Isolated; both receive
NA for the p-value, Z-score and moments. The C backend re-seeds its
random number generator per observation, so results are identical for any
n.cores; n.cores is ignored when the package is built without
OpenMP.
A numeric matrix of class c("localC", "matrix", "array")
with columns Ci, Z.Ci, and Pr Sim. When
moments = TRUE, the permutation-moment columns are appended.
It has the following attributes:
A significance-filtered factor with levels Not significant, High-High, Low-Low, Other Positive, Negative, Undefined, and Isolated.
The matched call.
Anselin, L. (1995) Local Indicators of Spatial Association—LISA. Geographical Analysis 27(2), 93–115. doi:10.1111/j.1538-4632.1995.tb00338.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_geary(x, lw, nsim = 99L, n.cores = 1L) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_geary(x, lw, nsim = 99L, n.cores = 1L) head(res)
local_gstar computes the Getis-Ord local statistic, the
self-inclusive companion of local_g: observation is treated
as its own neighbour (weight 1). With valid neighbours, row-standardised
neighbour weights , and global total ,
i.e. the average value over the focal unit and its neighbours divided by the
global sum. Large flags a hot spot and small a cold spot,
with the focal unit included.
local_gstar( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_gstar( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
x |
Numeric vector of length |
listw |
A |
nsim |
Integer; number of permutations. Default |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Inference uses a conditional permutation test (nsim reps), with the focal
held fixed while neighbour values are permuted. The pseudo p-value is
folded (two-tailed),
where counts permutations with
. The standardised score
uses the permutation moments; Skew.G*i/Kurt.G*i (when
moments = TRUE) follow the e1071 type-3 convention.
Observations with a missing x value are labelled Undefined and
observations with no neighbours are labelled Isolated; both receive
NA for the p-value, Z-score and moments. The C backend re-seeds its
random number generator per observation, so results are identical for any
n.cores; n.cores is ignored when the package is built without
OpenMP.
A numeric matrix of class c("localG", "matrix", "array")
with columns G*i, Z.G*i, and Pr(folded) Sim.
When moments = TRUE, the permutation-moment columns are appended.
It has the following attributes:
A significance-filtered factor with levels
Not significant, High-High, Low-Low,
Undefined and Isolated.
Logical flag set to TRUE indicating local G*.
The matched call.
Getis, A. and Ord, J. K. (1992) The Analysis of Spatial Association by Use of Distance Statistics. Geographical Analysis 24(3), 189–206. doi:10.1111/j.1538-4632.1992.tb00261.x
Ord, J. K. and Getis, A. (1995) Local Spatial Autocorrelation Statistics: Distributional Issues and an Application. Geographical Analysis 27(4), 286–306. doi:10.1111/j.1538-4632.1995.tb00912.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_gstar(x, lw, nsim = 99L, n.cores = 1L) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_gstar(x, lw, nsim = 99L, n.cores = 1L) head(res)
local_moran computes the univariate local Moran's , the classic
Local Indicator of Spatial Association measuring whether a value coincides with
its neighbours' average. On the sample () standardised variable
with row-standardised weights ,
A positive indicates similarity to neighbours (a High-High or Low-Low
cluster); a negative indicates a spatial outlier (High-Low or
Low-High). Standardisation uses the sample standard deviation (
denominator).
local_moran( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_moran( x, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
x |
Numeric vector of length |
listw |
A |
nsim |
Integer; number of permutations. Default |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
This is the special case of bivariate local Moran's I, so the
computation delegates to local_moran_bv (with scale = TRUE)
and relabels the columns. Inference uses a conditional permutation test
(nsim reps) with the folded two-tailed pseudo p-value
, where is the
number of permutations with . The
standardised score is
and
Skew.Ii/Kurt.Ii (when moments = TRUE) use the e1071
type-3 convention. NA observations are Undefined and neighbourless
observations are Isolated (both NA in p-value, Z-score and moments).
The C backend re-seeds its random number generator per observation, so results
are identical for any n.cores.
A numeric matrix of class c("localmoran", "matrix", "array")
with n rows and 3 columns by default:
Observed univariate Moran statistic.
Standardised Z-score computed from permutation moments.
rgeoda-style folded empirical permutation p-value.
When moments = TRUE, the permutation-distribution columns
E.Ii, Var.Ii, Skew.Ii, and Kurt.Ii are
appended.
The matrix has the following attributes:
Moran scatter-plot quadrant classification.
A significance-filtered factor with levels
Not significant, High-High, Low-Low, Low-High,
High-Low, Undefined and Isolated.
Anselin, L. (1995) Local Indicators of Spatial Association—LISA. Geographical Analysis 27(2), 93–115. doi:10.1111/j.1538-4632.1995.tb00338.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_moran(x, lw, nsim = 99L, n.cores = 1L, moments = TRUE) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) res <- local_moran(x, lw, nsim = 99L, n.cores = 1L, moments = TRUE) head(res)
local_moran_bv computes the bivariate local Moran's , which
correlates a variable at with the spatial lag of a second
variable over 's neighbours. On the sample () standardised
variables (when scale = TRUE) with row-standardised weights
,
A positive means 's value coincides with high lagged
nearby; a negative value indicates spatial mismatch. The univariate local
Moran's I is the special case (see local_moran). The
backend is plain C with optional OpenMP parallelism.
local_moran_bv( x, y, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_moran_bv( x, y, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
x |
Numeric vector of length |
y |
Numeric vector of length |
listw |
A |
nsim |
Integer; number of permutations for the pseudo p-value.
Default |
scale |
Logical; if |
iseed |
Integer seed for the RNG, or |
p.value |
Numeric; observations with
|
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Inference uses a conditional permutation test (nsim reps): the neighbour
-values are permuted with the focal observation held fixed. See the
P-values and Cluster codes sections below for the folded p-value and
the cluster coding. The standardised score is
;
Skew.Ibvi/Kurt.Ibvi (when moments = TRUE) follow the
e1071 type-3 convention. NA observations are Undefined and
neighbourless observations are Isolated (both NA in p-value, Z-score
and moments). The C backend re-seeds its random number generator per observation,
so results are identical for any n.cores.
A numeric matrix of class c("localmoran", "matrix", "array")
with n rows and 3 columns by default:
Observed bivariate Moran statistic.
Standardised Z-score computed from permutation moments.
rgeoda-style folded empirical permutation p-value.
When moments = TRUE, the permutation-distribution columns
E.Ibvi, Var.Ibvi, Skew.Ibvi, and Kurt.Ibvi
are appended.
The matrix has the following attributes:
A data.frame with three factor columns
(mean, median, pysal) giving the Moran
scatter-plot quadrant for each observation, computed on the original
(unscaled) data scale.
A factor representing cluster classification
(Not significant, High-High, Low-Low, Low-High, High-Low, Undefined, Isolated).
The matched call.
Both x and y are standardised using the sample
standard deviation ( denominator) in R before computing the
statistic, consistent with the blisa backend.
Permutation p-values use the folded two-tailed formula matching rgeoda:
No normal approximation is computed.
The returned cluster factor attribute is based on integer codes 0–6:
| 0 | Not significant |
| 1 | High-High |
| 2 | Low-Low |
| 3 | Low-High |
| 4 | High-Low |
| 5 | Undefined (NA input) |
| 6 | Isolated (no neighbours) |
Codes 5 and 6 are preserved regardless of the significance cutoff.
Anselin, L. (1995) Local Indicators of Spatial Association—LISA. Geographical Analysis 27(2), 93–115. doi:10.1111/j.1538-4632.1995.tb00338.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) y <- rev(x) res <- local_moran_bv(x, y, lw, nsim = 99L, n.cores = 1L, moments = TRUE) head(res) attr(res, "quadr")lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) y <- rev(x) res <- local_moran_bv(x, y, lw, nsim = 99L, n.cores = 1L, moments = TRUE) head(res) attr(res, "quadr")
local_moran_eb computes local Moran's I on Empirical Bayes (EB)
variance-stabilised rates, for event-count data observed over a population at
risk. Raw rates from small
populations are noisy; EB standardisation shrinks them toward the global rate
using a variance component
,
and local Moran's I is then computed on . This follows the GeoDa/libgeoda
EBLocalMoran formulation.
local_moran_eb( event, base, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_moran_eb( event, base, listw, nsim = 999L, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
event |
Numeric vector of events (e.g. case counts). |
base |
Numeric vector of populations at risk. |
listw |
A |
nsim |
Integer; number of permutations. Default |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Two standardisations are applied and are not redundant: the EB rate
standardisation above stabilises the rate variance, and the usual sample
() z-score standardisation that local Moran's I requires is then applied
to the EB rates internally. Because univariate Moran's I on a standardised
variable equals the bivariate statistic with , the permutation engine
is reused via local_moran_bv. Inference is a conditional
permutation test (nsim reps); the folded two-tailed pseudo p-value and the
score
are as in local_moran, and Skew.Ii/Kurt.Ii (when
moments = TRUE) use the e1071 type-3 convention.
Observations with NA event/base or base are
labelled Undefined; observations with no neighbours are Isolated;
both receive NA for the p-value, Z-score and moments. The C backend
re-seeds its random number generator per observation, so results are identical
for any n.cores.
A numeric matrix of class c("local_moran_eb", "matrix") with
n rows and 3 columns by default:
Observed Local Moran statistic computed on EB-standardised rates.
Standardised Z-score computed from permutation moments.
Folded empirical permutation p-value.
When moments = TRUE, the permutation-distribution columns
E.Ii, Var.Ii, Skew.Ii, and Kurt.Ii are
appended.
The matrix has the following attributes:
Moran scatter-plot quadrant classification.
A significance-filtered factor with levels
Not significant, High-High, Low-Low, Low-High,
High-Low, Undefined and Isolated.
The matched call.
Number of simulations used.
Assunção, R. M. and Reis, E. A. (1999) A new proposal to adjust Moran's I for population density. Statistics in Medicine 18(16), 2147–2162. doi:10.1002/(SICI)1097-0258(19990830)18:16<2147::AID-SIM179>3.0.CO;2-I
Anselin, L. (1995) Local Indicators of Spatial Association—LISA. Geographical Analysis 27(2), 93–115. doi:10.1111/j.1538-4632.1995.tb00338.x
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) event <- as.numeric(seq_len(49)) base <- rep(100, 49) res <- local_moran_eb(event, base, lw, nsim = 99L, n.cores = 1L) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) event <- as.numeric(seq_len(49)) base <- rep(100, 49) res <- local_moran_eb(event, base, lw, nsim = 99L, n.cores = 1L) head(res)
local_multigeary computes the multivariate local Geary's
(Anselin 2019), the average across variables of the univariate
squared-difference statistic. On the sample () standardised variables
(when scale = TRUE) with row-standardised weights
,
A small indicates that is similar to its neighbours across all
variables (positive association); a large indicates multivariate
dissimilarity (a spatial outlier).
local_multigeary( df, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )local_multigeary( df, listw, nsim = 999L, scale = TRUE, iseed = NULL, p.value = 0.05, n.cores = 1L, moments = FALSE, p.method = c("count", "rank") )
df |
A data.frame or matrix with selected variables. |
listw |
A |
nsim |
Integer; number of permutations. Default |
scale |
Logical; if |
iseed |
Integer seed for RNG, or |
p.value |
Numeric significance cutoff. Default |
n.cores |
Integer; number of OpenMP threads. Default |
moments |
Logical; if |
p.method |
Character; how the observed statistic is located within its
permutation distribution. |
Inference uses a one-tailed conditional permutation test (nsim reps); each
replicate applies the same permuted neighbour configuration to every variable.
The observed is compared with the permutation mean to choose the tail,
and , where counts permuted
statistics in that tail. The standardised score is
;
Skew.Ci/Kurt.Ci (when moments = TRUE) follow the e1071
type-3 convention. Significant units are labelled Positive (similar) or
Negative (dissimilar).
Rows with any missing value are labelled Undefined and observations with
no neighbours are labelled Isolated; both receive NA for the
p-value, Z-score and moments. The C backend re-seeds its random number generator
per observation, so results are identical for any n.cores; n.cores
is ignored when the package is built without OpenMP.
A numeric matrix of class c("localC", "matrix", "array")
with columns Ci, Z.Ci, and Pr Sim. When
moments = TRUE, the permutation-moment columns are appended.
It has the following attributes:
A significance-filtered factor with levels Not significant, Positive, Negative, Undefined, and Isolated.
The matched call.
Anselin, L. (2019) A Local Indicator of Multivariate Spatial Association: Extending Geary's c. Geographical Analysis 51(2), 133–150. doi:10.1111/gean.12164
lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) df <- cbind(x, rev(x)) res <- local_multigeary(df, lw, nsim = 99L, n.cores = 1L) head(res)lw <- spdep::nb2listw(spdep::cell2nb(7, 7)) x <- as.numeric(seq_len(49)) df <- cbind(x, rev(x)) res <- local_multigeary(df, lw, nsim = 99L, n.cores = 1L) head(res)