Statistical Analysis#

The result.stats namespace provides powerful analytical tools for geospatial and timeseries data. All statistical methods return a new Result object with the computed lazy data and populated metadata.

Descriptive Statistics#

# Describe specific columns
desc = res.stats.describe(columns=["ndvi", "rainfall"])

# Breakdown per entity
desc_entity = res.stats.describe(by="entity")

Correlation#

Find temporal or spatial correlations between variables:

from core_lens.base.namespaces.stats import CorrelateMethod

corr = res.stats.correlate(
    columns=["ndvi", "rainfall", "temperature"],
    method=CorrelateMethod.PEARSON,  # or SPEARMAN, KENDALL
    across="entity",  # correlate across entities or time
)

Hypothesis Testing#

Test for significant differences between groups or periods:

from core_lens.base.namespaces.stats import TestMethod

# Group-based testing
test_res = res.stats.test(
    column="cropping_intensity",
    groups="temperature_zone",
    method=TestMethod.MANN_WHITNEY,
)

# Period-based testing
test_period = res.stats.test(
    column="ndvi", periods=[(2010, 2015), (2016, 2023)], method=TestMethod.T_TEST
)

Change Detection#

Analyse absolute, percentage, or trend changes over time:

from core_lens.base.namespaces.stats import ChangeMethod

# Trend over time
trend = res.stats.change(
    column="ndvi", from_period=2010, to_period=2023, method=ChangeMethod.TREND
)

# Absolute or percentage change
pct_change = res.stats.change(
    column="tree_cover",
    from_period=2018,
    to_period=2023,
    method=ChangeMethod.PERCENTAGE,
)

Anomaly Detection#

Identify anomalies against a historical baseline or cross-sectionally:

from core_lens.base.namespaces.stats import AnomalyTsMethod, AnomalyCrossMethod

# Timeseries anomaly against its own history
ts_anomalies = res.stats.anomaly(
    column="ndvi", mode="timeseries", method=AnomalyTsMethod.STL, baseline=(2010, 2018)
)

# Cross-sectional anomaly against other entities
cross_anomalies = res.stats.anomaly(
    column="ndvi",
    mode="cross_sectional",
    method=AnomalyCrossMethod.ZSCORE,
    baseline=(2010, 2020),
)