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)[source]

Generalized Local G Autocorrelation

Parameters:
wW | 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)

pseudo p values

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.

island_weight:

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.

Notes

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

For technical details see [GO10] and [OG10].

Examples

>>> import libpysal
>>> import numpy
>>> numpy.random.seed(10)

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

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

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

>>> from esda.getisord import G_Local
>>> lg = G_Local(y,w,transform='B')

Examining the results

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

p-value based on standard normal approximation from permutations >>> round(lg.p_z_sim[0], 3) 0.154

>>> numpy.random.seed(10)

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

>>> lg_star = G_Local(y,w,transform='B',star=True)

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)
0.101
>>> numpy.random.seed(12345)

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

>>> lg = G_Local(y,w,transform='R')

Examining the results

>>> lg.Zs
array([-0.62074534, -0.01780611,  1.31558703, -0.12824171,  0.28843496,
        1.77833941])
>>> round(lg.p_sim[0], 3)
0.103
>>> numpy.random.seed(10)

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

>>> lg_star = G_Local(y,w,transform='R',star=True)

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)
0.101
Attributes:
wW | Graph

spatial weights instance as W or Graph aligned with y

the values is scalar, since the expectation is identical across all observations

for two-sided tests, this value should be multiplied by 2

for permutated samples

null - spatial randomness alternative - the observed G is extreme

(it is either extremely high or extremely low)

permutations (one-sided)

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

Methods

__init__(y, w[, transform, permutations, ...])

by_col(df, cols[, w, inplace, pvalue, outvals])

Function to compute a G_Local statistic on a dataframe

calc()

classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]

Function to compute a G_Local statistic on a dataframe

Parameters:
wW | Graph

spatial weights instance as W or Graph aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata

return a series contaning the results of the computation. If operating inplace, the derived columns will be named ‘column_g_local’

the G_Local statistic’s documentation for available p-values

G_Local statistic

documentation for the G_Local statistic.

Returns:
in memory. Otherwise, returns a copy of the dataframe with the relevant columns attached.

calc()[source]