# esda.G

class esda.G(y, w, permutations=999)

  Global G Autocorrelation Statistic.

  Parameters:
    y `array` (n,1)

      Attribute values

    w `W` | `Graph`

      spatial weights instance as W or Graph aligned with y

    permutations `int`

      the number of random permutations for calculating pseudo p_values

  Attributes:
    y `array`

      original variable

    w `W` | `Graph`

      spatial weights instance as W or Graph aligned with y

    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

  Moments are based on normality assumption.

  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)
      >>> w.transform = "B"

  Preparing a variable

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

  Applying Getis and Ord G test

      >>> from esda.getisord import G
      >>> g = G(y,w)

  Examining the results

      >>> round(g.G, 3)
      0.557

      >>> round(g.p_norm, 3)
      0.173.

  __init__(y, w, permutations=999)

  Methods

  `__init__`(y, w[, permutations]) |
  `by_col`(df, cols[, w, inplace, pvalue, outvals]) | Function to compute a G statistic on a dataframe

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

    Function to compute a G statistic on a dataframe

    Parameters:
      df `pandas.DataFrame`

        a pandas dataframe with a geometry column

      cols `str` or `list` of `str`

        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 `str`

        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 `dict`

        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.