esda.getisord — Getis-Ord statistics for spatial association

New in version 1.0.

Getis and Ord G statistic for spatial autocorrelation

class pysal.esda.getisord.G(y, w, permutations=999)[source]

Global G Autocorrelation Statistic

Parameters:
  • y (array (n,1)) – Attribute values
  • w (W) – DistanceBand W spatial weights based on distance band
  • permutations (int) – the number of random permutations for calculating pseudo p_values
y

array – original variable

w

W – DistanceBand W spatial weights based on distance band

permutation

int – the number of permutations

G

float – the value of statistic

EG

float – the expected value of statistic

VG

float – the variance of G under normality assumption

z_norm

float – standard normal test statistic

p_norm

float – p-value under normality assumption (one-sided)

sim

array – (if permutations > 0) vector of G values for permutated samples

p_sim

float – p-value based on permutations (one-sided) null: spatial randomness alternative: the observed G is extreme it is either extremely high or extremely low

EG_sim

float – average value of G from permutations

VG_sim

float – variance of G from permutations

seG_sim

float – standard deviation of G under permutations.

z_sim

float – standardized G based on permutations

p_z_sim

float – p-value based on standard normal approximation from permutations (one-sided)

Notes

Moments are based on normality assumption.

Examples

>>> from pysal.weights.Distance import DistanceBand
>>> 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 = DistanceBand(points,threshold=15) >>> w.transform = “B”

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

Applying Getis and Ord G test >>> g = G(y,w)

Examining the results >>> print “%.8f” % g.G 0.55709779

>>> print "%.4f" % g.p_norm
0.1729
classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]

Function to compute a G statistic on a dataframe

Parameters:
  • df (pandas.DataFrame) – a pandas dataframe with a geometry column
  • cols (string or list of string) – name or list of names of columns to use to compute the statistic
  • w (pysal weights object) – a weights object aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata
  • inplace (bool) – a boolean denoting whether to operate on the dataframe inplace or to return a series contaning the results of the computation. If operating inplace, the derived columns will be named ‘column_g’
  • pvalue (string) – a string denoting which pvalue should be returned. Refer to the the G statistic’s documentation for available p-values
  • outvals (list of strings) – list of arbitrary attributes to return as columns from the G statistic
  • **stat_kws (keyword arguments) – options to pass to the underlying statistic. For this, see the documentation for the G statistic.
Returns:

  • If inplace, None, and operation is conducted on dataframe in memory. Otherwise,
  • returns a copy of the dataframe with the relevant columns attached.

See also

For, refer

class pysal.esda.getisord.G_Local(y, w, transform='R', permutations=999, star=False)[source]

Generalized Local G Autocorrelation Statistic [Getis1992], [Ord1995], [Getis1996] .

Parameters:
  • y (array) – variable
  • w (W) – DistanceBand, weights instance that is based on threshold distance and is assumed to be 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 (boolean) – whether or not to include focal observation in sums (default: False)
y

array – original variable

w

DistanceBand W – original weights object

permutations

int – the number of permutations

Gs

array – of floats, the value of the orginal G statistic in Getis & Ord (1992)

EGs

float – expected value of Gs under normality assumption the values is scalar, since the expectation is identical across all observations

VGs

array – of floats, variance values of Gs under normality assumption

Zs

array – of floats, standardized Gs

p_norm

array – of floats, p-value under normality assumption (one-sided) for two-sided tests, this value should be multiplied by 2

sim

array – of arrays of floats (if permutations>0), vector of I values for permutated samples

p_sim

array – of floats, p-value based on permutations (one-sided) null - spatial randomness alternative - the observed G is extreme it is either extremely high or extremely low

EG_sim

array – of floats, average value of G from permutations

VG_sim

array – of floats, variance of G from permutations

seG_sim

array – of floats, standard deviation of G under permutations.

z_sim

array – of floats, standardized G based on permutations

p_z_sim

array – of floats, p-value based on standard normal approximation from permutations (one-sided)

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).

Examples

>>> from pysal.weights.Distance import DistanceBand
>>> 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 = DistanceBand(points,threshold=15)

Prepareing a variable

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

Applying Getis and Ord local G test using a binary weights object >>> 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])
>>> lg.p_sim[0]
0.10100000000000001
>>> 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])
>>> lg_star.p_sim[0]
0.10100000000000001
>>> numpy.random.seed(10)

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])
>>> lg.p_sim[0]
0.10100000000000001
>>> 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])
>>> lg_star.p_sim[0]
0.10100000000000001
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:
  • df (pandas.DataFrame) – a pandas dataframe with a geometry column
  • cols (string or list of string) – name or list of names of columns to use to compute the statistic
  • w (pysal weights object) – a weights object aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata
  • inplace (bool) – a boolean denoting whether to operate on the dataframe inplace or to return a series contaning the results of the computation. If operating inplace, the derived columns will be named ‘column_g_local’
  • pvalue (string) – a string denoting which pvalue should be returned. Refer to the the G_Local statistic’s documentation for available p-values
  • outvals (list of strings) – list of arbitrary attributes to return as columns from the G_Local statistic
  • **stat_kws (keyword arguments) – options to pass to the underlying statistic. For this, see the documentation for the G_Local statistic.
Returns:

  • If inplace, None, and operation is conducted on dataframe in memory. Otherwise,
  • returns a copy of the dataframe with the relevant columns attached.

See also

For, refer