esda.Gamma¶
-
class esda.Gamma(y, w, operation=
'c', standardize=False, permutations=999)[source]¶ Gamma index for spatial autocorrelation
- Parameters:¶
- y : array¶
variable measured across n spatial units
- w : W | Graph¶
spatial weights instance as W or Graph aligned with y can be binary or row-standardized
- operation : {'c', 's', 'a'}¶
attribute similarity function where, ‘c’ cross product ‘s’ squared difference ‘a’ absolute difference
- standardize : {False, True}¶
standardize variables first False, keep as is True, standardize to mean zero and variance one
- permutations : int¶
number of random permutations for calculation of pseudo-p_values
- op[source]¶
attribute similarity function, as per parameters attribute similarity function
- Type:¶
{‘c’, ‘s’, ‘a’}
- p_sim_g[source]¶
(if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed Gamma is more extreme than under randomness implemented as a two-sided test
- Type:¶
array
Examples
use same example as for join counts to show similarity
>>> import libpysal, numpy as np >>> from esda import Gamma >>> w = libpysal.weights.lat2W(4, 4) >>> y=np.ones(16) >>> y[0:8]=0 >>> np.random.seed(12345) >>> g = Gamma(y, w) >>> g.g np.float64(20.0) >>> round(g.g_z, 3) np.float64(3.188) >>> round(g.p_sim_g, 3) np.float64(0.003) >>> g.min_g np.float64(0.0) >>> g.max_g np.float64(20.0) >>> g.mean_g np.float64(11.093093093093094) >>> np.random.seed(12345) >>> g1 = Gamma(y, w, operation='s') >>> g1.g np.float64(8.0) >>> round(g1.g_z, 3) np.float64(-3.706) >>> g1.p_sim_g np.float64(0.001) >>> g1.min_g np.float64(14.0) >>> g1.max_g np.float64(48.0) >>> g1.mean_g np.float64(25.623623623623622) >>> np.random.seed(12345) >>> g2 = Gamma(y, w, operation='a') >>> g2.g np.float64(8.0) >>> round(g2.g_z, 3) np.float64(-3.706) >>> g2.p_sim_g np.float64(0.001) >>> g2.min_g np.float64(14.0) >>> g2.max_g np.float64(48.0) >>> g2.mean_g np.float64(25.623623623623622) >>> np.random.seed(12345) >>> g3 = Gamma(y, w, standardize=True) >>> g3.g np.float64(32.0) >>> round(g3.g_z, 3) np.float64(3.706) >>> g3.p_sim_g np.float64(0.001) >>> g3.min_g np.float64(-48.0) >>> g3.max_g np.float64(20.0) >>> g3.mean_g np.float64(-3.2472472472472473) >>> np.random.seed(12345) >>> def func(z, i, j): ... q = z[i] * z[j] ... return q ... >>> g4 = Gamma(y, w, operation=func) >>> g4.g np.float64(20.0) >>> round(g4.g_z, 3) np.float64(3.188) >>> round(g4.p_sim_g, 3) np.float64(0.003)Notes
For further technical details see [Hubert et al., 1981].
Attributes
new name to fit with Moran module