ANOVA¶
One-way, factorial, ANCOVA, and repeated measures ANOVA. Type I/II/III sums of squares. Post-hoc tests (Tukey HSD, Bonferroni, Dunnett). Levene’s test for homogeneity of variances.
Analysis of Variance (ANOVA).
- Public API:
anova_oneway(y, group, …) -> AnovaSolution anova(y, factors, …) -> AnovaSolution # factorial / ANCOVA anova_rm(y, subject, within, …) -> AnovaRMSolution # repeated measures anova_posthoc(result, …) -> PostHocSolution # Tukey / Bonferroni / Dunnett levene_test(y, group, …) -> LeveneSolution # homogeneity of variances
- pystatistics.anova.anova(y, factors, *, covariates=None, ss_type=2, interactions=True)[source]¶
Factorial ANOVA or ANCOVA.
Tests main effects and interactions of two or more factors, with optional continuous covariates (ANCOVA).
- Parameters:
y (Any) – Response variable (1D numeric array-like)
covariates (dict[str, Any] | None) – {name: 1D numeric array} or None
ss_type (int) – Type of sums of squares (1, 2, or 3). Default 2. Type I: sequential (order-dependent) Type II: marginal, respects marginality (R’s car::Anova default) Type III: each term last (requires deviation coding)
interactions (bool) – Whether to include interaction terms. Default True.
- Returns:
AnovaSolution with ANOVA table, effect sizes, and group means
- Return type:
Examples
>>> result = anova(y, {'A': factor_a, 'B': factor_b}) >>> print(result.summary()) >>> result = anova(y, {'treatment': tx}, covariates={'age': age}, ss_type=2)
- pystatistics.anova.anova_oneway(y, group, *, ss_type=1)[source]¶
One-way Analysis of Variance.
Tests whether the means of two or more groups are equal.
- Parameters:
- Returns:
AnovaSolution with ANOVA table, effect sizes, and group means
- Return type:
Examples
>>> result = anova_oneway(y, group) >>> print(result.summary()) >>> result.table[0].f_value # F statistic for the group effect >>> result.eta_squared # effect sizes
- pystatistics.anova.anova_posthoc(anova_result, *, method='tukey', factor=None, control=None, conf_level=0.95)[source]¶
Post-hoc pairwise comparisons following ANOVA.
- Parameters:
anova_result (AnovaSolution) – Result from anova_oneway() or anova()
method (str) – ‘tukey’ (default), ‘bonferroni’, or ‘dunnett’
factor (str | None) – Which factor to compare (required for factorial, auto for oneway)
control (str | None) – Control group name (required for dunnett)
conf_level (float) – Confidence level (default 0.95)
- Returns:
PostHocSolution with comparison table and adjusted p-values
- Return type:
Examples
>>> anova_result = anova_oneway(y, group) >>> posthoc = anova_posthoc(anova_result, method='tukey') >>> print(posthoc.summary())
- pystatistics.anova.anova_rm(y, subject, within, *, between=None, correction='auto')[source]¶
Repeated-measures ANOVA.
Tests within-subjects effects with optional between-subjects factors (mixed design). Includes Mauchly’s sphericity test and GG/HF corrections.
- Parameters:
y (Any) – Response variable (1D, long format)
subject (Any) – Subject identifiers (1D)
within (dict[str, Any]) – {factor_name: 1D condition labels}
between (dict[str, Any] | None) – {factor_name: 1D group labels} or None
correction (str) – Sphericity correction: ‘none’: no correction ‘gg’: Greenhouse-Geisser ‘hf’: Huynh-Feldt ‘auto’: GG if Mauchly p < 0.05, else none (default)
- Returns:
AnovaRMSolution with ANOVA table, sphericity, corrected p-values
- Return type:
Examples
>>> result = anova_rm(y, subject=subj, within={'condition': cond}) >>> print(result.summary()) >>> result.sphericity[0].gg_epsilon # GG correction factor
- pystatistics.anova.levene_test(y, group, *, center='median')[source]¶
Levene’s test for homogeneity of variances.
Tests the null hypothesis that all groups have equal variances. With center=’median’ (default), this is the Brown-Forsythe variant which is more robust to non-normality.
- Parameters:
- Returns:
LeveneSolution with F statistic, p-value, and group variances
- Return type:
Examples
>>> result = levene_test(y, group) >>> result.p_value > 0.05 # Can't reject equal variances >>> print(result.summary())
- class pystatistics.anova.AnovaSolution(_result)[source]¶
Bases:
objectUser-facing result for between-subjects ANOVA.
Produced by anova_oneway() and anova().
- Parameters:
_result (Result[AnovaParams])
- class pystatistics.anova.AnovaRMSolution(_result)[source]¶
Bases:
objectUser-facing result for repeated-measures ANOVA.
Produced by anova_rm().
- Parameters:
_result (Result[AnovaRMParams])
- class pystatistics.anova.LeveneSolution(_result)[source]¶
Bases:
objectUser-facing result for Levene’s test.
Produced by levene_test().
- Parameters:
_result (Result[LeveneParams])