Mixed effects model: random factors and variance components
A mixed effects model contains both fixed factors, whose specific levels you chose and care about (two cure temperatures, three machine settings), and random factors, whose levels are a sample from a larger population (five batches out of all the batches the supplier will ever make, six operators out of the workforce). It estimates the fixed effects, splits the variation into variance components for each random source, and, most important, tests the fixed effects against the right error term.
When to use it
- Some factors are samples: material lots, batches, parts, operators, days, test sites. You want conclusions that hold for future batches or operators, not just the ones in the study.
- You want to know how much of the total variation each source contributes: batch to batch, within batch, measurement.
- A fixed factor is crossed with a random one, such as temperature tested on several batches, and you need a valid test of the fixed factor.
- Data are unbalanced, with missing runs, which simple ANOVA formulas cannot handle.
Gage R&R studies are a special case: parts and operators are random, and the variance components are the repeatability and reproducibility. Nested random factors, such as parts that only one operator measures, appear in nested gage R&R. With only fixed factors, use the general linear model.
How it works
Take a fixed factor A (a levels) crossed with a random factor B (b levels), with n replicates per cell:
y = μ + αᵢ + Bⱼ + (αB)ᵢⱼ + ε, Bⱼ ~ N(0, σ²_B), (αB)ᵢⱼ ~ N(0, σ²_AB), ε ~ N(0, σ²)The αᵢ are fixed numbers to estimate; Bⱼ and (αB)ᵢⱼ are random, described only by their variances. The ANOVA sums of squares are the same as in a fixed-effects analysis, but the expected mean squares differ. In the unrestricted model used here:
| Source | Expected mean square |
|---|---|
| A (fixed) | σ² + nσ²_AB + (fixed effect of A) |
| B (random) | σ² + nσ²_AB + a·n·σ²_B |
| A × B (random) | σ² + nσ²_AB |
| Error | σ² |
Each F test divides by the mean square whose expectation matches everything except the term tested. So the fixed factor A is tested against the A × B interaction, not against the error: the question is whether A's effect is consistent across batches, and the batch-to-batch variation in that effect is the yardstick.
Variance components come from setting the mean squares equal to their expectations:
σ̂²_B = (MS_B − MS_AB) / (a·n) σ̂²_AB = (MS_AB − MS_E) / n σ̂² = MS_EThis is the ANOVA (method of moments) estimator. Modern software usually fits mixed models by REML (restricted maximum likelihood), which also handles unbalanced data and never gives negative variances. For balanced data like the example, REML gives the same components whenever none of the ANOVA estimates is negative.
Example
An assembly plant wants to raise the cure temperature of a structural adhesive from 150 to 170 °C. Since every batch of adhesive is a little different, the engineer picks five batches at random from the supplier's recent deliveries and bonds two lap-shear coupons per batch at each temperature (20 coupons, run in random order). Shear strength (MPa):
| Batch | 150 °C | 170 °C |
|---|---|---|
| 1 | 26.3, 26.7 | 28.7, 29.4 |
| 2 | 19.6, 20.2 | 22.4, 22.4 |
| 3 | 24.4, 24.6 | 26.6, 25.7 |
| 4 | 23.7, 23.2 | 24.5, 25.1 |
| 5 | 25.7, 25.9 | 24.8, 24.6 |
Temperature is fixed; batch and the temperature × batch interaction are random:
| Source | DF | SS | MS | F | P | Tested against |
|---|---|---|---|---|---|---|
| Temperature | 1 | 9.661 | 9.661 | 4.37 | 0.105 | Temp × Batch |
| Batch | 4 | 92.315 | 23.079 | 10.43 | 0.022 | Temp × Batch |
| Temp × Batch | 4 | 8.847 | 2.212 | 17.35 | < 0.001 | Error |
| Error | 10 | 1.275 | 0.1275 | |||
| Total | 19 | 112.098 |
Variance components:
| Source | Variance | Share | Standard deviation (MPa) |
|---|---|---|---|
| Batch | 5.217 | 81.7% | 2.284 |
| Temp × Batch | 1.042 | 16.3% | 1.021 |
| Error (coupon to coupon) | 0.128 | 2.0% | 0.357 |
The mean gain from 150 to 170 °C is 1.39 MPa. With the interaction mean square as the error term (4 degrees of freedom, t = 2.776), its 95% confidence interval is −0.46 to 3.24 MPa.
How to read the results
- The temperature gain is not proven for future batches. It ranges from +2.55 MPa (batch 1) to −1.10 MPa (batch 5). The interaction is large and real, so five batches cannot pin down the average gain: p = 0.105.
- A fixed-effects analysis would mislead. Testing temperature against the coupon-to-coupon error (MS = 0.1275, 10 degrees of freedom) gives F = 75.8 and p < 0.001, with an interval of 1.03 to 1.75 MPa. That answer is about these five batches only, and it ignores that the next batch may respond differently.
- Batch is the dominant source of variation. Batch-to-batch differences account for about 82% of the variance; a single coupon's strength has a standard deviation of about 2.5 MPa from all random sources together. Working with the supplier on batch consistency matters more than the cure temperature.
- Measurement and coupon preparation are not the problem. Their standard deviation is only 0.36 MPa.
- Next step: find out why batch 5 behaves differently (age, storage, a different filler lot) and test more batches before changing the cure temperature.
Common mistakes
- Treating a random factor as fixed. The tests then answer a question about the specific batches in the study, and the p-values for fixed factors come out far too small.
- Too few levels of the random factor. With five batches, σ²_B rests on 4 degrees of freedom and is very uncertain. Aim for more levels rather than more replicates per level.
- Ignoring negative variance estimates. With the ANOVA method, a component can come out negative; treat it as zero and consider whether the model is right. REML avoids this.
- Calling a factor random just because it varies. A factor is random when its levels are a sample from a population you want to generalize to; two specific ovens you will keep using are fixed.
- Confusing replicates with repeats. Two readings of the same coupon are not two coupons; they measure only the gage.
Frequently asked questions
What is the difference between fixed and random factors?
Fixed factor levels are chosen on purpose and are the only ones you care about. Random factor levels are a sample from a larger population, and you care about the population's variation, not the individual levels.
What are variance components?
The parts of the total variance that come from each random source. Here 5.22 MPa² from batches, 1.04 from the batch-by-temperature interaction and 0.13 from coupon to coupon.
Why is the fixed factor tested against the interaction?
Because its effect varies from batch to batch. To claim the effect holds for batches in general, you compare it with how much it varies between batches, which is what the interaction mean square measures.
What is REML?
Restricted maximum likelihood, the standard method for estimating variance components in mixed models. It handles unbalanced data and, for balanced data with positive estimates, agrees with the ANOVA method.