Introduction
With only two groups, a t-test settles the question of whether their means differ. With three or more — regions, dosages, product tiers — running pairwise t-tests inflates your false-positive rate, which is exactly the problem ANOVA solves. OneWayANOVA tests whether at least one group mean differs from the rest, and then automatically runs Tukey's HSD post-hoc test so you know which specific pairs of groups are actually different, not just that some difference exists somewhere.
One-way ANOVA is essential for:
- Comparing sales performance across different retail regions
- Testing the efficacy of multiple drug treatments relative to a control
- Analyzing variations in machinery output under different operating temperatures
- Evaluating differences in customer satisfaction scores across product tiers
- Assessing the impact of various educational methods on student scores
- Comparing investment returns across different asset classes
- Validating whether different marketing campaigns result in distinct conversion rates
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
dataframerequired | | — | The pandas DataFrame containing the experimental data. |
outcome_columnrequired | | — | Name of the column containing the continuous outcome variable (dependent variable). |
grouping_columnrequired | | — | Name of the column containing the categorical grouping labels (independent variable). |
signficance_level | | 0.05 | The alpha level used to determine statistical significance. Defaults to 0.05. |
homogeneity_of_variance | | True | If True, assumes equality of variance between groups. If False, adjusts calculations for unequal variances. Defaults to True. |
use_welch_correction | | False | If True, applies Welch's correction to the ANOVA calculation, which is recommended when group variances or sample sizes are unequal. Defaults to False. |
plot_sample_distributions | | True | If True, displays a kernel density estimate of simulated sample means for each group to visualize differences. Defaults to True. |
color_palette | | 'Set2' | Seaborn color palette name used for the lines and fills in the plot. Defaults to 'Set2'. |
title_for_plot | | 'One-Way ANOVA' | Main title text to display at the top of the plot. Defaults to 'One-Way ANOVA'. |
subtitle_for_plot | | 'Shows the distribution of the sample means for each group.' | Subtitle text to display below the main title. |
caption_for_plot | | None | Caption text displayed at the bottom of the plot. Defaults to None. |
data_source_for_plot | | None | Optional text identifying the data source, displayed in the caption area. Defaults to None. |
show_y_axis | | False | If True, displays the y-axis (density scale) on the distribution plot. Defaults to False. |
title_y_indent | | 1.1 | Vertical position for the main title relative to the axes. Defaults to 1.1. |
subtitle_y_indent | | 1.05 | Vertical position for the subtitle relative to the axes. Defaults to 1.05. |
caption_y_indent | | -0.15 | Vertical position for the caption relative to the axes. Defaults to -0.15. |
figure_size | | (8, 6) | Tuple specifying the (width, height) of the figure in inches. Defaults to (8, 6). |
Returns
A statsmodels Summary object containing the results of Tukey's Honestly Significant Difference (HSD) post-hoc test, including pairwise group differences, confidence intervals, and rejection decisions.
Example
from analysistoolbox.hypothesis_testing import OneWayANOVA
import pandas as pd
import numpy as np
# Compare average sales across three different regions
sales_df = pd.DataFrame({
'sales': np.random.normal(500, 50, 60),
'region': ['East', 'West', 'South'] * 20
})
tukey_results = OneWayANOVA(
dataframe=sales_df,
outcome_column='sales',
grouping_column='region'
)
print(tukey_results)