esda.Moran_Local

class esda.Moran_Local(y, w, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None)[source]

Local Moran Statistics

Parameters
yarray

(n,1), attribute array

wW

weight instance assumed to be aligned with y

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

n_jobsint

Number of cores to be used in the conditional randomisation. If -1, all available cores are used.

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.

Notes

For technical details see [Ans95].

Examples

>>> import libpysal
>>> import numpy as np
>>> np.random.seed(10)
>>> w = libpysal.io.open(libpysal.examples.get_path("desmith.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("desmith.txt"))
>>> y = np.array(f.by_col['z'])
>>> from esda.moran import Moran_Local
>>> lm = Moran_Local(y, w, transformation = "r", permutations = 99)
>>> lm.q
array([4, 4, 4, 2, 3, 3, 1, 4, 3, 3])
>>> lm.p_z_sim[0]
0.24669152541631179
>>> lm = Moran_Local(y, w, transformation = "r", permutations = 99,                             geoda_quads=True)
>>> lm.q
array([4, 4, 4, 3, 2, 2, 1, 4, 2, 2])

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

original variable

wW

original w object

permutationsint

number of random permutations for calculation of pseudo p_values

Isarray

local Moran’s I values

qarray

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

simarray (permutations by n)

(if permutations>0) I values for permuted samples

p_simarray

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

EI_simarray

(if permutations>0) average values of local Is from permutations

VI_simarray

(if permutations>0) variance of Is from permutations

EIarray

analytical expectation of Is under total permutation, from [Anselin1995]. Is the same at each site, and equal to the expectation of I itself when transformation=’r’. We recommend using EI_sim, not EI, for analysis. This EI is only provided for reproducibility.

VIarray

analytical variance of Is under total permutation, from [Anselin1995]. Varies according only to cardinality. We recommend using VI_sim, not VI, for analysis. This VI is only provided for reproducibility.

EIcarray

analytical expectation of Is under conditional permutation, from [SOT98]. Varies strongly by site, since it conditions on z_i. We recommend using EI_sim, not EIc, for analysis. This EIc is only provided for reproducibility.

VIcarray

analytical variance of Is under conditional permutation, from [SOT98]. Varies strongly by site, since it conditions on z_i. We recommend using VI_sim, not VIc, for analysis. This VIc is only provided for reproducibility.

seI_simarray

(if permutations>0) standard deviations of Is under permutations.

z_simarrray

(if permutations>0) standardized Is based on permutations

p_z_simarray

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

n_jobsint

Number of cores to be used in the conditional randomisation. If -1, all available cores are used.

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.

__init__(y, w, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None)[source]

Methods

__init__(y, w[, transformation, …])

by_col(df, cols[, w, inplace, pvalue, outvals])

Function to compute a Moran_Local statistic on a dataframe