esda.Moran_Local_Rate

class esda.Moran_Local_Rate(e, b, w, adjusted=True, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None, island_weight=0)[source]

Adjusted Local Moran Statistics for Rate Variables [AR99].

Parameters:
earray

(n,1), an event variable across n spatial units

barray

(n,1), a population-at-risk variable across n spatial units

wW

weight instance assumed to be aligned with y

adjustedbool

whether or not local Moran statistics need 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, “U”: untransformed (general weights), “V”: variance-stabilizing.

permutationsint

number of random permutations for calculation of pseudo p_values

geoda_quadsbool

(default=False) If True use GeoDa scheme: HH=1, LL=2, LH=3, HL=4 If False use PySAL Scheme: HH=1, LH=2, LL=3, HL=4

njobsint

number of workers to use to compute the local statistic.

keep_simulationsBoolean

(default=True) If True, the entire matrix of replications under the null is stored in memory and accessible; otherwise, replications are not saved

seedNone/int

Seed to ensure reproducibility of conditional randomizations. Must be set here, and not outside of the function, since numba does not correctly interpret external seeds nor numpy.random.RandomState instances.

island_weightfloat

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.

Examples

>>> import libpysal
>>> import numpy as np
>>> np.random.seed(10)
>>> 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_Local_Rate
>>> lm = Moran_Local_Rate(e, b, w, transformation="r", permutations=99)
>>> lm.q[:10]
array([2, 4, 3, 1, 2, 1, 1, 4, 2, 4])
>>> lm = Moran_Local_Rate(
...     e, b, w, transformation = "r", permutations=99, geoda_quads=True
)
>>> lm.q[:10]
array([3, 4, 2, 1, 3, 1, 1, 4, 3, 4])

Note random components result is slightly different values across architectures so the results have been removed from doctests and will be moved into unittests that are conditional on architectures

Attributes:
yarray

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

wW

original w object

permutationsint

number of random permutations for calculation of pseudo p_values

Isfloat

value of Local Moran’s Ii

qarray

(if permutations>0) values indicate quandrant location 1 HH, 2 LH, 3 LL, 4 HL

simarray

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

p_simarray

(if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed Ii is further away or extreme from the median of simulated Iis. It is either extremely high or extremely low in the distribution of simulated Is

EI_simfloat

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

VI_simfloat

(if permutations>0) variance of I from permutations

seI_simfloat

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

z_simfloat

(if permutations>0) standardized I based on permutations

p_z_simfloat

(if permutations>0) p-value based on standard normal approximation from permutations (one-sided) for two-sided tests, these values should be multiplied by 2

__init__(e, b, w, adjusted=True, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None, island_weight=0)[source]

Methods

__init__(e, b, w[, adjusted, ...])

by_col(df, events, populations[, w, ...])

Function to compute a Moran_Local_Rate statistic on a dataframe

explore(gdf[, crit_value])

Create interactive map of LISA indicators

get_cluster_labels([crit_value])

Return LISA cluster labels for each observation.

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

Function to compute a Moran_Local_Rate statistic on a dataframe

Parameters:
dfpandas.DataFrame

a pandas dataframe with a geometry column

eventsstr or list of strings

one or more names where events are stored

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

wpysal weights object

a weights object aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata

inplacebool

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_local_rate’

pvaluestr

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

outvalslist of strings

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

**stat_kwsdict

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