Ordination: seeing the fitted shared structure
Question. Once a two-level latent-variable model has been fitted, what can an ordination show without making the latent axes look more certain or more biological than they are?
An ordination is a view of the shared part of a fitted covariance model. A trait-loading ordination shows which measured traits align with the fitted shared axes. A score ordination can also show where individuals or occasions lie along those axes, but those score locations are model-based estimates, not new measurements. Neither view replaces the B and W covariance matrices, their correlations, or their uncertainty. Read those first; use an ordination to inspect the fitted low-rank structure.
Start with the fitted ordinations. In Arctic charr, follow distance travelled and exit time across two axes at each level. In dogs, follow dog-directed fear and touch sensitivity across three two-axis views. Each analysis rotates the between- and within-individual loadings separately. The worked calculation below uses simulated data so we can see how the axes relate to known loadings.
Start with the covariance model
For the Gaussian starting point used in these lessons,
\[ \mathbf y_{ij}=\boldsymbol\mu+\mathbf B\mathbf x_{ij}+\mathbf u_i+\mathbf e_{ij}, \qquad \mathbf u_i\sim N(\mathbf0,\boldsymbol\Sigma_B), \qquad \mathbf e_{ij}\sim N(\mathbf0,\boldsymbol\Sigma_W). \]
where \(\boldsymbol\mu\) is the vector of trait intercepts, \(\mathbf x_{ij}\) holds the covariates and \(\mathbf B\) their trait-specific coefficients.
At each level, a low-rank model writes the covariance as
\[ \boldsymbol\Sigma_B=\boldsymbol\Lambda_B\boldsymbol\Lambda_B^{\mathsf T}+\boldsymbol\Psi_B, \qquad \boldsymbol\Sigma_W=\boldsymbol\Lambda_W\boldsymbol\Lambda_W^{\mathsf T}+\boldsymbol\Psi_W. \]
The columns of \(\boldsymbol\Lambda_B\) and \(\boldsymbol\Lambda_W\) are the fitted shared axes. The diagonal matrices \(\boldsymbol\Psi_B\) and \(\boldsymbol\Psi_W\) retain trait-specific variation that those axes do not represent. An ordination shows the axes and associated scores. A covariance or correlation matrix shows the total fitted association, including the effect of the unique variances on its scale.
For the Gaussian models used here, a useful description is a mixed model with factor-analytic covariance. The mean model handles fixed effects and repeated measurements; the factor analysis represents each B or W covariance matrix with shared axes plus trait-specific variance. This is not PCA: PCA is a separate data-reduction method and does not fit this repeated-measures model. For the dog figures, a standard matrix calculation chooses convenient display axes from the fitted shared covariance. This changes how we draw the fitted pattern, not the model itself.
This page uses the same notation as the manuscript: \(\boldsymbol\Sigma_B\) and \(\boldsymbol\Sigma_W\) are B and W covariance matrices; \(\boldsymbol\Lambda_B\) and \(\boldsymbol\Lambda_W\) are loading matrices; and uppercase \(\boldsymbol\Psi_B\) and \(\boldsymbol\Psi_W\) are unique-variance matrices. Lowercase \(s\) denotes a random deviation, not a variance matrix.
A rank-one ordination has one axis
Here is a simple simulated example. A one-dimensional display has no meaningful vertical latent coordinate: any vertical spread is only visual jitter so that points do not cover each other.
In a fitted empirical model, B scores are model-based estimates of stable individual deviations after the specified covariates have been accounted for. W scores are model-based estimates of shared departures at an observation or occasion. They are shrunken estimates, not direct measurements of personality, state, or a biological mechanism. The B and W plots should be interpreted separately.
The code below shows the gllvmTMB plotting route for the rank-one displays. It applies to fits made with gllvmTMB; other engines use their own extraction and plotting functions. It is an optional illustration of the syntax. The figure above uses known simulation scores. For a runnable fit from bundled data, follow the rank-two simulation below or the main dog lesson.
#| eval: false
# Supply a checked rank-one gllvmTMB fit at both levels before running this example.
ordination_B <- gllvmTMB::extract_ordination(fit_gllvm, level = "unit")
ordination_W <- gllvmTMB::extract_ordination(fit_gllvm, level = "unit_obs")
# One dimension: the score panel is a horizontal strip and the other panel
# gives the trait loadings. `rotation = "none"` keeps the reported orientation.
plot(fit_gllvm, type = "ordination", level = "unit", rotation = "none")
plot(fit_gllvm, type = "ordination", level = "unit_obs", rotation = "none")
# The returned objects make the contents explicit.
head(ordination_B$scores) # one row per individual
ordination_B$loadings # one row per trait
head(ordination_W$scores) # one row per recorded occasion
ordination_W$loadingsThe plotted sign can reverse with no change to the fitted covariance. In rank two or higher, axes can rotate as well. These representations make the same \(\boldsymbol\Lambda\boldsymbol\Lambda^{\mathsf T}\), so compare reconstructed \(\boldsymbol\Sigma_B\), \(\boldsymbol\Sigma_W\), correlations, and uncertainty rather than interpreting an arrow direction in isolation. When \(\boldsymbol\Psi\) is nonzero, arrow angles do not equal total trait correlations.
Why two axes change the display
Charr and red knots use two axes at each level. Dogs use three, which the dog lesson shows in separate pairwise projections.
The arrows point toward increasing values of the displayed shared axes. Traits that have similar arrows load similarly on those axes. This is a compact description of the shared component; it does not establish that those traits have the same total correlation, causal relation, or biological function. The point cloud is also not a hypothesis test. For this reason, a manuscript should normally lead with covariance summaries and interval evidence, then use ordination as an explanatory or supplementary display.
Reproduce the teaching example
The symbolic alignment sheet records the exact relation between every symbol, simulation draw, model term, and plotted truth. The complete source below uses a fixed seed and writes both figures, the simulated long-format data, and its known loadings and unique variances.
Complete figure and data source
# Reproducible known-truth figures for the ordination lesson.
# Run from the repository root:
# Rscript tutorial/downloads/make-ordination-teaching.R
library(ggplot2)
library(patchwork)
set.seed(20260911)
out_fig <- file.path("tutorial", "figures")
out_data <- file.path("tutorial", "downloads")
dir.create(out_fig, recursive = TRUE, showWarnings = FALSE)
dir.create(out_data, recursive = TRUE, showWarnings = FALSE)
traits <- c("mass", "gizzard", "BMR", "activity", "feeding", "exploration")
simulate_two_level <- function(lambda_B, lambda_W, psi_B, psi_W,
n_individual = 80L, n_occasion = 6L) {
n_trait <- nrow(lambda_B)
d_B <- ncol(lambda_B)
d_W <- ncol(lambda_W)
z_B <- matrix(rnorm(n_individual * d_B), ncol = d_B)
z_W <- matrix(rnorm(n_individual * n_occasion * d_W), ncol = d_W)
s_B <- matrix(rnorm(n_individual * n_trait,
sd = rep(sqrt(diag(psi_B)), each = n_individual)),
ncol = n_trait)
s_W <- matrix(rnorm(n_individual * n_occasion * n_trait,
sd = rep(sqrt(diag(psi_W)),
each = n_individual * n_occasion)),
ncol = n_trait)
records <- expand.grid(
individual = seq_len(n_individual), occasion = seq_len(n_occasion),
KEEP.OUT.ATTRS = FALSE
)
records <- records[order(records$individual, records$occasion), ]
records$occasion_id <- seq_len(nrow(records))
y <- matrix(NA_real_, nrow(records), n_trait)
for (row in seq_len(nrow(records))) {
i <- records$individual[row]
j <- records$occasion_id[row]
y[row, ] <- lambda_B %*% z_B[i, ] + s_B[i, ] +
lambda_W %*% z_W[j, ] + s_W[j, ]
}
colnames(y) <- traits
list(
data = cbind(records, as.data.frame(y)),
z_B = z_B, z_W = z_W,
sigma_B = lambda_B %*% t(lambda_B) + psi_B,
sigma_W = lambda_W %*% t(lambda_W) + psi_W
)
}
make_score_strip <- function(scores, title, xlab) {
dat <- data.frame(score = scores[, 1L], y = 0)
ggplot(dat, aes(x = score, y = y)) +
geom_vline(xintercept = 0, linewidth = 0.35, linetype = "dashed", colour = "grey45") +
geom_jitter(width = 0, height = 0.11, alpha = 0.35, size = 1.15,
colour = "#173f5f") +
scale_y_continuous(NULL, breaks = NULL) +
labs(title = title, x = xlab) +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold"), panel.grid.minor = element_blank())
}
make_lollipop <- function(loadings, title) {
dat <- data.frame(trait = factor(traits, levels = rev(traits)),
loading = as.numeric(loadings[, 1L]))
ggplot(dat, aes(x = loading, y = trait)) +
geom_vline(xintercept = 0, linewidth = 0.35, linetype = "dashed", colour = "grey45") +
geom_segment(aes(x = 0, xend = loading, yend = trait), linewidth = 0.7,
colour = "#e48624") +
geom_point(size = 2.2, colour = "#e48624") +
labs(title = title, x = "Known loading", y = NULL) +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold"), panel.grid.minor = element_blank())
}
make_biplot <- function(scores, loadings, title, point_label) {
score <- data.frame(axis_1 = scores[, 1L], axis_2 = scores[, 2L])
scale_arrow <- 0.72 * min(
diff(range(score$axis_1)) / diff(range(loadings[, 1L])),
diff(range(score$axis_2)) / diff(range(loadings[, 2L]))
)
arrow <- data.frame(
trait = traits,
axis_1 = loadings[, 1L] * scale_arrow,
axis_2 = loadings[, 2L] * scale_arrow
)
ggplot(score, aes(x = axis_1, y = axis_2)) +
geom_hline(yintercept = 0, linewidth = 0.3, colour = "grey65") +
geom_vline(xintercept = 0, linewidth = 0.3, colour = "grey65") +
geom_point(alpha = 0.32, size = 1.15, colour = "#173f5f") +
geom_segment(data = arrow, inherit.aes = FALSE,
aes(x = 0, y = 0, xend = axis_1, yend = axis_2),
arrow = grid::arrow(length = grid::unit(2.4, "mm")),
linewidth = 0.7, colour = "#e48624") +
geom_text(data = arrow, inherit.aes = FALSE,
aes(x = axis_1, y = axis_2, label = trait),
hjust = 0.5, vjust = -0.55, size = 2.8, colour = "#7a3e00") +
labs(title = title, x = "Latent axis 1", y = "Latent axis 2") +
coord_equal() +
theme_minimal(base_size = 10) +
theme(plot.title = element_text(face = "bold"),
panel.grid.minor = element_blank())
}
# Rank-one: suitable for the empirical examples. A plotted vertical position is
# intentionally only jitter; there is no second latent coordinate.
lambda_B1 <- matrix(c(0.85, 0.65, 0.45, 0.10, -0.35, -0.65), ncol = 1)
lambda_W1 <- matrix(c(0.30, 0.10, -0.25, 0.75, 0.55, -0.45), ncol = 1)
psi_B1 <- diag(c(0.28, 0.30, 0.32, 0.25, 0.35, 0.30))
psi_W1 <- diag(c(0.55, 0.50, 0.55, 0.48, 0.52, 0.58))
rank_one <- simulate_two_level(lambda_B1, lambda_W1, psi_B1, psi_W1)
rank_one_plot <-
(make_score_strip(rank_one$z_B, "A. Between-individual axis",
"Known individual score on the one shared B axis") +
make_lollipop(lambda_B1, "B. Between-individual loadings")) /
(make_score_strip(rank_one$z_W, "C. Within-individual axis",
"Known occasion score on the one shared W axis") +
make_lollipop(lambda_W1, "D. Within-individual loadings")) +
plot_annotation(
title = "One-dimensional ordination at two levels",
subtitle = "Known values from a simulation. Vertical spread in score panels is visual jitter, not a second axis."
)
ggsave(file.path(out_fig, "ordination-rank-one.png"), rank_one_plot,
width = 10.5, height = 7, dpi = 300)
ggsave(file.path(out_fig, "ordination-rank-one.pdf"), rank_one_plot,
width = 10.5, height = 7)
# Rank-two: a separate, six-trait simulation. The current four-trait empirical
# rank-one examples cannot provide an identifiable free-uniqueness rank-two fit.
lambda_B2 <- rbind(
c(0.80, 0.05), c(0.70, 0.20), c(0.45, 0.65),
c(0.10, 0.80), c(-0.35, 0.70), c(-0.65, -0.20)
)
lambda_W2 <- rbind(
c(0.35, 0.70), c(0.20, 0.65), c(-0.25, 0.70),
c(0.75, 0.20), c(0.65, -0.25), c(-0.55, 0.30)
)
psi_B2 <- diag(c(0.28, 0.30, 0.32, 0.25, 0.35, 0.30))
psi_W2 <- diag(c(0.55, 0.50, 0.55, 0.48, 0.52, 0.58))
rank_two <- simulate_two_level(lambda_B2, lambda_W2, psi_B2, psi_W2)
rank_two_plot <-
make_biplot(rank_two$z_B, lambda_B2, "A. Between-individual two-axis space", "individual") +
make_biplot(rank_two$z_W, lambda_W2, "B. Within-individual two-axis space", "occasion") +
plot_layout(guides = "collect") +
plot_annotation(
title = "Two-dimensional ordination needs enough traits",
subtitle = "Known values from a six-trait simulation; B and W shown separately."
)
ggsave(file.path(out_fig, "ordination-rank-two.png"), rank_two_plot,
width = 9.6, height = 5.2, dpi = 300)
ggsave(file.path(out_fig, "ordination-rank-two.pdf"), rank_two_plot,
width = 9.6, height = 5.2)
# Public data for the optional fitting exercise. Truth records make the plotted
# teaching quantities auditable without claiming fitted recovery.
write.csv(rank_two$data, file.path(out_data, "ordination-teaching-data.csv"), row.names = FALSE)
truth <- rbind(
data.frame(level = "B", trait = traits, axis_1 = lambda_B2[, 1], axis_2 = lambda_B2[, 2],
unique_variance = diag(psi_B2)),
data.frame(level = "W", trait = traits, axis_1 = lambda_W2[, 1], axis_2 = lambda_W2[, 2],
unique_variance = diag(psi_W2))
)
write.csv(truth, file.path(out_data, "ordination-teaching-truth.csv"), row.names = FALSE)Download the simulated wide-format data, known loading and uniqueness values, and source script. These are simulated teaching data, so they may be freely inspected and modified.
To fit the rank-two simulation, first reshape the six trait columns to the long format used in the other lessons. The following complete example does that and then fits the matching gllvmTMB covariance specification. It is an optional exercise, not a recovery claim: the displayed figures above show known simulation values, not fitted output.
#| eval: false
teaching_path <- if (file.exists(file.path("tutorial", "downloads", "ordination-teaching-data.csv"))) {
file.path("tutorial", "downloads", "ordination-teaching-data.csv")
} else {
file.path("downloads", "ordination-teaching-data.csv")
}
teaching_wide <- read.csv(teaching_path)
trait_names <- c("mass", "gizzard", "BMR", "activity", "feeding", "exploration")
teaching_long <- data.frame(
individual = rep(teaching_wide$individual, each = length(trait_names)),
occasion_id = rep(teaching_wide$occasion_id, each = length(trait_names)),
trait = rep(trait_names, times = nrow(teaching_wide)),
value = as.vector(t(as.matrix(teaching_wide[, trait_names])))
)
teaching_long$trait <- factor(teaching_long$trait, levels = trait_names)
fit_two_axis <- gllvmTMB::gllvmTMB(
value ~ 0 + trait +
latent(0 + trait | individual, d = 2, unique = TRUE) +
latent(0 + trait | occasion_id, d = 2, unique = TRUE),
data = teaching_long,
trait = "trait", unit = "individual", unit_obs = "occasion_id",
family = stats::gaussian(), REML = FALSE
)
health <- fit_two_axis$fit_health
stopifnot(isTRUE(health$convergence == 0L), isTRUE(health$pd_hessian),
isTRUE(is.finite(health$max_gradient) && health$max_gradient <= 0.01))
# A two-dimensional view. Varimax changes the displayed orientation, not the
# reconstructed covariance matrix; sign anchoring makes repeated figures easier
# to compare but does not make a sign biologically identified.
plot(fit_two_axis, type = "ordination", level = "unit", axes = c(1, 2),
rotation = "varimax", sign_anchor = "auto")
plot(fit_two_axis, type = "ordination", level = "unit_obs", axes = c(1, 2),
rotation = "varimax", sign_anchor = "auto")Put uncertainty on the quantities people will interpret
Bootstrap uncertainty is most useful for reconstructed correlations, covariance contrasts, repeatabilities, and communalities. Those quantities have an unambiguous scientific scale. Bootstrapping point locations or loading arrows also requires each replicate to be aligned for sign and, with two or more axes, rotation; otherwise an interval can reflect equivalent reorientations rather than uncertainty about the covariance.
For the empirical examples, start with the retained model-conditional intervals in the Uncertainty lesson, then use the ordination as a secondary guide. If individual score uncertainty is central to a new biological claim, say how scores and axes were aligned across the bootstrap replicates and show that alignment method.
“Boldness”, “pace of life”, “integration”, or “plasticity” are biological interpretations. A fitted loading pattern alone is insufficient evidence for any of them. State the trait pattern first, then connect it to external design or theory if that connection is justified.

