New in version 1.0.
Moran’s I Spatial Autocorrelation Statistics
Moran’s I Global Autocorrelation Statistic
| Parameters: | y : array
w : W
permutations : int
|
|---|
Examples
>>> import pysal
>>> w=pysal.open("../examples/stl.gal").read()
>>> f=pysal.open("../examples/stl_hom.txt")
>>> y=np.array(f.by_col['HR8893'])
>>> mi=Moran(y,w)
>>> "%7.5f"%mi.I
'0.24366'
>>> mi.EI
-0.012987012987012988
>>> mi.p_norm
0.00027147862770937614
SIDS example replicating OpenGeoda
>>> w=pysal.open("../examples/sids2.gal").read()
>>> f=pysal.open("../examples/sids2.dbf")
>>> SIDR=np.array(f.by_col("SIDR74"))
>>> mi=pysal.Moran(SIDR,w)
>>> "%6.4f"%mi.I
'0.2477'
>>> mi.p_norm
0.0001158330781489969
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 (1-tailed) |
| 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 (1-tailed) |
| sim | array (if permutations>0) | vector of I values for permutated samples |
| p_sim | array (if permutations>0) | p-value 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 |
Local Moran Statistics
| Parameters: | y : n*1 array w : weight instance assumed to be aligned with y transformation : string
permutations : number of random permutations for calculation of pseudo-p_values |
|---|
Notes
p-values are one sided - where side is based on the original I value for each observation (in self.Is). In other words extreme is considered being further away from the origin and in the same direction than original I statistic for the focal observation.
Examples
>>> import pysal
>>> import numpy as np
>>> np.random.seed(10)
>>> w=pysal.open("../examples/desmith.gal").read()
>>> f=pysal.open("../examples/desmith.txt")
>>> y=np.array(f.by_col['z'])
>>> 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.99036648060872201
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
| y | array | original variable |
| w | W | original w object |
| permutations | int | number of random permutations for calculation of pseudo-p_values |
| I | float | value of Moran’s I |
| q | array (if permutations>0) | values indicate quadrat location 1 HH, 2 LH, 3 LL, 4 HL |
| sim | array (if permutations>0) | vector of I values for permutated samples |
| p_sim | array (if permutations>0) | p-value 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
| calc |
Bivariate Moran’s I
| Parameters: | x : array
y : array
w : W
transformation : string
permutations : int
|
|---|
Notes
Inference is only based on permutations as analytical results are none too reliable.
Examples
>>> import pysal
>>> import numpy as np
>>> np.random.seed(10)
>>> f=pysal.open("../examples/sids2.dbf")
>>> SIDR74=np.array(f.by_col['SIDR74'])
>>> SIDR79=np.array(f.by_col['SIDR79'])
>>> w=pysal.open("../examples/sids2.gal").read()
>>> mbi=Moran_BV(SIDR79,SIDR74,w)
>>> print mbi.I
0.156131961696
>>> mbi.p_z_sim
0.0028373234843530604
Attributes
| zx | array | original x variable standardized by mean and std |
| zy | array | original y variable standardized by mean and std |
| w | W | original w object |
| permutation | int | number of permutations |
| I | float | value of bivariate Moran’s I |
| sim | array (if permutations>0) | vector of I values for permutated samples |
| p_sim | float (if permutations>0) | p-value based on permutations |
| EI_sim | array (if permutations>0) | average value of I from permutations |
| VI_sim | array (if permutations>0) | variance of I from permutations |
| seI_sim | array (if permutations>0) | standard deviation of I under permutations. |
| z_sim | array (if permutations>0) | standardized I based on permutations |
| p_z_sim | float (if permutations>0) | p-value based on standard normal approximation from permutations |
Bivariate Moran Matrix
Calculates bivariate Moran between all pairs of a set of variables.
| Parameters: | variables : list
w : W
permutations : int
varnames : list
|
|---|---|
| Returns: | results : dictionary
|
Examples
>>> import pysal
>>> f=pysal.open("../examples/sids2.dbf")
>>> varnames=['SIDR74','SIDR79','NWR74','NWR79']
>>> vars=[np.array(f.by_col[var]) for var in varnames]
>>> w=pysal.open("../examples/sids2.gal").read()
>>> res=Moran_BV_matrix(vars,w,varnames=varnames)
x wy I
SIDR74 SIDR79 0.194
SIDR79 SIDR74 0.156
SIDR74 NWR74 0.384
NWR74 SIDR74 0.375
SIDR74 NWR79 0.388
NWR79 SIDR74 0.377
SIDR79 NWR74 0.116
NWR74 SIDR79 0.103
SIDR79 NWR79 0.122
NWR79 SIDR79 0.110
NWR74 NWR79 0.735
NWR79 NWR74 0.737
>>>