esda.MoranLocalConditional

class esda.MoranLocalConditional(permutations=999, unit_scale=True, transformer=None, alternative='two-sided')[source]

Fit a local moran statistic for y after regressing out the effects of confounding X on y. A “stronger” version of the MoranLocalPartial statistic, as defined by [Wolf, 2024]

Compute the Multivariable Local Moran statistics under partial dependence [Wolf, 2024]

Parameters:
permutations : int

the number of permutations to run for the inference, driven by conditional randomization.

unit_scale : bool

whether to enforce unit variance in the local statistics. This normalizes the variance of the data at inupt, ensuring that the covariance statistics are not overwhelmed by any single covariate’s large variance.

partial_labels : bool, default=True

whether to calculate the classification based on the part-regressive quadrant classification or the univariate quadrant classification, like a classical Moran’s I. When mvquads is True, the variables are labelled as: - label 1: observations with large y - rho * x that also have large Wy values. - label 2: observations with small y - rho * x values that also have large Wy values. - label 3: observations with small y - rho * x values that also have small Wy values. - label 4: observations with large y - rho * x values that have small Wy values.

alternative : str (default: 'two-sided')

the alternative hypothesis for the inference. One of ‘two-sided’, ‘greater’, ‘lesser’, ‘directed’, or ‘folded’. See the esda.significance.calculate_significance() documentation for more information.

connectivity[source]
Type:

The weights matrix inputted, but row standardized

D[source]

not None, this will be [1 y X]

Type:

The “design” matrix used in computation. If X is

R[source]

always be the same shape as D and contain [1, Wy, Wy, ….]

Type:

the “response” matrix used in computation. Will

DtDi[source]

the P x P matrix describing the variance and covariance of y and X.

Type:

empirical parameter covariance matrix

P[source]
Type:

the number of parameters. 1 if X is not provided.

association_[source]

the first column, lmos[:,1] is the LISAs corresponding to the relationship between Wy and y conditioning on X.

Type:

the N,P matrix of multivariable LISA statistics.

reference_distribution_[source]

the (N, permutations, P+1) realizations from the conditional randomization to generate reference distributions for each Local Moran statistic. rlmos_[:,:,1] pertain to the reference distribution of y and Wy.

significance_[source]

part-regressive relationships. quads[:,0] pertains to the relationship between y and Wy. The mean is not classified, since it’s just binary above/below mean usually.

Type:

the (N, P) matrix of quadrant classifications for the

partials_[source]

The ith slice of partials_[:,:,i] contains the partial regressive contribution of that covariate, with the first column indicating the part-regressive outcome and the second indicating the part-regressive design. The partial regression matrix starts at zero, so partials_[:,:,0] corresponds to the partial regression describing the relationship between y and Wy.

Type:

the (N,2,P+1) matrix of part-regressive contributions.

labels_[source]

part-regressive relationships. See the partial_labels argument for more information.

Type:

the (N,) array of quadrant classifications for the

Methods

by_col(df, cols[, w, inplace, pvalue, outvals])

Function to compute a Moran_Local statistic on a dataframe.

explore(gdf[, crit_value])

Create interactive map of LISA indicators

fit(X, y, W)

get_cluster_labels([crit_value])

Return LISA cluster labels for each observation.

plot(gdf[, crit_value])

Create static map of LISA indicators

plot_combination(gdf, attribute[, ...])

Produce three-plot visualisation of Moran Scatteprlot, LISA cluster and Choropleth maps, with Local Moran region and quadrant masking

plot_scatter([crit_value, ax, scatter_kwds, ...])

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:
df : pandas.DataFrame

a pandas dataframe with a geometry column

cols : string or list of string

name or list of names of columns to use to compute the statistic

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

inplace : bool

a boolean denoting whether to operate on the dataframe inplace or to return a series contaning the results of the computation. If operating inplace, the derived columns will be named ‘column_moran_local’

pvalue : string

a string denoting which pvalue should be returned. Refer to the the Moran_Local statistic’s documentation for available p-values

outvals : list of strings

list of arbitrary attributes to return as columns from the Moran_Local statistic

**stat_kws : dict

options to pass to the underlying statistic. For this, see the documentation for the Moran_Local statistic.

Returns:

  • If inplace, None, and operation is conducted on dataframe

  • in memory. Otherwise, returns a copy of the dataframe with

  • the relevant columns attached.

explore(gdf, crit_value=0.05, **kwargs)[source]

Create interactive map of LISA indicators

Parameters:
gdf : geopandas.GeoDataFrame

geodataframe used to conduct the local Moran analysis

crit_value : float, optional

critical value to determine statistical significance, by default 0.05

kwargs : dict, optional

additional keyword arguments passed to the geopandas explore method

Returns:

interactive map with LISA clusters

Return type:

Folium.Map

fit(X, y, W)[source]
Parameters:
y : (N,1) array

array of data that is the targeted “outcome” covariate to compute the multivariable Moran’s I

X : (N,3) array

array of data that is used as “confounding factors” to account for their covariance with Y.

W : (N,N) weights object

spatial weights instance as W or Graph aligned with y. Immediately row-standardized.

Return type:

A fitted MoranLocalConditional() estimator

get_cluster_labels(crit_value=0.05)[source]

Return LISA cluster labels for each observation.

Parameters:
crit_value : float, optional

crititical significance value for statistical inference, by default 0.05

Returns:

an array of cluster labels aligned with the input data used to conduct the local Moran analysis

Return type:

numpy.array

plot(gdf, crit_value=0.05, **kwargs)[source]

Create static map of LISA indicators

Parameters:
gdf : geopandas.GeoDataFrame

geodataframe used to conduct the local Moran analysis

crit_value : float, optional

critical value to determine statistical significance, by default 0.05

kwargs : dict, optional

additional keyword arguments passed to the geopandas explore method

Returns:

matplotlib axis

Return type:

ax

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, losh_scaling_factor=False, losh_inference=None, a=2)[source]

Produce three-plot visualisation of Moran Scatteprlot, LISA cluster and Choropleth maps, with Local Moran region and quadrant masking

Parameters:
gdf : geopandas.GeoDataFrame

geodataframe used to conduct the local Moran analysis

attribute : str

Column name of attribute which should be depicted in Choropleth map.

crit_value : float, optional

critical value to determine statistical significance, by default 0.05

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’.

quadrant : int, optional

Quadrant 1-4 in scatterplot masking values in LISA cluster and 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’.

scatter_kwds : keyword arguments, optional

Keywords used for creating and designing the scatter points, by default None.

fitline_kwds : keyword arguments, optional

Keywords used for creating and designing the moran fitline in the scatterplot, by default None.

legend_kwds : dict

Keyword arguments passed to geopandas.GeodataFrame.plot legend_kwds allowing repositioning of the legend in LISA cluster plot and choropleth.

losh_scaling_factor : bool | int | float, by default False

Scale the scatterplot observations by LOSH. When set to a number, it is treated as the multiplicative factor applied to exp(LOSH.Hi) when converting LOSH values into marker areas.

losh_inference : str, optional

Inference method for LOSH. See LOSH for supported options. Applies only if losh_scaling_factor is not False.

a : int or float, default=2

Residual exponent passed to esda.losh.LOSH.fit(). The default corresponds to a variance-based LOSH measure. Applies only if losh_scaling_factor is not False.

Returns:

axs

Return type:

array of Matplotlib axes

plot_scatter(crit_value=0.05, ax=None, scatter_kwds=None, fitline_kwds=None, losh_scaling_factor=False, losh_inference=None, a=2)[source]

Plot a Moran scatterplot with optional coloring for significant points.

Parameters:
crit_value : float, optional

Critical value to determine statistical significance, by default 0.05.

ax : matplotlib.axes.Axes, optional

Pre-existing axes for the plot, by default None.

scatter_kwds : dict, optional

Additional keyword arguments for scatter plot, by default None.

fitline_kwds : dict, optional

Additional keyword arguments for fit line, by default None.

losh_scaling_factor : bool | int | float, by default False

Scale the observations by LOSH. When set to a number, it is treated as the multiplicative factor applied to exp(LOSH.Hi) when converting LOSH values into marker areas.

losh_inference : str, optional

Inference method for LOSH. See LOSH for supported options. Applies only if losh_scaling_factor is not False.

a : int or float, default=2

Residual exponent passed to esda.losh.LOSH.fit(). The default corresponds to a variance-based LOSH measure. Applies only if losh_scaling_factor is not False.

Returns:

Axes object with the Moran scatterplot.

Return type:

matplotlib.axes.Axes