pysal.explore.esda.Moran

class pysal.explore.esda.Moran(y, w, transformation='r', permutations=999, two_tailed=True)[source]

Moran’s I Global Autocorrelation Statistic

Parameters:
y : array

variable measured across n spatial units

w : W

spatial weights instance

transformation : string

weights transformation, default is row-standardized “r”. Other options include “B”: binary, “D”: doubly-standardized, “U”: untransformed (general weights), “V”: variance-stabilizing.

permutations : int

number of random permutations for calculation of pseudo-p_values

two_tailed : boolean

If True (default) analytical p-values for Moran are two tailed, otherwise if False, they are one-tailed.

Notes

Technical details and derivations can be found in [CO81].

Examples

>>> import pysal.lib
>>> w = pysal.lib.io.open(pysal.lib.examples.get_path("stl.gal")).read()
>>> f = pysal.lib.io.open(pysal.lib.examples.get_path("stl_hom.txt"))
>>> y = np.array(f.by_col['HR8893'])
>>> from pysal.explore.esda.moran import Moran
>>> mi = Moran(y,  w)
>>> round(mi.I, 3)
0.244
>>> mi.EI
-0.012987012987012988
>>> mi.p_norm
0.00027147862770937614

SIDS example replicating OpenGeoda >>> w = pysal.lib.io.open(pysal.lib.examples.get_path(“sids2.gal”)).read() >>> f = pysal.lib.io.open(pysal.lib.examples.get_path(“sids2.dbf”)) >>> SIDR = np.array(f.by_col(“SIDR74”)) >>> mi = Moran(SIDR, w) >>> round(mi.I, 3) 0.248 >>> mi.p_norm 0.0001158330781489969

One-tailed

>>> mi_1 = Moran(SIDR,  w, two_tailed=False)
>>> round(mi_1.I, 3)
0.248
>>> round(mi_1.p_norm, 4)
0.0001
Attributes:
y : array

original variable

w : W

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 : boolean

If True p_norm and p_rand are two-tailed, 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-tailed) null: spatial randomness alternative: the observed I is extreme if it is either extremely greater or extremely lower than the values obtained based on permutations

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 permutations

Methods

by_col(df, cols[, w, inplace, pvalue, outvals]) Function to compute a Moran statistic on a dataframe
__init__(y, w, transformation='r', permutations=999, two_tailed=True)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(y, w[, transformation, …]) Initialize self.
by_col(df, cols[, w, inplace, pvalue, outvals]) Function to compute a Moran statistic on a dataframe