Theory: how sommer parameterizes and optimizes covariance structures
sommer development team
2026-10-06
Source:vignettes/sommer.theory.Rmd
sommer.theory.RmdThis vignette is written like a short book. Each chapter builds on the previous one, and all chapters share the same notation so formulas can be compared directly across chapters:
- : a natural parameter — a variance, a correlation, a range — the thing that has a real statistical meaning but also has to obey a rule (e.g. “must be positive”).
- : a working parameter — the same information, but recoded so it is allowed to be any real number, with no rule to break.
- : the transform connecting them, .
- : the (dimensionless) covariance shape, normalized so .
-
: the single overall scale, owned by
vsm(). - : the precision (inverse covariance shape).
- : the structural derivative of the shape with respect to working parameter .
Table of contents
- Chapter 1: The linear mixed model and Henderson’s equations
- Chapter 2: Parameterization theory, explained from first principles
- Chapter 3: Catalog of covariance structures
- Chapter 4: REML, AI-REML, and
ai_mme_sp2() - Chapter 5: Worked examples, one per structure
- Chapter 6: End-to-end numerical trace, from to the REML objective
Chapter 1: The linear mixed model and Henderson’s equations
1.1 The model
fits
- : fixed effects.
-
:
random effects, one term per
random=~...entry. - , : the covariance matrices this whole vignette is about.
sommer never treats or as free unconstrained matrices. Every one is built from a small number of variance components (Chapter 2), and REML estimates , not the matrix entries directly.
1.2 Henderson’s Mixed Model Equations (MME)
Rather than maximizing the marginal likelihood of directly (which needs , generally dense and huge), Henderson’s equations solve for jointly using only and :
with .
Why this matters for parameterization: every
quantity sommer actually needs —
,
its log-determinant, and the REML score/AI-matrix — is built from
inverses
(,
)
and their derivatives with respect to
,
never from
or
themselves except to invert them once per structure per iteration. This
is why sommer’s internal name for
within a structure is Lambda
().
1.3 Where covariance structures come in
For a random term built with
vsm(dsm(Env), usm(Trait), ism(Line)), sommer constructs
- Exactly one free scale
per
vsm()call (itssigma2argument). - Every other factor (
dsm,usm,ism, …) supplies a dimensionless shape with .
This separation of scale (one parameter, always
variance-like) from shape (any number of parameters, some
variance-like, some correlation-like) is the central design decision
explored in the rest of this vignette, and it directly determines how
derivatives are computed in ai_mme_sp2().
1.4 Preview of the key distinction (developed in Chapter 4)
| Variance-type parameter | Correlation-type parameter | |
|---|---|---|
| Example |
sigma2, dsm() ratios, fam()
specific variances |
csm()/ar1m() rho,
usm()/corgm() off-diagonal terms |
| Effect on | rescales one or few diagonal blocks | reshapes the entire matrix jointly |
| sparse / diagonal | dense | |
| Average vs Expected Information | typically agree closely | can diverge — needs EM/AI blending |
| Practical consequence | fast trace/derivative shortcuts available | full dense chain-rule required |
Chapter 2: Parameterization theory, explained from first principles
2.1 Why we can’t just let the computer search freely
Imagine you are tuning two dials for a model:
- Dial A controls a variance. It must always stay strictly positive — a “negative amount of variability” makes no sense.
- Dial B controls a correlation. It must always stay strictly between and — a correlation of or makes no sense either.
If you let an optimization algorithm (the computer’s “hill-climbing” procedure that tries to improve the fit step by step) move these dials by any amount, in any direction, it will sooner or later try an illegal value: a negative variance, or a correlation bigger than 1. At that point the model is broken (the covariance matrix stops being a valid one — technically it is no longer positive definite, which is the mathematical way of saying “this could actually occur as a covariance of real data”).
sommer’s answer to this problem is always the same trick, used for every single covariance structure in the package:
Never let the optimizer touch the real dial (). Instead, give it a fake dial () that can be turned all the way in either direction, forever, without ever breaking anything. Then use a fixed recipe () to translate the fake dial’s position into a legal value of the real dial.
Formally: , where ranges over all real numbers ( to ) and is built so that always lands in the legal range for , no matter what is.
This is exactly the same idea used elsewhere in statistics: for example, when you model a probability (which must stay in ) with a logistic regression, you don’t optimize the probability directly — you optimize an unconstrained “logit” score and convert it to a probability at the very end. sommer does the same thing, systematically, for every variance and correlation in every covariance structure it supports.
2.2 The working-parameter vector
In sommer’s code, the collection of fake dials for one covariance
structure is called par (short for “working parameters”),
and it always lives in the CovarianceFactor descriptor
returned by every constructor (csm(), ar1m(),
usm(), …). Three related pieces travel together:
-
par— the current numeric values of . -
free— a logical flag per entry: is this estimated by REML, or is the user holding it fixed (fixed=TRUE)? -
par_names— a human-readable label per entry, e.g."rho"or"variance_ratio[B]", used when you callsummary()on a fitted model.
REML (Chapter 4) works entirely with
par/.
It never sees
directly;
is only computed when sommer needs to actually build the
covariance matrix
,
or when it reports results back to you in a human-readable form.
2.3 Transform family 1 — variances: the exponential map
The rule: .
The recipe: .
Why this works: no matter what real number is — very negative, zero, very positive — is always a positive number. As , (but never reaches it); as , . Every positive number is reachable by exactly one (the inverse recipe is ).
A nice bonus: the “speed” at which changes as you nudge (its derivative, ) is proportional to itself. This means equal steps in -space are equal-percentage steps in -space (multiplicative, like moving up a musical scale in octaves) rather than equal-amount steps — exactly the natural way variances tend to move (a variance going from 1 to 2 “feels” like the same size change as going from 10 to 20).
sommer almost never applies this to a raw variance, though. Instead it applies it to a ratio relative to a reference level — this detail matters because of scale confounding (see 2.6), so let’s define it now since you will see it in almost every structure in Chapter 3:
Level 1 is always the reference: is fixed at 1 by definition, so only working parameters are needed to describe relative variances.
2.4 Transform family 2 — bounded quantities: logit and tanh
The rule: , a bounded open interval — e.g. a correlation , or a compound-symmetry .
The recipe (general bounded interval):
The sigmoid function is the same S-shaped curve used in logistic regression: it always outputs a number strictly between 0 and 1, approaching 0 as and approaching 1 as , and it is smooth and increasing everywhere. Stretching and shifting its output () maps it onto any open interval instead of just .
The recipe (symmetric interval ): when the bounds are exactly and (as for a plain correlation), sommer often uses the equivalent but more compact hyperbolic tangent:
which is just the logit recipe above rescaled — same S-shape, same guarantee ( is always strictly between and ), just centered at 0 instead of at .
Why bother with a whole interval instead of just “positive,” like variances? Because a correlation has two walls (an upper and a lower limit), while a variance only has one (a floor at 0, no ceiling). The sigmoid/tanh family is the natural tool whenever there are two walls to respect simultaneously.
A subtlety that matters in Chapter 4: near the middle of the interval, changes quickly as moves — a small step in makes a decent-sized change in . But near the two walls (as gets very large in either direction), becomes almost flat: huge changes in barely move at all. This is deliberate and useful — it means that if REML tries to push a correlation toward its boundary, the working scale automatically resists further movement (the “gas pedal” stops doing much once you’re already flooring it), rather than needing an artificial rule bolted on afterward.
2.5 Transform family 3 — many correlated quantities at once (factorizations)
Families 1 and 2 work great for a single variance or a single correlation, one dial at a time. But some structures have many correlations that all have to be jointly consistent with each other — for example, an unstructured correlation matrix has 3 pairwise correlations, but not every combination of 3 numbers in is a valid correlation matrix (try — no data set can ever produce that).
So instead of transforming each correlation separately, sommer reparameterizes the whole matrix at once through a factorization — a recipe that builds the matrix out of simpler unconstrained ingredients in such a way that the result is automatically valid, no matter what those ingredients are. The two building blocks used throughout the package are:
-
Cholesky factor: any covariance/correlation matrix
can be written as
for some lower-triangular matrix
with positive diagonal. Conversely, any lower-triangular
with positive diagonal, multiplied by its own transpose, automatically
produces a valid (positive definite)
— there is no combination of entries of
that can break this. So sommer parameterizes
instead of
:
the off-diagonal entries of
are unconstrained working parameters directly, and the diagonal entries
of
go through the family-1 exponential recipe (to keep them positive). Used
by
usm()(Chapter 3.7) and, restricted to unit-diagonal , bycorgm()(Chapter 3.8). -
Loadings + diagonal (“factor-analytic”) factor:
for a rectangular
loading matrix
(any real numbers) and a diagonal matrix
with positive entries (again via the family-1 recipe). A sum of
“something squared”
(,
always positive semi-definite) and “something positive on the diagonal”
()
is always positive definite — again, automatically, for any
real
.
Used by
fam()/rrcm()(Chapter 3.9) and, in a triangular/banded variant, byantem()(Chapter 3.10).
The common thread across all three families: every recipe in this chapter is a one-way-safe translation from “any real number(s) at all” to “a legal /.” This is why sommer’s optimizer (Chapter 4) can take a Newton step of any size, in any direction, in -space, and never produce an invalid model — the only thing that can still go wrong is that the fit gets worse, which is a completely different (and much easier to handle) problem than breaking the math.
2.6 Why the reference level matters: avoiding scale confounding
Recall from Chapter 1 that a vsm() term is a Kronecker
product
.
If every
were allowed to carry its own free overall scale (instead of being
pinned to
via a reference level), the model would have infinitely many
combinations that produce the exact same
— for instance doubling
while halving every entry of
changes nothing observable. This is called
non-identifiability: REML would have no way to choose
among the infinitely many equally-good answers, and the optimizer would
wander aimlessly or fail to converge.
sommer avoids this by a strict convention, applied without exception:
every covariance-shaping factor is normalized so its first diagonal
entry is exactly 1
(),
and the one and only free overall scale lives in
vsm()’s sigma2 argument. This is why,
throughout Chapter 3, you will see
“
is the reference, fixed at 1” repeated for structure after structure —
it is not a coincidence, it is the mechanism that keeps the whole model
identifiable.
Chapter 3: Catalog of covariance structures
For each structure: the shape formula (normalized so ), the working parameters and their transform (from Chapter 2), and whether it is fundamentally a variance-type or correlation/shape-type parameterization (this label is used again in Chapter 4 and in the matching worked example of Chapter 5).
3.1 ism(x) — identity
Simplest possible shape: independent, homoscedastic levels. Used as
the “main effect” incidence in most vsm() calls, or as a
Kronecker factor when no structure is desired on one dimension.
3.2 dsm(x, values, fixed, theta) /
atm(x, levs, values, fixed) — heterogeneous diagonal
variances
Family-1 (exponential/log-ratio) transform, applied to every level
except the reference. Pure variance-type structure:
free log-variance ratios, no correlation at all (off-diagonal is exactly
0). atm() is the same construction restricted to a
user-selected subset of levels (levs); unselected levels
get zero columns in the design matrix and are excluded from
.
3.3 csm(x, rho, fixed, variance, values) — compound
symmetry
Family-2 (bounded logit) transform: .
-
variance="homogeneous"(default): only is free — a single correlation-type parameter. -
variance="heterogeneous": additionally appends family-1 log-variance-ratios , so with the homogeneous compound-symmetric correlation. A mixed parameterization: 1 correlation-type + variance-type parameters.
3.4
ar1m/ar2m/ar3m/toeplitzm
— autoregressive & general Toeplitz correlation
All parameterize an ordered correlation matrix through partial autocorrelations (PACF) , family-2 (tanh) transform , reconstructed to full correlations (lag ) via the Durbin–Levinson recursion:
-
ar1m(): order 1, (the classical AR(1) correlation), 1 correlation-type parameter. -
ar2m()/ar3m(): order 2/3, PACF vector of length 2/3 mapped through Durbin–Levinson to for all lags up to . -
toeplitzm(): order (fully general stationary Toeplitz correlation, no autoregressive-order restriction) — the most flexible member of this family, still guaranteed valid for any PACF in (this is exactly the joint-validity guarantee discussed in Chapter 2.5, achieved here through PACF rather than through a matrix factorization). - All four support
variance = "heterogeneous"(AR family only;toeplitzm()is shape-only) the same way ascsm(): append family-1 log-variance-ratios after the PACF working parameters.
3.5 mam/ma1m/ma2m —
moving-average covariance
Working parameters are the raw MA coefficients themselves (, no transform at all) — unlike AR, any finite MA coefficients produce a valid covariance; invertibility of the MA polynomial is not required to define the covariance matrix, so no bounding transform is needed. This is the one “ordered” structure whose working parameter equals its natural parameter directly. Purely a correlation/shape-type structure (no variance option).
3.6 corgm(x, theta, fixed) — general correlation
matrix
Family-3 (factorization) transform: the strictly-lower-triangular
entries of
are working parameters directly (no further per-entry transform is
needed — Chapter 2.5 explains why any real lower-triangular
with unit diagonal automatically gives a valid
).
purely correlation-type parameters, no variance
component at all (contrast with usm() below, which also
carries diagonal/variance information).
3.7 usm(x, theta, fixed) — general unstructured
covariance
Family-3 (Cholesky factorization) transform: for each free entry of below the diagonal — the off-diagonal entries are working parameters directly (), the diagonal entries go through the family-1 log transform (, keeping hence nonsingular). Total free parameters (the is , fixed by the Chapter 2.6 reference-level convention).
This is the maximally flexible valid shape for levels — every possible covariance shape is reachable, at the cost of parameters. It mixes variance-type (log-diagonal) and correlation-type (off-diagonal) working parameters in a single structure.
3.8 fam(x, k, loadings, specific, fixed) /
rrcm(x, k, loadings, fixed) — factor-analytic
covariance
Family-3 (loadings + diagonal) transform:
- : loadings, lower-triangular in its leading block (for a unique, “rotationally identified” solution), diagonal entries family-1 log-parameterized (must be positive by convention), off-diagonal loadings unconstrained working parameters.
- : specific variances, family-1 parameterized as log-ratios relative to (the reference level, per Chapter 2.6).
A
rank-correlation-type structure (loadings) plus a genuinely
variance-type component (specific variances) — a
compact alternative to usm() when
is large and a low-rank + diagonal approximation is statistically
reasonable (the standard “FA” model for many traits or many
environments). rrcm() is the same loading parameterization
with
fixed (a pure reduced-rank approximation, no free specific variances) —
purely correlation/shape-type.
3.9 antem(x, order, beta, innovations, fixed) —
antedependence
is unit lower-triangular with regression coefficients
only in the requested order subdiagonals (working
parameters =
directly, unconstrained — a banded relative of the family-3
factorization idea).
’s
remaining diagonal entries are
family-1 log-innovation-ratios (variance-type). A mixed structure like
usm() but banded/order-limited rather than fully dense,
useful for longitudinal/repeated-measures data where dependence should
decay with temporal order but need not follow a strict AR form.
3.10 maternm(x, range, nu, fixed, distance) — Matérn
spatial correlation
Family-1 (log) transform on both parameters: (both must be positive: range and smoothness). Distance comes from supplied coordinates or a user-supplied distance matrix. Two correlation-type (in the “shape” sense — they reshape the whole matrix, not just rescale one entry) parameters governing decay rate and smoothness of spatial dependence.
3.11 sar(x, W, rho, fixed) — simultaneous
autoregressive spatial covariance
Family-2 (bounded logit) transform: bounded by the inverse spectral radius of (guarantees nonsingular). One correlation-type (shape) parameter that reshapes the entire spatial covariance through matrix inversion.
3.12 car(x, W, rho, fixed) — proper conditional
autoregressive covariance
Family-2 (bounded logit) transform:
bounded by the reciprocal extreme eigenvalues of the normalized
adjacency
(the exact condition for
to stay valid). Same flavor as sar(): one
correlation/shape-type parameter, whole-matrix reshaping via
inversion.
3.13 ownm(x, K, fun, par, fixed, dfun) — user-defined
shape
Either a fixed known valid matrix K (zero free
parameters, sommer only normalizes it by its
entry), or a user function fun(par) returning a valid
matrix, normalized the same way. Here the user is responsible for
choosing their own transform family from Chapter 2 (or inventing a new
one); sommer only imposes the final
normalization. If dfun(par,k) (analytic
)
is not supplied, ai_mme_sp2() falls back to a numerical
derivative. This is the escape hatch for any structure not already
covered — it plugs into the exact same CovarianceFactor
interface as
maternm()/toeplitzm()/sar()/car().
3.14 covm(ran1, ran2, thetaC, theta, ...) — legacy
two-random-effect helper
Predates the general vsm() Kronecker interface; builds a
CovarianceFactor directly from two random-effect terms and
an explicit correlation-structure matrix
thetaC/theta. Internally normalized and
compiled through the same descriptor contract as every structure above,
so it participates in REML identically once compiled — retained mainly
for backward compatibility with older model specifications.
3.15 Summary table
| Constructor | Free working parameters | Transform family (Ch. 2) | Type |
|---|---|---|---|
ism |
0 | — | — |
dsm/atm
|
1 (log-ratio) | variance | |
csm (homogeneous) |
1 (rho) |
2 (bounded logit) | correlation |
csm (heterogeneous) |
2 + 1 | mixed | |
ar1m |
1 (rho) |
2 (tanh) | correlation |
ar2m/ar3m
|
2 / 3 (PACF), + if heterogeneous | 2 (+1) | correlation / mixed |
toeplitzm |
(PACF) | 2 (tanh) | correlation |
mam/ma1m/ma2m
|
order (1 or 2) | none (identity) | correlation |
usm |
3 (Cholesky) + 1 (diag) | mixed (dense) | |
corgm |
3 (unit-diag factor) | correlation (dense) | |
fam |
loadings (-rank) + specific | 3 (loadings) + 1 | mixed |
rrcm |
loadings (-rank) | 3 (loadings) | correlation |
antem |
banded regression coeffs + innovations | 3 (banded) + 1 | mixed |
maternm |
2 (range, nu) | 1 (log) x2 | correlation (shape) |
sar/car
|
1 (rho) |
2 (bounded logit) | correlation (shape) |
ownm |
user-defined | user-defined | user-defined |
Chapter 4: REML, AI-REML, and ai_mme_sp2()
4.1 The REML log-likelihood sommer maximizes
For the Henderson system of Chapter 1, the (restricted)
log-likelihood ai_mme_sp2() evaluates every iteration
is
mapped directly onto the code:
-
logDetC— , from the sparse Cholesky/LDLT factorization of Henderson’s matrix (or CHOLMOD/PCG-approximated for large sparse ). -
logDetR— , computed per residual-structure branch (diagonal fast path, Kronecker-residual branch, or dense fallback). -
logDetA(i)— per random effect (relationship/precision matrices), via sparse LDLT. -
yPy— the quadratic form from absorbing into the MME solve.
REML maximizes over the working parameters from Chapter 2 (not the natural parameters ), using a Newton-type Average-Information (AI) REML algorithm.
4.2 The AI-REML update
- : the score vector, .
-
InfMat: a convex blend of the Average Information matrix (avInf) and the Expected Information matrix (emInf):
with per-iteration weights
(emweight/weightEmInf, user/schedule
controlled) trading off AI-REML’s fast quadratic convergence against
classical EM-REML’s guaranteed monotone ascent and better global
behavior when the AI matrix is momentarily ill-conditioned. This
blending is exactly the mechanism that absorbs the numerical differences
between variance-type and correlation-type parameters described below —
when the AI block for a dense correlation structure is poorly
conditioned, increasing the EM weight locally stabilizes the step
without touching the well-behaved variance blocks.
4.3 The core object: precision and its derivative
For a covariance shape
,
sommer works with its inverse (precision)
(lambdaDense in ai_mme_sp2()). All REML
derivatives route through the standard matrix-inverse identity:
implemented essentially verbatim:
arma::mat dLambda = -lambdaDense * Bk * lambdaDense; // Bk = dK/d(eta_k)
dLambda = 0.5 * (dLambda + dLambda.t()); // symmetrize (roundoff)Bk (called
cachedCovarianceD1()/covarianceD1() in the
code) is where every structure-specific formula from
Chapter 3 actually enters the optimizer — for analytic structures (diag,
AR, CSM, US, …) it’s a closed-form matrix; for generic-interface
structures (maternm, toeplitzm,
sar, car, ownm without
dfun) it’s a numerical derivative of the R-level
evaluator function. Either way, from this point on
ai_mme_sp2() treats Bk identically regardless
of structure — the only thing that changes the downstream
numerics is what Bk looks like, which is precisely
the variance-vs-correlation distinction below.
4.4 Variance-type parameters: sparse/diagonal
For a pure variance-ratio working parameter
(e.g. dsm()’s
,
or vsm()’s own outer sigma2):
is rank-one and diagonal — a single nonzero entry. Consequences:
- collapses to a rank-one update restricted to row/column : cheap to form, cheap to multiply against other quantities.
- The trace terms needed for the score and for
avInf/emInf(generically and ) reduce to a small number of scalar row/column contractions instead of full dense matrix products — this is exactly the “diagonal residual fast path” specialization used for pure-variance residual structures, which only exists because the derivative itself is diagonal, not because the covariance is diagonal per se. - For the single overall
sigma2invsm(), exactly (the whole shape, undifferentiated) — the classical textbook variance-component REML derivative. This is the parameter for which Average Information and Expected Information coincide most closely in well-behaved models, which is part of why classical variance-components REML (pre-AI, EM-only) worked well for decades on models built purely fromism()/dsm()-type structures.
4.5 Correlation-type parameters: dense
For a correlation/shape working parameter (e.g. csm()’s
,
ar1m()’s
,
usm()/corgm()’s Cholesky-factor entries):
Both factors are dense in general: changing a single
correlation parameter perturbs every off-diagonal entry of
simultaneously (e.g. for ar1m(),
so
is nonzero for
every
).
Consequences:
- is a full matrix with no exploitable sparsity in general (compound symmetry and AR have some exploitable structure, but not the sparsity a diagonal derivative gives).
- is a genuinely dense matrix product, per parameter per iteration — no shortcut analogous to the diagonal case.
- The chain-rule factor (derivative of the logit-inverse or from Chapter 2.4) is itself not constant: for the bounded-logit map, where , which vanishes as (i.e. as approaches its boundary). This is the same “flattening near the walls” property described in Chapter 2.4 — it naturally damps REML steps that would otherwise push against its feasible limit — but it also means the information matrix entries for correlation parameters shrink near the boundary, unlike variance parameters, whose exponential-family Jacobian never vanishes (only grows as grows).
- Because dense
products couple every pair
of structure parameters through
,
the resulting
avInfblock for correlation parameters is fully dense and more prone to near-singularity (e.g. when a correlation parameter is weakly identified, or two correlation parameters trade off against each other, as inusm()with many levels and modest sample size) — this is precisely the situation the EM/AI blending in Section 4.2 exists to stabilize:emInf(expected information) is guaranteed valid and typically better conditioned thanavInfin these dense/boundary-adjacent regimes, so increasing its weight recovers a well-defined, descent-guaranteeing step even whenavInfalone would not.
4.6 trust_cap: a second REML-stability mechanism tied
to parameter type
Independent of AI/EM blending, ai_mme_sp2() also
enforces a per-parameter trust-region cap
(trust_cap in each CovarianceFactor) that
bounds how far a single working parameter may move in one iteration:
- Variance-type parameters (unbounded exponential map) are typically
given a larger cap —
sigma2-like parameters can safely take large multiplicative steps early in REML with little risk of overshoot causing invalidity — only the likelihood itself, not validity, is at stake. - Correlation-type / bounded-map parameters
(e.g.
maternm()’s range/nu usec(1.0, 0.75),sar()/car()use1.0) are given tighter caps, because a large step on the working scale, pushed through a saturating transform (logit/tanh), can still correspond to a huge change in the reconstructed matrix’s conditioning even though the value itself stays valid — the cap prevents a technically-valid but wildly-overshooting proposal from destabilizing the next likelihood evaluation.
This is a purely numerical safeguard layered on top of the always-valid-by-construction guarantee from Chapter 2 — validity is never at risk, but good conditioning and monotone likelihood ascent are, and they are protected differently for the two parameter families.
4.7 Summary: the full chain per parameter type
flowchart TD
A["Working parameter eta (unconstrained, R)"] -->|transform g| B["Natural parameter theta (variance / correlation)"]
B -->|reconstruction formula| C["Covariance shape K(eta)"]
C -->|invert| D["Precision Lambda = K^-1"]
D -->|analytic identity dLambda = -Lambda Bk Lambda| E["dLambda/d(eta_k)"]
E --> F["Score s(eta), avInf, emInf"]
F -->|blend + trust_cap| G["AI-REML Newton step"]
G --> A
| Stage | Variance-type parameter | Correlation-type parameter |
|---|---|---|
| Transform (Ch. 2) | family 1: exponential (unbounded above) | family 2/3: logit/tanh/factorization (saturating, bounded) |
| sparse/diagonal, rank-1 | dense, full matrix | |
| Cost of | cheap (structured update) | dense product |
| avInf conditioning | usually well-behaved | can be near-singular, especially near boundary or weak identifiability |
| EM/AI blend role | rarely needed | often needed for stability |
trust_cap |
looser | tighter |
This is the concrete, code-level answer to “how does the REML process differ between a variance parameter and a correlation parameter”: both are optimized by the same AI-REML machinery over unconstrained working parameters (Chapter 2), but the structure of their derivative (, hence , hence the AI/EM information blocks) is fundamentally sparser and better-conditioned for variance parameters than for correlation parameters, which is why sommer layers EM/AI blending and per-parameter trust caps on top of a uniform derivative framework rather than hard-coding structure-specific optimizers.
Chapter 5: Worked examples, one per structure
Every example below reuses the exact notation from Chapter 2 (, , , , , , ) so you can trace each structure’s entry in Chapter 3 all the way to a concrete number.
5.1 ism()
levels, no working parameters at all:
,
.
There is no
to iterate on for this factor — it contributes only through the
Kronecker product with the other factors in the same vsm()
term.
5.2 dsm()
levels, natural variances (already showing , the reference from Chapter 2.6). Family-1 transform:
Structural derivative for : — a single nonzero entry, the sparse/diagonal pattern of Chapter 4.4.
5.3 csm(), homogeneous
, . Suppose . Family-2 transform:
is dense (every off-diagonal entry moves together) — matching Chapter 4.5’s correlation-type pattern.
5.4 csm(), heterogeneous
Same (), plus variances giving , (family-1, exactly as in 5.2). Full working vector: — 1 correlation-type entry followed by 2 variance-type entries, the “mixed” row of the Chapter 3.15 table.
5.5 ar1m()
, . Family-2 (tanh) transform: .
; the single working parameter reshapes every off-diagonal band simultaneously (dense , Chapter 4.5).
5.6 ar2m() / ar3m() /
toeplitzm()
,
order-2 PACF
.
Family-2 transform:
.
The Durbin–Levinson recursion (Chapter 3.4) turns
into full lag correlations
,
which then fill
exactly like ar1m() above but allowing a richer decay
pattern. toeplitzm() with
would use 3 PACF values (one per lag up to
)
instead of being capped at a fixed AR order.
5.7 mam() / ma1m() /
ma2m()
, order 1, (the raw MA coefficient — recall from Chapter 3.5 there is no transform, so directly). The resulting is built from , giving a banded correlation matrix with only lag-1 correlation nonzero. Because is the identity map here, directly — no chain rule factor to track, unlike every bounded/positive structure above.
5.8 usm()
(the case from the original single-structure example, reproduced here in the shared notation). Working parameters , i.e. (family-3, off-diagonal, no transform) and (family-3 diagonal, family-1 log transform):
Structural derivatives (, , chain rule since ):
(off-diagonal, correlation-type) is dense; (log-diagonal, variance-type in flavor) is sparse/rank-one — Chapter 4.4/4.5’s pattern, both appearing inside the same structure.
5.9 corgm()
, unit-diagonal lower factor entries , , (family-3, no per-entry transform — any real numbers here give a valid unit-diagonal ):
(rows are renormalized to unit length internally so
exactly); working parameters are simply
,
i.e. par equals the lower-triangular entries directly, with
no chain-rule factor to apply when differentiating
with respect to
.
5.10 fam() / rrcm()
, rank . Loadings (with the leading entry log-parameterized: ; the remaining loadings unconstrained: , ), specific variances (family-1 log-ratio on levels 2-3: , ):
rrcm() would drop the
working parameters entirely (fixing
)
and keep only the loading parameters
.
5.11 antem()
,
order 1. Regression coefficients on the first subdiagonal only,
,
(unconstrained,
directly — same “no per-entry transform” logic as corgm()’s
off-diagonal factor entries), innovations
(family-1 log-ratio:
,
):
5.12 maternm()
spatial points, distances . Suppose , (Matérn with reduces to the exponential correlation ). Family-1 transform on both: .
Both working parameters are correlation/shape-type: changing either or reshapes every pairwise entry of at once (dense , as in Chapter 4.5).
5.13 sar()
areal units, adjacency with spectral radius (largest eigenvalue magnitude) , so the valid range is . Suppose . Family-2 (symmetric bounded logit) transform:
5.14 car()
areal units, symmetric non-negative adjacency , row sums . Suppose the valid range works out to and . Family-2 transform:
5.15 ownm()
A user supplies
fun <- function(par) matrix(c(1, par[1], par[1], 1), 2, 2)
with par=c(0.25) — here the user has chosen to
reuse the family-2 (bounded) idea manually by ensuring
par[1] always stays in
some other way (sommer does not enforce this for ownm());
directly, sommer only performs the
normalization from Chapter 2.6 and, since no dfun was
supplied, computes
by a numerical (finite-difference) derivative of fun.
Chapter 6: End-to-end numerical trace, from to the REML objective
Chapters 2-5 showed how a working parameter
turns into a shape
and a precision
.
This chapter shows where in the computation those numbers
actually get used, by carrying one tiny, fully-numeric example all the
way from
to the REML log-likelihood
itself — reusing the exact usm() numbers from Section
5.8.
6.1 A 4-observation, 2-line x 2-trait toy data set
Two lines
(),
two traits
(),
one observation per line-trait combination, model
(a single fixed intercept
,
one random effect per line-trait cell, and residual noise). Take the
random-effect design as vsm(usm(Trait), ism(Line)), which
makes each line’s 2-vector of trait effects
independent across lines with common covariance
:
To isolate exactly what the shape working parameters do, fix
the scale at
and the residual variance at
(in a real mmes() fit these would be extra variance-type
working parameters of their own, following Section 4.4).
6.2 Step 1 — working parameters to the shape and its precision (Chapter 2-3)
Exactly the Section 5.8 usm() example:
, so
,
,
and
6.3 Step 2 — precision to Henderson’s matrix (Chapter 1)
Because lines are independent (ism(Line)), the
random-effect precision
is block-diagonal, one copy of
per line — this is literally the only place
enters the whole computation; every quantity from here on is arithmetic
built on top of these four numbers. Henderson’s
(Section 1.2), with
so
:
rows/columns ordered . The blocks sit exactly where would otherwise be left alone — ’s only job, computationally, is to determine these four numbers added into .
6.4 Step 3 — solving the MME (BLUEs/BLUPs depend on )
Solving gives
If had been different, would differ, the four numbers inserted in Section 6.3 would differ, and every one of these five solutions would come out different — this is the concrete meaning of “the BLUPs/BLUEs depend on the covariance parameters.”
6.5 Step 4 — from the MME solution to the REML ingredients (Chapter 4.1)
Using the identity :
and, from the same matrix of Section 6.3 (a block-determinant calculation, done in practice by sparse Cholesky, not shown here step by step),
With ism(Line) contributing
and
contributing
,
Chapter 4.1’s REML log-likelihood becomes a single concrete number:
This is the number AI-REML is trying to make as large as possible, and every term in it was produced starting from the two numbers in .
6.6 Step 5 — perturbing : where the score/AI-matrix machinery lives
Section 4.3 gives the analytic derivative . We can check this numerically instead of trusting the formula blindly, using the same finite- difference idea a high-school calculus class would use for any derivative: nudge from to (holding fixed), rebuild and exactly as in Section 6.2, and see how much moved.
Nudged value: , giving (note is unchanged, since only the off-diagonal moved) and
Finite-difference estimate of the derivative:
Compare this to the analytic formula from Section 4.3/5.8, , plugged into :
The two match (up to the expected finite-step-size rounding). This is
exactly the object ai_mme_sp2() forms internally as
dLambda (Section 4.3), and it is what turns into the score
and the avInf/emInf blocks of Section 4.2 that
decide the next value of
— closing the loop:
for the forward pass (Sections 6.2-6.5), and
for the update that
drives REML to convergence (Chapter 4.2).
Where to go from here
- To fit a model with any of these structures, see
?vsmand the constructor’s own help page (e.g.?csm,?ar1m,?usm). - For the descriptor-level API details (fields of a
CovarianceFactor,free,par_names,trust_cap), seeusing-covariance-structures.Rmd. - For a deeper look at the specific performance optimizations inside
ai_mme_sp2()referenced in Chapter 4 (sparse LDLT, CHOLMOD, PCG, selected-inverse traces), see the package’s C++ source comments insrc/MNR.cpp.