esda.Moran¶
- class esda.Moran(y, w, transformation='r', permutations=999, two_tailed=True)[source]¶
Moran’s I Global Autocorrelation Statistic
- Parameters:
- w
W|Graph spatial weights instance as W or Graph aligned with y
Other options include “B”: binary, “D”:
doubly-standardized, “O”: restore original transformation
(applicable only if
wis passed asW) (general weights), “V”: variance-stabilizing.
pseudo-p_values
tailed, otherwise if False, they are one-tailed.
W | Graphoriginal w object
Notes
Technical details and derivations can be found in [CO81].
Examples
>>> import libpysal
>>> w = libpysal.io.open(libpysal.examples.get_path("stl.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("stl_hom.txt"))
>>> y = np.array(f.by_col['HR8893'])
>>> from esda.moran import Moran
>>> mi = Moran(y, w)
>>> round(mi.I, 3)
0.244
>>> mi.EI
-0.012987012987012988
>>> mi.p_norm
0.00027147862770937614
SIDS example replicating OpenGeoda
>>> w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("sids2.dbf"))
>>> SIDR = np.array(f.by_col("SIDR74"))
>>> mi = Moran(SIDR, w)
>>> round(mi.I, 3)
0.248
>>> mi.p_norm
0.0001158330781489969
One-tailed
>>> mi_1 = Moran(SIDR, w, two_tailed=False)
>>> round(mi_1.I, 3)
0.248
>>> round(mi_1.p_norm, 4)
0.0001
Methods
|
|
|
Function to compute a Moran statistic on a dataframe |
|
Plot a Moran scatterplot with optional coloring for significant points. |
|
Global Moran's I simulated reference distribution. |
- classmethod by_col(df, cols, w=None, inplace=False, pvalue='sim', outvals=None, **stat_kws)[source]¶
Function to compute a Moran 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’
the Moran statistic’s documentation for available p-values
Moran statistic
documentation for the Moran statistic.
therelevantcolumnsattached.
- plot_scatter(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.
- ax
matplotlib.axes.AxesAxes object with the Moran scatterplot.
- plot_simulation(ax=None, legend=False, fitline_kwds=None, **kwargs)[source]¶
Global Moran’s I simulated reference distribution.
- Parameters:
- ax
matplotlib.axes.Axes, optional Pre-existing axes for the plot, by default None.
- ax
by default None.
matplotlib.axes.AxesAxes object with the Moran scatterplot.
Notes
This requires optional dependencies matplotlib and seaborn.
Examples
>>> import libpysal
>>> w = libpysal.io.open(libpysal.examples.get_path("stl.gal")).read()
>>> f = libpysal.io.open(libpysal.examples.get_path("stl_hom.txt"))
>>> y = np.array(f.by_col['HR8893'])
>>> from esda.moran import Moran
>>> mi = Moran(y, w)
Default plot:
>>> mi.plot_simulation()
Customized styling that turns the distribution into a pink line and line indicating I to a black line:
>>> mi.plot_simulation(fitline_kwds={"color": "k"}, color="pink", shade=False)