stats.comparison.repeated_measures_anova

stats.comparison.repeated_measures_anova(panel)

Run a one-way repeated-measures ANOVA on a complete panel.

Tests equality of the column (entry) means of a complete block-by-entry matrix, treating the rows (e.g. target days) as blocks — the parametric omnibus test run before pairwise comparison with pairwise_paired_t.

Parameters

Name Type Description Default
panel pd.DataFrame Complete block-by-entry frame (one row per block, one column per treatment). Must contain no NaN. required

Returns

Name Type Description
RepeatedMeasuresAnova A RepeatedMeasuresAnova with the F test and the full
RepeatedMeasuresAnova sum-of-squares decomposition.

Raises

Name Type Description
ValueError When panel has fewer than two rows or columns, or contains NaN.

Examples

import pandas as pd
from spotforecast2_safe.stats.comparison import repeated_measures_anova

days = pd.date_range("2026-06-10", periods=5, freq="D")
panel = pd.DataFrame(
    {
        "alpha": [500.0, 700, 400, 650, 550],
        "beta": [540.0, 745, 435, 690, 595],
        "gamma": [505.0, 702, 405, 653, 552],
    },
    index=days,
)
anova = repeated_measures_anova(panel)
print(f"F({anova.df_treatment}, {anova.df_error}) = "
      f"{anova.f_statistic:.2f}, p = {anova.p_value:.4f}")
assert anova.n_blocks == 5 and anova.n_treatments == 3
F(2, 8) = 306.95, p = 0.0000