esda.geary — Geary’s C statistics for spatial autocorrelation

New in version 1.0.

Geary’s C statistic for spatial autocorrelation

class pysal.esda.geary.Geary(y, w, transformation='r', permutations=999)[source]

Global Geary C Autocorrelation statistic

Parameters:
  • y (array) – (n, 1) attribute vector
  • w (W) – spatial weights
  • transformation ({'B', 'R', 'D', 'U', 'V'}) – weights transformation, default is binary. Other options include “R”: row-standardized, “D”: doubly-standardized, “U”: untransformed (general weights), “V”: variance-stabilizing.
  • permutations (int) – number of random permutations for calculation of pseudo-p_values
y

array – original variable

w

W – spatial weights

permutations

int – number of permutations

C

float – value of statistic

EC

float – expected value

VC

float – variance of G under normality assumption

z_norm

float – z-statistic for C under normality assumption

z_rand

float – z-statistic for C under randomization assumption

p_norm

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

p_rand

float – p-value under randomization assumption (one-tailed)

sim

array – (if permutations!=0) vector of I values for permutated samples

p_sim

float – (if permutations!=0) p-value based on permutations (one-tailed) null: sptial randomness alternative: the observed C is extreme it is either extremely high or extremely low

EC_sim

float – (if permutations!=0) average value of C from permutations

VC_sim

float – (if permutations!=0) variance of C from permutations

seC_sim

float – (if permutations!=0) standard deviation of C under permutations.

z_sim

float – (if permutations!=0) standardized C based on permutations

p_z_sim

float – (if permutations!=0) p-value based on standard normal approximation from permutations (one-tailed)

Examples

>>> import pysal
>>> w = pysal.open(pysal.examples.get_path("book.gal")).read()
>>> f = pysal.open(pysal.examples.get_path("book.txt"))
>>> y = np.array(f.by_col['y'])
>>> c = Geary(y,w,permutations=0)
>>> print round(c.C,7)
0.3330108
>>> print round(c.p_norm,7)
9.2e-05
>>>
classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]

Function to compute a Geary 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, with default configurations, the derived columns will be named like ‘column_geary’ and ‘column_p_sim’
  • pvalue (string) – a string denoting which pvalue should be returned. Refer to the the Geary statistic’s documentation for available p-values
  • outvals (list of strings) – list of arbitrary attributes to return as columns from the Geary statistic
  • **stat_kws (keyword arguments) – options to pass to the underlying statistic. For this, see the documentation for the Geary 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