Skip to contents

Adds slope-only predictor deviations across response columns, with an additive-genetic relationship matrix \(A\) relating those columns. If B is the response-column by predictor coefficient matrix, the model is $$\mathrm{Cov}(\mathrm{vec}(B^\mathsf{T})) = A \otimes \Sigma_\mathrm{predictor}.$$ The RHS must be the response-column factor resolved from trait =, and the pedigree or matrix labels must match its levels. A single | estimates a full predictor covariance; || gives separate predictor variances with zero covariance. The term never adds a random intercept.

Usage

animal_slope(formula, pedigree = NULL, A = NULL, Ainv = NULL)

Arguments

formula

An lme4-bar formula. With one or more bare predictors and the resolved response-column factor on the RHS, x1 + x2 | trait is the full column-slope covariance alias and x1 + x2 || trait is its diagonal alias. For one predictor the two bars fit the same 1 x 1 covariance.

pedigree, A, Ainv

One relatedness input for the column-slope aliases: a pedigree, additive-genetic covariance matrix, or its precision.

Value

A formula marker; never evaluated.

Details

This route is covered for Gaussian long-format data with bare finite numeric predictors. Wide-format column slopes, non-Gaussian responses, transformed or factor bases, latent predictor covariance, and intervals are not supported in this release. Use extract_Sigma(fit, level = "column_slope") for \(\Sigma_\mathrm{predictor}\).

Historical non-trait RHS forms remain accepted to preserve existing fits. They are compatibility behaviour, not the teaching API; new code uses the resolved response-column factor on the RHS.

Examples

set.seed(1)
## Six response columns (e.g. six related lines) whose relatedness is a
## pedigree-derived additive-genetic matrix A; labels match the trait levels.
ped <- data.frame(
  id   = paste0("line", 1:6),
  sire = c(NA, NA, "line1", "line1", "line3", "line3"),
  dam  = c(NA, NA, "line2", "line2", "line4", "line4")
)
A <- pedigree_to_A(ped)
## Column-specific slopes on two predictors: Cov(vec(t(B))) = A %x% Sigma.
Sigma <- matrix(c(0.5, 0.2, 0.2, 0.3), 2, 2)
B <- t(chol(A)) %*% matrix(rnorm(6 * 2), 6, 2) %*% chol(Sigma)
dat <- expand.grid(unit = factor(1:40), trait = factor(ped$id, levels = ped$id))
dat$elevation <- rnorm(nrow(dat))
dat$forest_cover <- rnorm(nrow(dat))
col <- as.integer(dat$trait)
dat$value <- B[col, 1] * dat$elevation + B[col, 2] * dat$forest_cover +
  rnorm(nrow(dat), sd = 0.5)
fit <- gllvmTMB(
  value ~ 0 + trait + animal_slope(elevation + forest_cover | trait, A = A),
  data = dat, trait = "trait", unit = "unit"
)
extract_Sigma(fit, level = "column_slope")$Sigma
#>               elevation forest_cover
#> elevation    0.35848241   0.01296847
#> forest_cover 0.01296847   0.25671012