Quick answers
- What is a mixed model?
- A linear model with both fixed effects (treatments compared directly) and random effects (sources of variation, such as blocks or animals, treated as a sample from a larger population).
- What is the difference between fixed and random effects?
- Fixed: levels chosen on purpose, and you compare them (four diets). Random: levels are a sample, and you care about how much they vary (six litters out of all litters).
- When should I use a linear mixed model?
- Whenever the design has more than one source of random variation: random blocks, split-plots, nested sampling (pigs in pens), repeated measures, or trials across locations and years.
- What is a split-plot design?
- A factorial in which one factor is applied to large main plots and the other to subplots within them. It has two experimental units and two error terms.
- What is ANCOVA?
- Analysis of covariance: ANOVA plus a continuous covariate, such as start weight, that explains part of the response. It adjusts treatment means and reduces error.
- What is BLUP?
- Best linear unbiased prediction: the estimate of a random effect, such as a sire's breeding value or a litter's effect, shrunk toward zero according to how much information there is.
On this page
Fixed vs random effects
| Fixed effect | Random effect | |
|---|---|---|
| Levels | Chosen deliberately | A sample from a larger population |
| Question | Do these levels differ? By how much? | How much variation does this source add? |
| Inference | Only to the levels in the trial | To the whole population of levels |
| Examples | Diet, variety, N rate, sex | Litter, block, pen, location, year, sire, animal |
| Estimated as | Means and differences | Variance components (and BLUPs) |
Some factors are debated. Years are random if they stand for the range of seasons the results should cover, fixed if you chose specific contrasting years. Blocks are often treated as random so that conclusions extend beyond the particular blocks, and because random blocks recover information when data are unbalanced.
Random blocks: the pig trial as a mixed model
yᵢⱼ = μ + τᵢ + Lⱼ + εᵢⱼ, with Lⱼ ~ N(0, σ²_L) and εᵢⱼ ~ N(0, σ²)
Mixed models estimate variance components by REML (restricted maximum likelihood) and test fixed effects with approximate degrees of freedom (Satterthwaite or Kenward-Roger). The standard error of a diet mean now includes litter variation (0.033 vs 0.019 kg/day), because it describes pigs from any litter, not just these six.
Split-plot designs: two sizes of experimental unit
Some factors need big plots: irrigation, tillage, sowing date, or a variety sown with a drill. A split-plot design puts these on main plots and applies a second factor, such as nitrogen rate, to subplots within each main plot. In animal science the same structure appears when a diet is fed to a pen (main plot) and an implant is given to individual pigs within it (subplot).
yᵢⱼₖ = μ + Bₖ + Vᵢ + (BV)ᵢₖ + Nⱼ + (VN)ᵢⱼ + εᵢⱼₖ
The main-plot error (BV)ᵢₖ, block × variety, is the error for testing varieties. Subplot treatments and the interaction are tested against the smaller subplot error.
The rule: every factor is tested against the variation among the units it was randomized to. Strip-plot (strip-block) designs and split-split-plots extend the same idea.
Nested designs and subsampling
A factor is nested in another when each of its levels appears within only one level of the other: pigs within pens, plants within plots, leaves within plants, sires within breeds. Crossed factors, by contrast, appear in every combination (every diet in every litter).
- If a diet is fed to whole pens of 8 pigs, the pen is the experimental unit and the pigs are subsamples. The correct error for diets is pen within diet; using the pig-to-pig variation is pseudoreplication.
- A mixed model with pen as random,
adg ~ diet + (1 | pen), gives the right test and also estimates how much variation comes from pens and from pigs within pens, which helps plan the next trial. - More subsamples per unit help only a little; more experimental units help much more.
Analysis of covariance (ANCOVA)
ANCOVA adds a continuous covariate measured before treatments act, such as initial weight, stand count or a pre-trial yield, to the model. It reduces error variance and adjusts treatment means to a common covariate value.
yᵢⱼ = μ + τᵢ + β(xᵢⱼ − x̄) + εᵢⱼ
- The covariate must not be affected by the treatments; measure it before they start.
- Check that slopes are similar across treatments (no treatment × covariate interaction).
- A covariate is an alternative or a complement to blocking: blocks group units, covariates adjust for a measured value.
Random coefficients and BLUP
In a random coefficient model, each subject has its own intercept and slope, drawn from a population: growth curves of individual animals, or the yield response to nitrogen at each of many farms. The model estimates the average line and how much individual lines vary around it.
Random effects are predicted by BLUP (best linear unbiased prediction). BLUPs shrink extreme values toward the mean, more so when a level has little data, which makes them better predictors than raw averages. In the pig trial the BLUPs of the litter effects range from −0.100 kg/day (litter 4) to +0.076 (litter 2).
BLUP is the foundation of genetic evaluation in animal breeding: a sire's estimated breeding value is a BLUP using records of all his relatives, weighted by their genetic relationships (Henderson's mixed model equations). Plant breeders use the same machinery for genotype BLUPs in multi-environment trials.
Mixed models in R and SAS
In R
library(lmerTest)
m1 <- lmer(adg ~ diet + (1 | litter), data = dat) # random blocks
anova(m1); VarCorr(m1); ranef(m1) # tests, variances, BLUPs
wheat$block <- factor(wheat$block); wheat$N <- factor(wheat$n_rate)
m2 <- lmer(yield ~ variety * N + (1 | block) + (1 | block:variety), data = wheat) # split-plot
anova(m2)
m3 <- lm(adg ~ start_wt + diet, data = dat) # ANCOVA
emmeans::emmeans(m3, "diet") # adjusted meansIn SAS
proc mixed data=pigs;
class litter diet;
model adg = diet / ddfm=kr;
random litter / solution; /* BLUPs of litters */
lsmeans diet / adjust=tukey;
run;
proc mixed data=wheat;
class block variety n_rate;
model yield = variety n_rate variety*n_rate / ddfm=kr;
random block block*variety; /* main-plot error */
run;Key takeaways
- Fixed effects are compared directly; random effects are a sample whose variance you estimate.
- Mixed models handle random blocks, split-plots, subsampling, repeated measures and multi-site trials.
- In a split-plot, test each factor against the variation among the units it was randomized to; the wrong analysis can be wildly overconfident.
- ANCOVA adjusts treatment means for a covariate measured before treatment and reduces error.
- BLUPs predict random effects with shrinkage; they underlie breeding values.
Questions people ask
Should blocks be fixed or random?
Either gives the same treatment test with balanced data. Random blocks are preferred when data are unbalanced or you want inference beyond the specific blocks; with very few blocks (2 or 3) the block variance is poorly estimated.
What is REML?
Restricted maximum likelihood, the standard method for estimating variance components. It corrects the bias that ordinary maximum likelihood has with small samples.
What does a variance component of zero mean?
That the data show no detectable variation from that source. Software may report a 'singular fit'; the term can usually stay in the model to reflect the design.
What is the difference between PROC GLM and PROC MIXED?
PROC GLM fits fixed-effects models and treats random effects awkwardly. PROC MIXED (and GLIMMIX) fit mixed models properly, with correct standard errors and degrees of freedom.
Is a split-plot the same as a nested design?
Related: subplots are nested within main plots. But in a split-plot the subplot factor is a treatment crossed with the main-plot factor, so the interaction is estimated.
Sources
- Littell, R. C., Milliken, G. A., Stroup, W. W., Wolfinger, R. D., and Schabenberger, O. (2006). SAS for Mixed Models (2nd ed.). SAS Institute.
- Kaps, M., and Lamberson, W. R. (2017). Biostatistics for Animal Science (3rd ed.), chapters on random effects, mixed models, nested and split-plot designs, and analysis of covariance. CABI.
- Henderson, C. R. (1975). Best linear unbiased estimation and prediction under a selection model. Biometrics, 31(2), 423–447.
- Bates, D., Mächler, M., Bolker, B., and Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1).