esda.G_Local

class esda.G_Local(y, w, transform='R', permutations=999, star=False, keep_simulations=True, n_jobs=-1, seed=None, island_weight=0, alternative=None)[source]

Generalized Local G Autocorrelation

Parameters:
y : array

Variable.

w : W | Graph

Spatial weights instance as W or Graph aligned with y.

transform : {'R', 'B'}

The type of w, either ‘B’ (binary) or ‘R’ (row-standardized).

permutations : int

The number of random permutations for calculating pseudo p-values.

star : bool or float

Whether to include focal observation in sums (default: False). If the row-transformed weight is provided, then this is the default value to use within the spatial lag. Generally, weights should be provided in binary form, and standardization/self-weighting will be handled by the function itself.

seed : None or int

Seed to ensure reproducibility of conditional randomizations. Must be set here, and not outside of the function, since numba does not correctly interpret external seeds nor numpy.random.RandomState instances.

island_weight : float

Value to use as a weight for the “fake” neighbor for every island. If numpy.nan, will propagate to the final local statistic depending on the stat_func. If 0, then the lag is always zero for islands.

alternative : None or str, optional

The alternative hypothesis for conditional randomization. See crand.crand() for complete description.

y[source]

Original variable.

Type:

array

w[source]

Spatial weights instance as W or Graph aligned with y.

Type:

W | Graph

permutations[source]

The number of permutations.

Type:

int

Gs[source]

Values of the original G statistic in Getis & Ord (1992).

Type:

array

EGs[source]

Expected value of Gs under the normality assumption. The value is scalar, since the expectation is identical across all observations.

Type:

float

VGs[source]

Variance values of Gs under the normality assumption.

Type:

array

Zs[source]

Standardized Gs.

Type:

array

p_norm[source]

P-values under the normality assumption (one-sided). For two-sided tests, this value should be multiplied by 2.

Type:

array

sim[source]

Array of simulated statistic values (if permutations > 0).

Type:

array

p_sim[source]

P-values based on permutations (one-sided). The null is spatial randomness; the alternative is that the observed G is extreme.

Type:

array

EG_sim[source]

Average value of G from permutations.

Type:

array

VG_sim[source]

Variance of G from permutations.

Type:

array

seG_sim[source]

Standard deviation of G under permutations.

Type:

array

z_sim[source]

Standardized G based on permutations.

Type:

array

p_z_sim[source]

P-values based on the standard normal approximation from permutations (one-sided).

Type:

array

Notes

To compute moments of Gs under the normality assumption, PySAL considers w to be either binary or row-standardized. For a binary weights object, the weight value for self is 1. For a row-standardized weights object, the weight value for self is 1 / (the number of its neighbors + 1).

For technical details see [Getis and Ord, 2010] and [Ord and Getis, 2010].

Examples

>>> import libpysal

Preparing a point data set.

>>> points = [(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]

Creating a weights object from points.

>>> w = libpysal.weights.DistanceBand(points, threshold=15)

Preparing a variable.

>>> import numpy
>>> y = numpy.array([2, 3, 3.2, 5, 8, 7])

Applying Getis and Ord local G test using a binary weights object.

>>> from esda import G_Local
>>> lg = G_Local(y, w, transform='B', seed=12345, alternative='two-sided')

Examining the results.

>>> lg.Zs
array([-1.0136729 , -0.04361589,  1.31558703, -0.31412676,  1.15373986,
       1.77833941])
>>> round(lg.p_sim[0], 3)
np.float32(0.413)

P-value based on standard normal approximation from permutations.

>>> round(lg.p_z_sim[0], 3)
np.float64(0.153)

Applying Getis and Ord local G* test using a binary weights object.

>>> lg_star = G_Local(
...     y, w, transform='B', star=True, seed=12345, alternative='two-sided',
... )

Examining the results.

>>> lg_star.Zs
array([-1.39727626, -0.28917762,  0.65064964, -0.28917762,  1.23452088,
       2.02424331])
>>> round(lg_star.p_sim[0], 3)
np.float32(0.413)

Applying Getis and Ord local G test using a row-standardized weights object.

>>> lg = G_Local(y, w, transform='R', seed=12345, alternative='two-sided')

Examining the results.

>>> lg.Zs
array([-0.62074534, -0.01780611,  1.31558703, -0.12824171,  0.28843496,
       1.77833941])
>>> round(lg.p_sim[0], 3)
np.float32(0.413)

Applying Getis and Ord local G* test using a row-standardized weights object.

>>> lg_star = G_Local(
...     y, w, transform='R', star=True, seed=12345, alternative='two-sided',
... )

Examining the results.

>>> lg_star.Zs
array([-0.62488094, -0.09144599,  0.41150696, -0.09144599,  0.24690418,
       1.28024388])
>>> round(lg_star.p_sim[0], 3)
np.float32(0.209)

Methods

calc()

calc()[source]