Linear Models in Animal Breeding

A Worked Approach

Author

Austin Putz

Welcome

ImportantUnder Construction

This book is being written, and most of it is not finished yet. Chapter 1 is drafted; every other chapter and appendix is a placeholder showing only its title and learning objectives, so you can see the shape of the whole book and follow along as it fills in.

Anything you read here may change. Do not cite it yet.

Welcome to Linear Models in Animal Breeding: A Worked Approach.

About This Book

This book provides a hands-on, example-driven introduction to mixed model equations for graduate students in animal breeding and genetics. Each chapter starts with small datasets (5-10 animals), demonstrates hand calculations step-by-step, and then scales up to realistic applications using R.

Learning Approach

Our pedagogical philosophy emphasizes:

  • Start Small: every model begins with a toy dataset of five to ten animals that you can solve by hand
  • Numbers Before Symbols: the operation is performed on real numbers first, and the general formula arrives afterwards as a name for something you have already done — never before it
  • Show Every Step: every symbol is introduced as a name for something already on the page, and the dimensions of every matrix are stated
  • Hand First, Then R: solve it with a calculator, then reproduce the identical answer in R, then see the one-line package call that does the same thing
  • Code You Can Read: the R is shown, not folded away, and is written to be retyped
  • Check Yourself: short predict-then-check questions, placed where you could have guessed the answer but have not been told it yet

What You’ll Learn

By working through this book, you will:

  • Understand the theory and practice of mixed model equations (MME)
  • Master pedigree-based relationship matrices and their inverses
  • Implement animal models for single and multiple traits
  • Prepare data properly: contemporary groups, connectedness, and pedigree quality
  • Model longitudinal data with random regressions and reaction norms
  • Handle categorical traits with threshold models and survival analysis
  • Fit non-additive, multibreed, and crossbred models
  • Estimate variance components using ANOVA, REML, AI-REML, and Gibbs sampling
  • Validate a genetic evaluation for accuracy, bias, and dispersion

Prerequisites

Students using this book should have:

  • Elementary statistics (linear regression, variance components, distributions)
  • R programming experience (helpful but not strictly required - all code is explained)

No prior linear algebra is assumed. Chapter 1 develops every matrix operation the book uses, and tells you which sections each later chapter depends on.

Scope

This book covers the pedigree-based mixed model. Genomic selection - the genomic relationship matrix, GBLUP, single-step, and the Bayesian alphabet - is a large enough subject to need its own volume, and is deferred to a companion book rather than compressed into a chapter here. Large-scale computation is likewise deferred, apart from Chapter 24, which exists so that readers understand why production evaluations are not solved the way the examples in this book are.

The chapters

Every chapter is listed below, and the sidebar on the left carries the same list on every page. Chapter 6 is the centre of the book — everything in Part I builds toward it, and everything after it is a variation on it.

Chapters marked ✏️ are drafted. The rest are placeholders carrying their learning objectives only.

Part I — Background

Chapter What it does
1 ✏️ Matrix Algebra for Animal Breeders Only the linear algebra the book actually uses, with a map of what is needed where
2 Linear Models Fixed effects only. Build X, solve the normal equations, confront non-full-rank
3 Mixed Models Without Relationships Z and random effects, with no genetics attached yet
4 Pedigrees and Relationship Matrices A and A⁻¹ — the object that makes the animal model work
5 Data Preparation and Connectedness What goes wrong before a model is ever fitted. Where real analyses fail

Part II — Core Animal Models

Chapter What it does
6 The Animal Model The central chapter. Solve the full MME with A⁻¹, then interpret what came out
7 Equivalent and Reduced Models Sire, sire–MGS, and reduced animal models as data reduction
8 Random Environmental Effects Repeatability and common environment: a second random effect that is not genetic
9 Genetic Groups Unknown parent groups, and an honest statement of what they get wrong
10 Maternal Effects Models Two correlated genetic effects on one phenotype

Part III — Advanced Model Structures

Chapter What it does
11 Multivariate Models Several traits at once; the Kronecker product earns its keep
12 Longitudinal Data and Random Regression Traits measured along a trajectory
13 Social Interaction Models An animal’s phenotype depends on its group-mates’ genes

Part IV — Categorical and Time-to-Event Traits

Chapter What it does
14 Threshold Models Binary and ordered categorical traits — same model, more thresholds
15 Survival Analysis Time-to-event data and censoring

Part V — Non-additive Genetic Effects

Chapter What it does
16 Dominance Models Genotypic value, not just breeding value
17 Epistasis Models Why, in practice, nearly everything comes out additive

Part VI — Multibreed and Crossbred Evaluation

Chapter What it does
18 Multibreed Models More than one breed in a single evaluation
19 Crossbred Evaluation and CCPS Selecting purebreds for crossbred performance

Part VII — Variance Component Estimation

Chapter What it does
20 ANOVA and Henderson’s Methods Where variance components came from, and why they had to be replaced
21 REML The workhorse
22 Bayesian Estimation via Gibbs Sampling The third route to the same components, and the one that gives full uncertainty

Part VIII — Validation and Computation

Chapter What it does
23 Validating Genetic Evaluations How do you know the evaluation works?
24 Solving the MME at Scale What production software actually does. Deliberately thin

Appendices

A — Notation Reference · B — BLUP Derivation · C — Inbreeding Algorithms · D — Legendre Polynomials · E — Deregression · F — R Code Reference · G — Datasets · H — Solutions to Exercises · I — BLUPF90 Guide

Appendix A is the one to bookmark. It is the authoritative notation reference and carries an index of every Key Equation in the book, one line each — the single page to revise from.

How to Navigate

Chapters 1-6 form the essential foundation and should be read in order. After that, you can follow different paths depending on your interests:

  • Linear path (comprehensive): read chapters sequentially
  • Longitudinal models: Ch 1-6, 8, 11-12, 21
  • Categorical and fitness traits: Ch 1-6, 14-15, 22
  • Crossbreeding: Ch 1-6, 9, 11, 16, 18-19
  • Variance components: Ch 1-6, 20-22, 23

Each chapter lists its prerequisites at the start.

How to read a chapter

Every chapter is built the same way, so once you have read one you know where everything is.

The order is always the same. A chapter opens on a small dataset, works it in literal numbers, and only then writes the general form. A formula never arrives before the worked example that earns it. If you want the rule without the walk-through, skip to the boxed equation — but the numbers above it are where the understanding actually comes from.

Coloured boxes mean different things. The colour tells you what to do with the box:

Box What it is
Key Equation The one to memorise. One to three per chapter, and nothing else is boxed
Derivation Optional, collapsed. Why the result holds in general. Skip it on a first read
Check Yourself A five-second self-test. The question is visible, the answer is hidden — try it before opening
Common Mistake The error students actually make, and how to catch it
In R An R-specific trap or idiom
Notation Watch Where the literature disagrees with itself
In Practice What a real national evaluation does
Beyond This Book A scope boundary, and where the topic is covered instead

Displayed equations come in three kinds. A boxed, numbered equation is one you should be able to write from memory. Ordinary display maths in the flow is something to follow with the book open. Anything inside a collapsed grey Derivation box is optional.

The R is meant to be typed. Code is shown by default, not folded away, and every chunk prints the same number the hand calculation produced so you can check the two against each other. Open an R session alongside the book and work down the page. The “Code” menu at the top right will download the source of any chapter.

Some sections have short animations. Where a calculation is a sequence — a row walking against a column, a matrix filling in cell by cell — there is a short silent clip showing the steps. They are never the only place something is explained: everything in a clip is also in the text, so nothing is lost if you skip them or are reading in print.

Datasets referenced in examples are available in the data/ directory of the book repository.

Getting set up in R

The book is written to be read with an R session open beside it. Everything you need is free, and the whole setup takes about ten minutes.

1. Install R

R itself comes from CRAN, the Comprehensive R Archive Network:

Any version from 4.3 onward will run everything in this book. To check what you have, open R and run:

R.version.string

2. Install an editor

R on its own is a bare console. You want an editor that keeps your script, your console, your plots and your data in one window:

  • RStudio Desktop — free, the standard choice, and what most course material assumes
  • Positron — Posit’s newer editor, if you also work in Python
  • VS Code with the R extension, if you already live there

Install R first, then the editor: the editor looks for an existing R installation when it starts.

3. Install the packages

Chapter 1 needs nothing at all. Matrix, MASS and survival are recommended packages — they ship with every standard R installation, so the whole of the matrix algebra chapter runs on a fresh install with no downloads.

Later chapters use a handful of specialist packages. Install them when you reach them, or all at once now:

install.packages(c(
  "lme4",         # general mixed models (Ch 3)
  "pedigreemm",   # pedigree-based mixed models (Ch 4, Ch 5)
  "nadiv",        # relationship matrices and their inverses (Ch 4, Ch 16)
  "sommer",       # REML for animal models, multi-trait (Ch 10, Ch 11, Ch 21)
  "MCMCglmm",     # Bayesian mixed models via MCMC (Ch 14, Ch 22)
  "coda",         # MCMC convergence diagnostics (Ch 22)
  "coxme",        # survival models with random effects (Ch 15)
  "orthopolynom", # Legendre polynomials (Ch 12)
  "tidyverse"     # data preparation and validation (Ch 5, Ch 23)
))

Two of these — sommer and MCMCglmm — compile from source on some systems and can take several minutes each. That is normal; let them finish.

To check that a package installed correctly, load it:

library(sommer)

If that returns a prompt with no error, you are set.

4. Running the book’s code

Every code chunk in this book is shown, not hidden, because the code is part of what is being taught rather than an appendix to it. Three ways to get it:

  • Copy one chunk. Hover over any code block and a copy button appears in its top-right corner.
  • Take a whole chapter. The </> Code menu at the top right of each page will show or hide every chunk at once, or download that chapter’s source.
  • Clone the whole book. If you want the datasets and the generating scripts as well:
git clone https://github.com/austin-putz/linear-models-in-animal-breeding.git

Then, from the project directory, Rscript setup.R installs the full package list in one go.

Work down the page rather than skipping to the end of a section: each chunk prints the same number the hand calculation above it produced, and comparing the two is the point of having the code there at all.

Citation

The book is versioned. Each release is tagged in the repository and can be retrieved exactly as it was, so a citation that names its version can always be checked. The version you are reading is 0.0.0-dev+080aefa, released 2026-09-12 — it is also printed in the footer of every page, in both the website and the PDF. Cite it as:

Putz, Austin (2026). Linear Models in Animal Breeding: A Worked Approach, version 0.0.0-dev+080aefa. https://austin-putz.github.io/linear-models-in-animal-breeding/

@book{putz_linear_models,
  author    = {Putz, Austin},
  title     = {Linear Models in Animal Breeding: A Worked Approach},
  year      = {2026},
  version   = {0.0.0-dev+080aefa},
  url       = {https://austin-putz.github.io/linear-models-in-animal-breeding/},
  note      = {Version 0.0.0-dev+080aefa, released 2026-09-12}
}

A version ending in -dev+ and a commit hash is a development build of the website between releases. It is still an exact reference — the hash identifies the text — but prefer a released version when you have the choice. Released versions and what changed between them are listed in the changelog.

License

Creative Commons License

This book is licensed in two parts, split by whether a file is something you run or something you read.

  • The code — the R in every chapter, the scripts that generate the datasets, the manim source and the build tooling — is under the MIT License. Reuse it freely, including commercially.
  • The book — the prose, the datasets, and the rendered figures and clips — is under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. You are free to share and adapt it for non-commercial purposes, provided you give appropriate credit and distribute your contributions under the same license.

The full breakdown of which files fall on which side is in the repository’s LICENSE file.

Feedback and Contributions

A wrong number, a typo, a section you did not follow, an idea — each has a route, and the Reporting Errors and Contributing page at the end of the book says which is which. Every report is read, the fix goes into the next release, and reporters are credited.

Acknowledgments

Special thanks to the students who provided feedback on early drafts, and to the open-source community for the tools that made this book possible — Quarto, R, the Matrix package, and Manim for the animations.


Ready to begin? Start with Chapter 1: Matrix Algebra for Animal Breeders.