cassiopeia/tools/autocorrelation.py:
High-level description
This file provides utility functions for computing autocorrelation statistics on trees, specifically the Moran’s I statistic. It is designed to work with CassiopeiaTree objects and can handle both single and multiple variables for autocorrelation analysis.Symbols
compute_morans_i
Description
Computes Moran’s I statistic for a given CassiopeiaTree. This statistic measures the spatial autocorrelation of numerical data associated with the leaves of the tree.Inputs
Outputs
Internal Logic
- Validates input data and combines meta_columns and X if both are provided.
- Ensures all data is numerical.
- Computes or uses the provided weight matrix W.
- Normalizes W and standardizes X.
- Computes Moran’s I using the formula: I = X’ * Wn * X.
Dependencies
Error Handling
The function raisesAutocorrelationError in the following cases:
- No data is specified for computing autocorrelations.
- The provided X dataframe doesn’t match the tree’s leaves.
- Non-numeric data is found in the specified columns.
- The weight matrix doesn’t match the tree’s leaves.
