giddy.markov.LISA_Markov¶
-
class
giddy.markov.
LISA_Markov
(y, w, permutations=0, significance_level=0.05, geoda_quads=False)[source]¶ Markov for Local Indicators of Spatial Association
- Parameters
- yarray
(n, t), n cross-sectional units observed over t time periods.
- wW
spatial weights object.
- permutationsint, optional
number of permutations used to determine LISA significance (the default is 0).
- significance_levelfloat, optional
significance level (two-sided) for filtering significant LISA endpoints in a transition (the default is 0.05).
- geoda_quadsbool
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. (the default is False).
Examples
>>> import libpysal >>> import numpy as np >>> from giddy.markov import LISA_Markov >>> f = libpysal.io.open(libpysal.examples.get_path("usjoin.csv")) >>> years = list(range(1929, 2010)) >>> pci = np.array([f.by_col[str(y)] for y in years]).transpose() >>> w = libpysal.io.open(libpysal.examples.get_path("states48.gal")).read() >>> lm = LISA_Markov(pci,w) >>> lm.classes array([1, 2, 3, 4]) >>> lm.steady_state array([0.28561505, 0.14190226, 0.40493672, 0.16754598]) >>> lm.transitions array([[1.087e+03, 4.400e+01, 4.000e+00, 3.400e+01], [4.100e+01, 4.700e+02, 3.600e+01, 1.000e+00], [5.000e+00, 3.400e+01, 1.422e+03, 3.900e+01], [3.000e+01, 1.000e+00, 4.000e+01, 5.520e+02]]) >>> lm.p array([[0.92985458, 0.03763901, 0.00342173, 0.02908469], [0.07481752, 0.85766423, 0.06569343, 0.00182482], [0.00333333, 0.02266667, 0.948 , 0.026 ], [0.04815409, 0.00160514, 0.06420546, 0.88603531]]) >>> lm.move_types[0,:3] array([11, 11, 11]) >>> lm.move_types[0,-3:] array([11, 11, 11])
Now consider only moves with one, or both, of the LISA end points being significant
>>> np.random.seed(10) >>> lm_random = LISA_Markov(pci, w, permutations=99) >>> lm_random.significant_moves[0, :3] array([11, 11, 11]) >>> lm_random.significant_moves[0,-3:] array([59, 43, 27])
Any value less than 49 indicates at least one of the LISA end points was significant. So for example, the first spatial unit experienced a transition of type 11 (LL, LL) during the first three and last tree intervals (according to lm.move_types), however, the last three of these transitions involved insignificant LISAS in both the start and ending year of each transition.
Test whether the moves of y are independent of the moves of wy
>>> "Chi2: %8.3f, p: %5.2f, dof: %d" % lm.chi_2 'Chi2: 1058.208, p: 0.00, dof: 9'
Actual transitions of LISAs
>>> lm.transitions array([[1.087e+03, 4.400e+01, 4.000e+00, 3.400e+01], [4.100e+01, 4.700e+02, 3.600e+01, 1.000e+00], [5.000e+00, 3.400e+01, 1.422e+03, 3.900e+01], [3.000e+01, 1.000e+00, 4.000e+01, 5.520e+02]])
Expected transitions of LISAs under the null y and wy are moving independently of one another
>>> lm.expected_t array([[1.12328098e+03, 1.15377356e+01, 3.47522158e-01, 3.38337644e+01], [3.50272664e+00, 5.28473882e+02, 1.59178880e+01, 1.05503814e-01], [1.53878082e-01, 2.32163556e+01, 1.46690710e+03, 9.72266513e+00], [9.60775143e+00, 9.86856346e-02, 6.23537392e+00, 6.07058189e+02]])
If the LISA classes are to be defined according to GeoDa, the geoda_quad option has to be set to true
>>> lm.q[0:5,0] array([3, 2, 3, 1, 4]) >>> lm = LISA_Markov(pci,w, geoda_quads=True) >>> lm.q[0:5,0] array([2, 3, 2, 1, 4])
- Attributes
- chi_2tuple
(3 elements) (chi square test statistic, p-value, degrees of freedom) for test that dynamics of y are independent of dynamics of wy.
- classesarray
(4, 1) 1=HH, 2=LH, 3=LL, 4=HL (own, lag) 1=HH, 2=LL, 3=LH, 4=HL (own, lag) (if geoda_quads=True)
- expected_tarray
(4, 4), expected number of transitions under the null that dynamics of y are independent of dynamics of wy.
- move_typesmatrix
(n, t-1), integer values indicating which type of LISA transition occurred (q1 is quadrant in period 1, q2 is quadrant in period 2).
q1
q2
move_type
1
1
1
1
2
2
1
3
3
1
4
4
2
1
5
2
2
6
2
3
7
2
4
8
3
1
9
3
2
10
3
3
11
3
4
12
4
1
13
4
2
14
4
3
15
4
4
16
- parray
(k, k), transition probability matrix.
- p_valuesmatrix
(n, t), LISA p-values for each end point (if permutations > 0).
- significant_movesmatrix
(n, t-1), integer values indicating the type and significance of a LISA transition. st = 1 if significant in period t, else st=0 (if permutations > 0).
(s1,s2)
move_type
(1,1)
[1, 16]
(1,0)
[17, 32]
(0,1)
[33, 48]
(0,0)
[49, 64]
q1
q2
s1
s2
move_type
1
1
1
1
1
1
2
1
1
2
1
3
1
1
3
1
4
1
1
4
2
1
1
1
5
2
2
1
1
6
2
3
1
1
7
2
4
1
1
8
3
1
1
1
9
3
2
1
1
10
3
3
1
1
11
3
4
1
1
12
4
1
1
1
13
4
2
1
1
14
4
3
1
1
15
4
4
1
1
16
1
1
1
0
17
1
2
1
0
18
.
.
.
.
.
.
.
.
.
.
4
3
1
0
31
4
4
1
0
32
1
1
0
1
33
1
2
0
1
34
.
.
.
.
.
.
.
.
.
.
4
3
0
1
47
4
4
0
1
48
1
1
0
0
49
1
2
0
0
50
.
.
.
.
.
.
.
.
.
.
4
3
0
0
63
4
4
0
0
64
- steady_statearray
(k, ), ergodic distribution.
- transitionsarray
(4, 4), count of transitions between each state i and j.
spillover
arrayDetect spillover locations for diffusion in LISA Markov.
Methods
spillover
(self[, quadrant, neighbors_on])Detect spillover locations for diffusion in LISA Markov.