esda.Moran_Local¶
- class esda.Moran_Local(y, w, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None, island_weight=0)[source]¶
Local Moran Statistics.
- Parameters:
- w
W|Graph spatial weights instance as W or Graph aligned with y
- transformation{‘R’, ‘B’, ‘D’, ‘U’, ‘V’}
weights transformation, default is row-standardized “r”. Other options include “B”: binary, “D”: doubly-standardized, “O”: restore original transformation (applicable only if
wis passed asW), “V”: variance-stabilizing.
p_values
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
all available cores are used.
- keep_simulations
Boolean (default=True) If True, the entire matrix of replications under the null is stored in memory and accessible; otherwise, replications are not saved
- seedNone/int
Seed to ensure reproducibility of conditional randomizations. Must be set here, and not outside of the function, since numba does not correctly interpret external seeds nor numpy.random.RandomState instances.
- island_weight:
value to use as a weight for the “fake” neighbor for every island. If numpy.nan, will propagate to the final local statistic depending on the stat_func. If 0, then the lag is always zero for islands.
W | Graphoriginal w object
arrray(if permutations>0) standardized Is based on permutations
Boolean(default=True) If True, the entire matrix of replications under the null is stored in memory and accessible; otherwise, replications are not saved
Seed to ensure reproducibility of conditional randomizations. Must be set here, and not outside of the function, since numba does not correctly interpret external seeds nor numpy.random.RandomState instances.
Notes
For technical details see [Ans95].
Examples
>>> import libpysal
>>> import numpy as np
>>> np.random.seed(10)
>>> w = libpysal.io.open(libpysal.examples.get_path("desmith.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("desmith.txt"))
>>> y = np.array(f.by_col['z'])
>>> from esda.moran import Moran_Local
>>> 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.24669152541631179
>>> lm = Moran_Local(y, w, transformation = "r", permutations = 99, geoda_quads=True)
>>> lm.q
array([4, 4, 4, 3, 2, 2, 1, 4, 2, 2])
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.
- __init__(y, w, transformation='r', permutations=999, geoda_quads=False, n_jobs=1, keep_simulations=True, seed=None, island_weight=0)[source]¶
Methods
|
|
|
Function to compute a Moran_Local statistic on a dataframe. |
|
Create interactive map of LISA indicators |
|
Return LISA cluster labels for each observation. |
|
Create static map of LISA indicators |
|
Produce three-plot visualisation of Moran Scatteprlot, LISA cluster and Choropleth maps, with Local Moran region and quadrant masking |
|
Plot a Moran scatterplot with optional coloring for significant points. |
- classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]¶
Function to compute a Moran_Local statistic on a dataframe.
- Parameters:
- w
W|Graph spatial weights instance as W or Graph aligned with the dataframe. If not provided, this is searched for in the dataframe’s metadata
return a series contaning the results of the computation. If
operating inplace, the derived columns will be named
‘column_moran_local’
the Moran_Local statistic’s documentation for available p-values
Moran_Local statistic
documentation for the Moran_Local statistic.
therelevantcolumnsattached.
- explore(gdf, crit_value=0.05, **kwargs)[source]¶
Create interactive map of LISA indicators
- Parameters:
Folium.Mapinteractive map with LISA clusters
- get_cluster_labels(crit_value=0.05)[source]¶
Return LISA cluster labels for each observation.
- Parameters:
- Returns:
-
local Moran analysis
axmatplotlib axis
- plot_combination(gdf, attribute, crit_value=0.05, region_column=None, mask=None, mask_color='#636363', quadrant=None, legend=True, scheme='Quantiles', cmap='YlGnBu', figsize=(15, 4), scatter_kwds=None, fitline_kwds=None, legend_kwds=None)[source]¶
Produce three-plot visualisation of Moran Scatteprlot, LISA cluster and Choropleth maps, with Local Moran region and quadrant masking
- Parameters:
- region_column: string, optional
Column name containing mask region of interest, by default None
- mask: str, float, int, optional
Identifier or name of the region to highlight, by default None Use the same dtype to specifiy as in original dataset.
- mask_color: str, optional
Color of mask, by default ‘#636363’.
Choropleth maps, by default None
- figsize: tuple, optional
W, h of figure, by default (15,4)
- legend: boolean, optional
If True, legend for maps will be depicted, by default True
- scheme: str, optional
Name of mapclassify classifier to be used, by default ‘Quantiles’
- cmap: str, optional
Name of matplotlib colormap used for plotting the Choropleth. By default ‘YlGnBu’.
None.
in the scatterplot, by default None.
allowing repositioning of the legend in LISA cluster plot and choropleth.
- plot_scatter(crit_value=0.05, ax=None, scatter_kwds=None, fitline_kwds=None)[source]¶
Plot a Moran scatterplot with optional coloring for significant points.
- Parameters:
- ax
matplotlib.axes.Axes, optional Pre-existing axes for the plot, by default None.
matplotlib.axes.AxesAxes object with the Moran scatterplot.