Choosing latent rank
Question. How many shared covariance axes should we retain when the data can support several increasingly flexible models?
Each added rank expands the set of covariance patterns that a model can express. That flexibility can reduce an information criterion and still leave a fragile interpretation. The aim is a defensible representation of the biological question, not the largest model an optimizer accepts.
Build a rank grid
For each candidate, record the between-individual rank, within-individual rank, likelihood criterion, rows retained, convergence, Hessian status, and information criterion. Candidates with a failed fit are evidence about the boundary of the analysis; they are not missing rows to erase from the comparison table.
For \(T\) traits and rank \(d\), the usual low-rank-plus-diagonal representation has \(T(d+1)-d(d-1)/2\) covariance parameters. It cannot exceed the \(T(T+1)/2\) parameters in an unstructured covariance; this is a necessary counting check, not evidence that a dataset identifies the parameters well. With three traits, rank one plus free uniqueness has six parameters, the same count as an unrestricted covariance; that equality does not prove the two representations are equivalent. Rank two plus free uniqueness has eight parameters for only six distinct covariance elements and is not identifiable without further restrictions. More repeated information, balanced trait observation, and healthy diagnostics are still needed.
| Candidate | Between rank | Within rank | What changes? |
|---|---|---|---|
| Baseline | 0 | 0 | No shared axes; retain trait-specific variation. |
| B-only | 1+ | 0 | Stable individual covariance only. |
| W-only | 0 | 1+ | Occasion-level covariance only. |
| Two-level | 1+ | 1+ | Both sources of shared covariance. |
Run a bounded comparison and retain every outcome
Keep the response, retained rows, fixed-effect design, likelihood, optimiser controls and trait order fixed across candidates. The following guidance-only grid compares no shared axis with one shared axis at each level. It does not claim a result for your data until you run it, inspect the diagnostics, and retain every fit or failure.
#| eval: false
library(glmmTMB)
level_term <- function(group, rank) {
diagonal <- sprintf("diag(0 + trait | %s)", group)
if (rank == 0) diagonal else paste0(
sprintf("rr(0 + trait | %s, d = %d)", group, rank), " + ", diagonal
)
}
fit_rank_candidate <- function(d_B, d_W, data = my_long) {
rhs <- paste(
"0 + trait + trait:temperature_between + trait:temperature_within +",
level_term("individual", d_B), "+", level_term("occasion", d_W)
)
tryCatch(
glmmTMB(
as.formula(paste("value ~", rhs)), data = data, family = gaussian(),
dispformula = ~ 0,
control = glmmTMBControl(optCtrl = list(iter.max = 1500, eval.max = 2000))
),
error = function(e) e
)
}
rank_grid <- expand.grid(d_B = 0:1, d_W = 0:1)
rank_grid$fit <- Map(fit_rank_candidate, rank_grid$d_B, rank_grid$d_W)
rank_grid$status <- vapply(rank_grid$fit, function(x) {
if (inherits(x, "error")) conditionMessage(x) else "fitted"
}, character(1))
rank_grid$AIC <- vapply(rank_grid$fit, function(x) {
if (inherits(x, "glmmTMB")) AIC(x) else NA_real_
}, numeric(1))
rank_grid$pdHess <- vapply(rank_grid$fit, function(x) {
inherits(x, "glmmTMB") && isTRUE(x$sdr$pdHess)
}, logical(1))
rank_grid[c("d_B", "d_W", "AIC", "pdHess", "status")]If you use one combined predictor rather than separate within- and between-individual effects, replace those two fixed-effect terms consistently in every candidate. A rank grid is a comparison of covariance structures, not an opportunity to change several modelling decisions at once. After choosing a healthy candidate, refit the matching gllvmTMB specification with unique = TRUE only as an implementation check; compare reconstructed covariance summaries, rather than signs of latent loadings.
A practical selection rule
First exclude candidates that do not meet the pre-specified health checks. Among healthy candidates, inspect the score difference, favouring a lower rank when scores are practically indistinguishable and the smaller representation answers the question. Then inspect whether the selected covariance is stable enough to interpret, rather than stopping at one scalar score.
Use maximum likelihood (ML) for the rank comparison in these matched grids. For Gaussian data, restricted maximum likelihood (REML) may be appropriate for a final model with a fixed mean design, but changing fixed effects under REML invalidates direct likelihood comparisons. State the criterion rather than relying on a default.
What rank does not tell you
A rank-one structure does not prove a single biological mechanism. A high rank does not prove complexity in nature. Both reflect a model representation conditional on traits, scaling, rows, residual convention, and the candidate grid.
The ten-score dog rank comparison shows how to compare 3/3 and 4/3 fits using the same records and scores.