# esda.Moran_Rate

class esda.Moran_Rate(e, b, w, adjusted=True, transformation='r', permutations=999, two_tailed=True)

  Adjusted Moran’s I Global Autocorrelation Statistic for Rate Variables [AR99]

  Parameters:
    e `array`

      an event variable measured across n spatial units

    b `array`

      a population-at-risk variable measured across n spatial units

    w `W` | `Graph`

      spatial weights instance as W or Graph aligned with e and b

    adjusted bool

      whether or not Moran’s I needs to be adjusted for rate variable

    transformation{‘R’, ‘B’, ‘D’, ‘U’, ‘V’}

      weights transformation, default is row-standardized “r”. Other options include “B”: binary, “D”: doubly-standardized, “O”: restore original transformation (applicable only if `w` is passed as `W`), “V”: variance-stabilizing.

    two_tailed bool

      If True (default), analytical p-values for Moran’s I are two-tailed, otherwise they are one tailed.

    permutations `int`

      number of random permutations for calculation of pseudo p_values

  Attributes:
    y `array`

      rate variable computed from parameters e and b if adjusted is True, y is standardized rates otherwise, y is raw rates

    z `array`

      zero-mean, unit standard deviation normalized y

    w `W` | `Graph`

      original w object

    permutations `int`

      number of permutations

    I `float`

      value of Moran’s I

    EI `float`

      expected value under normality assumption

    VI_norm `float`

      variance of I under normality assumption

    seI_norm `float`

      standard deviation of I under normality assumption

    z_norm `float`

      z-value of I under normality assumption

    p_norm `float`

      p-value of I under normality assumption

    VI_rand `float`

      variance of I under randomization assumption

    seI_rand `float`

      standard deviation of I under randomization assumption

    z_rand `float`

      z-value of I under randomization assumption

    p_rand `float`

      p-value of I under randomization assumption

    two_tailed bool

      If True, p_norm and p_rand are two-tailed p-values, otherwise they are one-tailed.

    sim `array`

      (if permutations>0) vector of I values for permuted samples

    p_sim `array`

      (if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed I is extreme if it is either extremely greater or extremely lower than the values obtained from permutaitons

    EI_sim `float`

      (if permutations>0) average value of I from permutations

    VI_sim `float`

      (if permutations>0) variance of I from permutations

    seI_sim `float`

      (if permutations>0) standard deviation of I under permutations.

    z_sim `float`

      (if permutations>0) standardized I based on permutations

    p_z_sim `float`

      (if permutations>0) p-value based on standard normal approximation from

  Examples

      >>> import libpysal
      >>> w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read()
      >>> f = libpysal.io.open(libpysal.examples.get_path("sids2.dbf"))
      >>> e = np.array(f.by_col('SID79'))
      >>> b = np.array(f.by_col('BIR79'))
      >>> from esda.moran import Moran_Rate
      >>> mi = Moran_Rate(e, b,  w, two_tailed=False)
      >>> "%6.4f" % mi.I
      '0.1662'
      >>> "%6.4f" % mi.p_norm
      '0.0042'

  __init__(e, b, w, adjusted=True, transformation='r', permutations=999, two_tailed=True)

  Methods

  `__init__`(e, b, w[, adjusted, ...]) |
  `by_col`(df, events, populations[, w, ...]) | Function to compute a Moran_Rate statistic on a dataframe
  `plot_scatter`([ax, scatter_kwds, fitline_kwds]) | Plot a Moran scatterplot with optional coloring for significant points.
  `plot_simulation`([ax, legend, fitline_kwds]) | Global Moran's I simulated reference distribution.

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

    Function to compute a Moran_Rate statistic on a dataframe

    Parameters:
      df `pandas.DataFrame`

        a pandas dataframe with a geometry column

      events `str` or `list` of `strings`

        one or more names where events are stored

      populations `str` or `list` of `strings`

        one or more names where the populations corresponding to the events are stored. If one population column is provided, it is used for all event columns. If more than one population column is provided but there is not a population for every event column, an exception will be raised.

      w `W` | `Graph`

        spatial weights instance as W or Graph 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_moran_rate’

      pvalue `str`

        a string denoting which pvalue should be returned. Refer to the the Moran_Rate statistic’s documentation for available p-values

      outvals `list` of `strings`

        list of arbitrary attributes to return as columns from the Moran_Rate statistic

      **stat_kws `keyword` `arguments`

        options to pass to the underlying statistic. For this, see the documentation for the Moran_Rate 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.