EZ Statistics

One-Way ANOVA

Calculator

2. Select Columns & Options

Learn More

One-way ANOVA

Definition

One-way ANOVA (Analysis of Variance) tests whether there are significant differences between the means of three or more independent groups. It extends the t-test to multiple groups while controlling the Type I error rate.

Formula

Key Components:

SSbetween=i=1kni(xˉixˉg)2SS_{between} = \sum_{i=1}^{k} n_i(\bar{x}_i - \bar{x}_g)^2

Between-groups sum of squares, where:

  • xˉi\bar{x}_i = mean of group ii
  • xˉg\bar{x}_g = grand mean
  • nin_i = sample size of group ii
SSwithin=i=1kj=1ni(xijxˉi)2SS_{within} = \sum_{i=1}^{k} \sum_{j=1}^{n_i} (x_{ij} - \bar{x}_i)^2

Within-groups sum of squares, where:

  • xijx_{ij} = jjth observation in group ii
  • xˉi\bar{x}_i = mean of group ii
  • nin_i = sample size of group ii

Final Test Statistic:

F=MSbetweenMSwithin=SSbetween/(k1)SSwithin/(Nk)F = \frac{MS_{between}}{MS_{within}} = \frac{SS_{between}/(k-1)}{SS_{within}/(N-k)}

Where:

  • SSwithinSS_{within} = within-groups sum of squares
  • kk = number of groups
  • NN = total sample size

Key Assumptions

Independence: Observations must be independent
Normality: Data within each group should be normally distributed
Homogeneity of Variance: Groups should have equal variances

Practical Example

Step 1: State the Data
Group AGroup BGroup C
869
9510
7810
1078
Step 2: State Hypotheses
  • H0:μ1=μ2=μ3H_0: \mu_1 = \mu_2 = \mu_3 (all means equal)
  • Ha:H_a: at least one mean is different
  • α=0.05\alpha = 0.05
Step 3: Calculate Summary Statistics
  • Group A: xˉA=8.50,sA=1.29\bar{x}_A = 8.50, s_A = 1.29
  • Group B: xˉB=6.50,sB=1.29\bar{x}_B = 6.50, s_B = 1.29
  • Group C: xˉC=9.25,sC=0.96\bar{x}_C = 9.25, s_C = 0.96
  • Grand mean: xˉ=8.08\bar{x} = 8.08
Step 4: Calculate Sums of Squares
SSbetween=16.17SS_{between} = 16.17SSwithin=12.75SS_{within} = 12.75SStotal=28.92SS_{total} = 28.92
Step 5: Calculate Mean Squares
MSbetween=SSbetweenk1=8.08MS_{between} = \frac{SS_{between}}{k-1} = 8.08MSwithin=SSwithinNk=1.42MS_{within} = \frac{SS_{within}}{N-k} = 1.42
Step 6: Calculate F-statistic

F=MSbetweenMSwithin=5.71F = \frac{MS_{between}}{MS_{within}} = 5.71

Step 7: Draw Conclusion

The critical value F(2,9)F_{(2,9)} at α=0.05\alpha = 0.05 is 4.264.26.

The calculated F-statistic (F=5.71F = 5.71) is greater than the critical value (4.264.26), and the p-value (p=0.025p = 0.025) is less than our significance level (alpha=0.05\\alpha = 0.05). We reject the null hypothesis in favor of the alternative. There is statistically significant evidence to conclude that not all group means are equal. Specifically, at least one group mean differs significantly from the others.

Effect Size

Eta-squared (η2\eta^2) measures the proportion of variance explained:

η2=SSbetweenSStotal\eta^2 = \frac{SS_{between}}{SS_{total}}

Guidelines:

  • Small effect: η20.01\eta^2 \approx 0.01
  • Medium effect: η20.06\eta^2 \approx 0.06
  • Large effect: η20.14\eta^2 \approx 0.14

For the example above, the effect size is:η2=16.1728.92=0.56\eta^2 = \frac{16.17}{28.92} = 0.56which indicates a large effect.

Code Examples

R
1library(tidyverse)
2group <- factor(c(rep("A", 4), rep("B", 4), rep("C", 4)))
3values <- c(8, 9, 7, 10, 6, 5, 8, 7, 9, 10, 10, 8)
4
5
6# calculate SS between manually
7mean_values <- tapply(values, group, mean)
8grand_mean <- mean(values)
9ss_between <- sum(table(group) * (mean_values - grand_mean)^2)
10print(str_glue("SS between: {ss_between}")))
11
12# calculate everything manually
13ss_within <- sum((values - ave(values, group, FUN = mean))^2)
14print(str_glue("SS within: {ss_within}"))
15
16ss_total = sum((values - grand_mean)^2)
17print(str_glue("SS total: {ss_total}"))
18
19ms_between = ss_between / (length(unique(group)) - 1)
20print(str_glue("MS between: {ms_between}"))
21
22ms_within = ss_within / (length(values) - length(unique(group)))
23print(str_glue("MS within: {ms_within}"))
24
25f = ms_between / ms_within
26print(str_glue("F: {f}"))
27
28p = 1 - pf(f, length(unique(group)) - 1, length(values) - length(unique(group)))
29print(str_glue("p value: {p}"))
30
31
32# Perform One-Way ANOVA using aov()
33data <- tibble(group, values)
34anova_result <- aov(values ~ group, data = data)
35summary(anova_result)
Python
1import numpy as np
2from scipy import stats
3
4# Data
5group_A = [8, 9, 7, 10]
6group_B = [6, 5, 8, 7]
7group_C = [9, 10, 10, 8]
8
9
10# calculate ss for each group
11ss_A = np.sum((group_A - np.mean(group_A)) ** 2)
12ss_B = np.sum((group_B - np.mean(group_B)) ** 2)
13ss_C = np.sum((group_C - np.mean(group_C)) ** 2)
14
15ss_whithin = ss_A + ss_B + ss_C
16print(f'SS within: {ss_whithin:.4f}')
17
18# calculate ss between
19grand_mean = np.mean([np.mean(group_A), np.mean(group_B), np.mean(group_C)])
20ss_between = len(group_A) * (np.mean(group_A) - grand_mean) ** 2 + len(group_B) * (np.mean(group_B) - grand_mean) ** 2 + len(group_C) * (np.mean(group_C) - grand_mean) ** 2
21print(f'SS between: {ss_between:.4f}')
22
23print(f'SS total: {ss_whithin + ss_between:.4f}')
24ms_within = ss_whithin / (len(group_A) + len(group_B) + len(group_C) - 3)
25print(f'MS within: {ss_whithin:.4f}')
26ms_between = ss_between / 2
27print(f'MS between: {ss_between:.4f}')
28
29f = ms_between / ms_within
30print(f'F-statistic: {f:.4f}')
31
32
33
34# Perform one-way ANOVA
35print('Perform one-way ANOVA using scipy.stats')
36f_stat, p_value = stats.f_oneway(group_A, group_B, group_C)
37
38# Print results
39print(f'F-statistic: {f_stat:.4f}')
40print(f'p-value: {p_value:.4f}')

Alternative Tests

Consider these alternatives when assumptions are violated:

  • Kruskal-Wallis Test: Non-parametric alternative when normality is violated
  • Welch's ANOVA: When variances are unequal
  • Brown-Forsythe Test: Robust to violations of normality

Related Calculators

Independent T-Test Calculator

Paired T-Test Calculator

Two-Way ANOVA Calculator

Kruskal-Wallis Test Calculator

Help us improve

Found an error or have a suggestion? Let us know!