morans_i#

morans_i(domain, label_name, population=None, include_boundaries=None, exclude_boundaries=None, boundary_exclude_distance=0, distance_weight_function=None, network_kwargs={'max_edge_distance': inf, 'min_edge_distance': 0, 'network_type': 'Delaunay'}, alpha=0.05, add_local_value_as_label=True, local_morans_label_name=None)#

Calculate the local and global Moran’s I statistic for a continuous label in the domain. Moran’s I quantifies the spatial autocorrelation of a label relative to a null hypothesis of Complete Spatial Randomness (CSR) and returned as a z-score and p-value.

Positive z-scores indicate clustering of similar label values whereas negative z-scores indicate dispersion of similar label values.

The local Moran’s I statistic quantifies the spatial autocorrelation for each object in the population. The global Moran’s I statistic quantifies the spatial autocorrelation for the entire population.

Local p-values are corrected using the Bonferroni method. Local Moran’s I values are added as labels to the domain if add_local_value_as_label is True.

Parameters:
domainobject

A muspan domain object.

label_namestr

The name of the label to be analysed.

populationlist or np.ndarray or query-like

The population of objects or a query to select objects.

include_boundarieslist, np.ndarray or query-like or None, optional

Boundaries to include or None to include all.

exclude_boundarieslist, np.ndarray or query-like or None, optional

Boundaries to exclude or None to exclude none.

boundary_exclude_distancefloat, optional

Distance to exclude around boundaries, default is 0.

distance_weight_functioncallable or None, optional

Function to weight distances, default f(x) = 1.

network_kwargsdict, optional

Dictionary of network generation parameters, default is {‘network_type’: ‘Delaunay’, ‘min_edge_distance’: 0, ‘max_edge_distance’: np.inf}.

alphafloat, optional

Significance level for null rejection, default is 0.05.

add_local_value_as_labelbool, optional

Whether to add local Moran’s I values as labels, default is True.

local_morans_label_namestr, optional

Name for the local Moran’s I label. If not specified, this will default to ‘Local Moran I statistic - {label_name}’, where {label_name} is the label specified above.

Returns:
global_morans_i_zscorefloat

Z-score for the global Moran’s I statistic.

global_morans_i_pvalfloat

P-value for the global Moran’s I statistic.

local_morans_i_zscorendarray

Array of z-scores for the local Moran’s I statistic.

local_morans_i_pvalndarray

Array of p-values for the local Moran’s I statistic.

object_indicesndarray

Array of object indices used in the analysis.

Raises:
ValueError

If the label does not exist or is not continuous, or if distance_weight_function is not callable.

Warning

UserWarning

If the number of objects is less than 30, a warning is issued about statistical validity.

Examples

Minimal example demonstrating the calculation of Moran’s I statistic for a continuous label:

import muspan as ms

# load example domain
domain = ms.datasets.load_example_domain('Mouse-Colon-Carcinoma')

# compute global and local Moran's I for the 'CD4' label
global_m_i_zscore, global_m_i_pval, local_m_i_zscore, local_m_i_pval, object_ids = ms.spatial_statistics.morans_i(domain,
                                                                                                                label_name='CD4',
                                                                                                                add_local_value_as_label=True,
                                                                                                                local_morans_label_name='local MI CD4')

# visualise the domain colored by the local Moran's I z-score for 'CD4'
ms.visualise.visualise(domain,color_by='local MI CD4')

print("Global Moran's I z-score: ", global_m_i_zscore)
print("Global Moran's I p-value: ", global_m_i_pval)