Sub topic 8
The ANOVA method and variance components
This chapter assumes you have read the earlier chapters on repeatability, reproducibility and crossed study design. It also assumes you know what a mean, a variance and a sum of squares are. Here you will split the variation in a gage R&R study into components, turn those components into the standard metrics, and learn where the calculation can go wrong.
Why ANOVA instead of average and range
The average and range method estimates repeatability and reproducibility from ranges and tabulated constants. It cannot separate an operator-by-part interaction from the other sources. The ANOVA method can. It treats the study as a two-factor crossed experiment with replication, and it tests whether operators handle some parts differently from others.
The model for the measurement of part i by operator j on replicate k is:
x(ijk) = μ + part(i) + operator(j) + (part × operator)(ij) + error(ijk)
Parts and operators are treated as random samples from larger populations. Each term therefore has a variance, and the study estimates those variances. The model is a random-effects model, and the formulas below depend on that choice.
| Term | Variance symbol | Gage R&R meaning |
|---|---|---|
| error | σ²(rep) | Repeatability |
| operator | σ²(oper) | Part of reproducibility |
| part × operator | σ²(int) | Part of reproducibility |
| part | σ²(part) | Real process variation |
From sums of squares to mean squares
Let p be the number of parts, o the number of operators and r the number of replicates. Write x̄ for a mean over the subscripts you average. The sums of squares are:
- SS(part) = o·r·Σ(x̄(i) − x̄)²
- SS(oper) = p·r·Σ(x̄(j) − x̄)²
- SS(int) = r·Σ(x̄(ij) − x̄(i) − x̄(j) + x̄)²
- SS(rep) = Σ(x(ijk) − x̄(ij))²
Each sum of squares divides by its degrees of freedom to give a mean square (MS):
| Source | Degrees of freedom |
|---|---|
| Part | p − 1 |
| Operator | o − 1 |
| Part × operator | (p − 1)(o − 1) |
| Repeatability (error) | p·o·(r − 1) |
A study with 10 parts, 3 operators and 2 replicates has 9, 2, 18 and 30 degrees of freedom. These sum to 59, which is the total number of measurements (60) minus 1.
Expected mean squares and variance components
A mean square is not a variance. Each one is a mixture of variances. In the random-effects crossed model, the expected values are:
| Mean square | Expected value |
|---|---|
| MS(rep) | σ²(rep) |
| MS(int) | σ²(rep) + r·σ²(int) |
| MS(oper) | σ²(rep) + r·σ²(int) + p·r·σ²(oper) |
| MS(part) | σ²(rep) + r·σ²(int) + o·r·σ²(part) |
Solving these equations from the bottom of the table upward gives the variance components:
- σ²(rep) = MS(rep)
- σ²(int) = (MS(int) − MS(rep)) / r
- σ²(oper) = (MS(oper) − MS(int)) / (p·r)
- σ²(part) = (MS(part) − MS(int)) / (o·r)
Notice that the operator and part effects are compared with the interaction mean square, not with repeatability. An operator difference only counts as real if it is large relative to how much operators disagree from part to part.
The components then combine into the quantities the study reports:
- Reproducibility: σ²(repro) = σ²(oper) + σ²(int)
- Gage R&R: σ²(GRR) = σ²(rep) + σ²(repro)
- Total variation: σ²(total) = σ²(GRR) + σ²(part)
A worked example by hand
Suppose a study with p = 10, o = 3, r = 2 gives these mean squares: MS(part) = 6.0, MS(oper) = 0.30, MS(int) = 0.012, MS(rep) = 0.010.
p, o, r = 10, 3, 2
ms_part, ms_oper, ms_int, ms_rep = 6.0, 0.30, 0.012, 0.010
var_rep = ms_rep
var_int = max(0.0, (ms_int - ms_rep) / r)
var_oper = max(0.0, (ms_oper - ms_int) / (p * r))
var_part = max(0.0, (ms_part - ms_int) / (o * r))
var_grr = var_rep + var_oper + var_int
var_total = var_grr + var_part
print(f"repeatability {var_rep:.4f}")
print(f"interaction {var_int:.4f}")
print(f"operator {var_oper:.4f}")
print(f"part {var_part:.4f}")
print(f"gage R&R {var_grr:.4f}")
print(f"%contribution {100 * var_grr / var_total:.2f}")
print(f"%study var {100 * (var_grr / var_total) ** 0.5:.2f}")The components are 0.0100 (repeatability), 0.0010 (interaction), 0.0144 (operator) and 0.9980 (part). Gage R&R variance is 0.0254, which is 2.5% of the total variance, or about 15.8% of the study variation. Operator differences contribute more than repeatability here, so training or a standard procedure would help more than a more precise gage.
The full function
The function below carries out the whole calculation on a three-dimensional array of shape (parts, operators, replicates). It also returns %tolerance when you supply the tolerance width (USL − LSL), using the 6σ convention, and the number of distinct categories (ndc). The next chapters cover how to read these metrics.
import numpy as np
def gage_rr_anova(x, tolerance=None):
"""Crossed gage R&R by the ANOVA method.
x has shape (parts, operators, replicates)."""
p, o, r = x.shape
grand = x.mean()
part = x.mean(axis=(1, 2))
oper = x.mean(axis=(0, 2))
cell = x.mean(axis=2)
ss_part = o * r * np.sum((part - grand) ** 2)
ss_oper = p * r * np.sum((oper - grand) ** 2)
ss_int = r * np.sum((cell - part[:, None] - oper[None, :] + grand) ** 2)
ss_rep = np.sum((x - cell[:, :, None]) ** 2)
ms_part = ss_part / (p - 1)
ms_oper = ss_oper / (o - 1)
ms_int = ss_int / ((p - 1) * (o - 1))
ms_rep = ss_rep / (p * o * (r - 1))
var_rep = ms_rep
var_int = max(0.0, (ms_int - ms_rep) / r)
var_oper = max(0.0, (ms_oper - ms_int) / (p * r))
var_part = max(0.0, (ms_part - ms_int) / (o * r))
var_repro = var_oper + var_int
var_grr = var_rep + var_repro
var_total = var_grr + var_part
sd_grr = np.sqrt(var_grr)
sd_part = np.sqrt(var_part)
out = {
"pct_contribution_grr": 100 * var_grr / var_total,
"pct_study_var_grr": 100 * np.sqrt(var_grr / var_total),
"ndc": int(np.floor(1.41 * sd_part / sd_grr)),
}
if tolerance is not None:
out["pct_tolerance_grr"] = 100 * 6 * sd_grr / tolerance
return out
rng = np.random.default_rng(1)
true_parts = rng.normal(10.0, 1.0, size=10)
bias_by_operator = np.array([0.0, 0.05, -0.05])
data = (true_parts[:, None, None]
+ bias_by_operator[None, :, None]
+ rng.normal(0, 0.1, size=(10, 3, 2)))
print(gage_rr_anova(data, tolerance=6.0))The data are simulated. Part values have a standard deviation of about 1.0, operators carry small biases, and the random measurement error has a standard deviation of 0.1. The result should show a small %contribution and a large ndc, since the true part spread is much larger than the measurement noise.
Edge cases and common errors
Negative variance components
Because variance components are differences of mean squares, sampling noise can make one negative. This happens most often for the interaction or the operator term when the true value is near zero. A variance cannot be negative, so the usual practice, used in the code above with max(0.0, ...), is to set it to zero. Treat a negative estimate as evidence that the true component is small, not as an error in the arithmetic.
Testing and removing the interaction
The interaction is tested with F = MS(int) / MS(rep). If the interaction is not statistically significant, many guidelines let you pool it into repeatability and refit a model without it. The AIAG guidance uses a significance level of 0.25 for this test. The high level is deliberate, because wrongly dropping a real interaction is worse than keeping a trivial one. Software defaults differ, so check what your package does. After pooling:
- σ²(rep) = (SS(int) + SS(rep)) / ((p − 1)(o − 1) + p·o·(r − 1))
- Operator and part components are compared with this pooled mean square instead of MS(int).
The function in this chapter always keeps the interaction, which is the safer default when you have not tested it.
Other traps
- Unbalanced data. The formulas assume every part-operator cell has the same number of replicates. A missing measurement breaks them. Repeat the missing run, or use software that fits a mixed model.
- Few operators. With 2 or 3 operators, σ²(oper) rests on only 1 or 2 degrees of freedom and is very uncertain. If the operators are a fixed, small group, treat the result as describing those people only.
- Parts that do not span the process. σ²(part) is estimated from the parts you chose. If they are all alike, part variation is understated and %contribution is inflated, even if the gage is excellent.
- Confusing the variance and standard deviation scales. %contribution uses variances. %study variation uses standard deviations. The same study gives 2.5% on one scale and 15.8% on the other, as in the worked example.
Summary
The ANOVA method splits the total variation of a crossed study into part, operator, interaction and repeatability components by solving the expected mean square equations. Gage R&R is repeatability plus reproducibility, where reproducibility is the operator term plus the interaction term. Negative components are set to zero, and a non-significant interaction may be pooled into repeatability.
Exercise
A study has 5 parts, 3 operators and 2 replicates. The mean squares are MS(oper) = 0.90 and MS(int) = 0.15. Calculate the operator variance component. Then explain what you would report if the result had come out as −0.02.
Show answer
σ²(oper) = (MS(oper) − MS(int)) / (p·r) = (0.90 − 0.15) / (5 × 2) = 0.075. If the estimate had been −0.02, you would set it to zero. This means operators contribute no detectable variation beyond what the part-by-operator interaction explains. A negative estimate comes from sampling noise in the mean squares, so it is not an arithmetic mistake.
Exercise
Why are the operator and part mean squares compared with MS(int) instead of MS(rep) when estimating σ²(oper) and σ²(part) in the full model?
Show answer
In the full random-effects model, the expected values of MS(oper) and MS(part) both contain the interaction term r·σ²(int). Subtracting MS(int) removes this term and isolates the operator or part variance. Subtracting MS(rep) would leave the interaction term in the estimate and overstate both components.