DSA LABData Science Applications
Experiment 09 · CO3

Do the Machines
Really Differ?

A factory runs three machines and asks: is their mean output truly different, or just random wobble? One-way ANOVA answers it by comparing variation between machines to variation within them. Move the means and watch the F-statistic and p-value react.

Course IT416
Outcome CO3
Test One-way ANOVA
Output F · p-value

Significance, live

F-TEST
0
Machines
0
Samples each
0
Significance α
0
Concept video
01

Lab Manual

Problem
A manufacturing company wants to analyse whether the mean production output differs significantly across multiple machines operating under different conditions. Identify the appropriate statistical technique, implement the solution in Python, and interpret the results for decision-making.
Aim
To apply one-way Analysis of Variance (ANOVA) to test whether three or more group means are equal, and to interpret the F-statistic and p-value.
Objectives
  • State the null and alternative hypotheses for comparing means.
  • Partition total variation into between-group and within-group parts.
  • Compute the F-statistic and its p-value.
  • Decide significance at α = 0.05 and (if needed) run a post-hoc test.
Software
Python 3.x · Jupyter / Colab · NumPy, Pandas, SciPy / statsmodels.
Theory
ANOVA compares the spread between group means to the spread within groups. If the between-group variation is large relative to the within-group variation, the means are unlikely to be equal. The ratio is the F-statistic; a small p-value (< 0.05) rejects the null hypothesis that all means are equal.
Outcome
CO3 — selecting and applying a statistical technique for decision-making.
02

Between vs Within

The hypotheses

H₀: μ₁ = μ₂ = μ₃  (all equal)
H₁: at least one mean differs

ANOVA is an omnibus test: a significant result says the means aren't all equal, but not which ones — that needs a post-hoc test (e.g. Tukey).

The F-ratio

F = MSbetween / MSwithin

Big F → the machines' averages are far apart compared with their internal noise → likely a real difference. The p-value turns F into a probability.

03

The ANOVA Engine

Each column is a machine's 12 output samples; the thick line is its mean, the dashed line is the grand mean. Slide a machine's mean and watch the F-statistic and p-value recompute — both are real, using the F-distribution. Press resample to redraw the random noise.

One-way ANOVA · 3 machinesspread the means apart to raise F
Machine A mean50
Machine B mean50
Machine C mean50
Within-machine spread (σ)6
F-statistic
p-value
Between MS
Within MS
Try this: start with all three means equal — F is small and p is large (no difference). Drag Machine C up; as the between-group spread grows, F shoots up and the p-value drops below 0.05, flipping the verdict to "significant".
04

Watch the Concepts

A clear explainer from StatQuest on how ANOVA works through linear models, plus a quick route to post-hoc testing.

StatQuestt-tests and ANOVA, Clearly ExplainedHow the F-test decides whether group means differ.
Further watching Post-hoc: Tukey's HSDAfter a significant ANOVA, find which machines differ. Open a clear walkthrough on YouTube. Open on YouTube ↗

Embedded video is from YouTube and belongs to its creator. If a frame is blank, your network may block YouTube.

05

The Program

Run the F-test in one line with SciPy, then the full table and post-hoc with statsmodels.

1 — anova_scipy.py
import pandas as pd
from scipy import stats

df = pd.read_csv("machines.csv")   # columns: machine, output
A = df[df.machine=="A"].output
B = df[df.machine=="B"].output
C = df[df.machine=="C"].output

F, p = stats.f_oneway(A, B, C)         # one-way ANOVA
print("F =", round(F,3), " p =", round(p,4))
print("Reject H0 (means differ)" if p < 0.05 else "Fail to reject H0")
2 — anova_table.py
import statsmodels.api as sm
from statsmodels.formula.api import ols

model = ols("output ~ C(machine)", data=df).fit()
table = sm.stats.anova_lm(model, typ=2)
print(table)        # sum_sq, df, F, PR(>F)
3 — posthoc.py
# If significant, find WHICH machines differ
from statsmodels.stats.multicomp import pairwise_tukeyhsd

tukey = pairwise_tukeyhsd(df.output, df.machine, alpha=0.05)
print(tukey.summary())
# Also check assumptions: normality of residuals, equal variances (Levene).
06

Procedure & Result

Steps followed

1 · Hypotheses
State H₀ (means equal) and H₁.
2 · Check
Assumptions: normality, equal variances.
3 · Partition
Compute between- and within-group sums of squares.
4 · F & p
F = MSB/MSW; get the p-value.
5 · Decide
Compare p with α = 0.05.
6 · Post-hoc
If significant, run Tukey's HSD.

Result

One-way ANOVA was applied to the machines' output. The F-statistic and p-value were computed; a p-value below 0.05 indicates the mean outputs differ significantly, and a Tukey post-hoc test identifies which machines stand apart — supporting a data-driven decision (CO3).

Conclusion: ANOVA compares signal (differences between machine averages) to noise (variation within each machine). A large F and small p mean the difference is real, not chance — telling the factory a machine genuinely needs attention. Always pair the result with a post-hoc test and an assumption check.
07

Viva Questions

What is ANOVA and when is it used?
Analysis of Variance tests whether the means of three or more groups are equal. It's used when comparing several group means at once, avoiding the inflated error of running many t-tests.
Why not just run multiple t-tests?
Each t-test carries a chance of a false positive; doing many inflates the overall Type-I error rate. ANOVA gives a single test of "are any means different?" at the chosen significance level.
What do between-group and within-group variance mean?
Between-group variance measures how far the group means are from the grand mean (the signal). Within-group variance measures the scatter inside each group (the noise). ANOVA compares the two.
What is the F-statistic and how is it interpreted?
F = MS_between / MS_within. Values near 1 suggest equal means; large values suggest the group means differ. Its p-value gives the probability of seeing such an F if H₀ were true.
What does the p-value tell you?
The probability of obtaining results at least as extreme as observed if all means were truly equal. If p < α (e.g. 0.05), reject H₀ and conclude the means differ.
What are the assumptions of one-way ANOVA?
Independent observations, approximately normal residuals, and roughly equal variances across groups (homoscedasticity). If violated, use Welch's ANOVA or the Kruskal-Wallis test.
Why is a post-hoc test needed after a significant ANOVA?
ANOVA only says at least one mean differs, not which. Post-hoc tests like Tukey's HSD compare pairs while controlling the overall error rate to pinpoint the differences.