giddy.markov.
LISA_Markov
(y, w, permutations=0, significance_level=0.05, geoda_quads=False)[source]¶Markov for Local Indicators of Spatial Association
Parameters: |
|
---|
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: |
|
---|
Methods
spillover ([quadrant, neighbors_on]) |
Detect spillover locations for diffusion in LISA Markov. |