Skip to contents

[Deprecated]

Usage

animal_unique(id, pedigree = NULL, A = NULL, Ainv = NULL)

Arguments

id

Bare column name of the individual factor.

pedigree

A 3-column data frame identifying individuals and parents. Columns are resolved by name using the synonyms id/animal, sire/father, and dam/mother; if none match, column 1 is id, column 2 is sire, and column 3 is dam. Unknown parents may be NA, "", or "0". Converted internally to a sparse inverse relationship matrix \(\mathbf A^{-1}\) by pedigree_to_Ainv_sparse() (Henderson/Quaas), not to a dense \(\mathbf A\). Must be passed by name (pedigree = ped). If several of pedigree, A, and Ainv are given, pedigree wins, then A, then Ainv.

A

Dense relatedness matrix (\(n \times n\)); rownames / colnames must match levels of id.

Ainv

Precision matrix (inverse of A). Sparse matrix inputs are preserved for the sparse engine route.

Value

See animal_scalar().

Details

animal_unique() is soft-deprecated as compatibility syntax in gllvmTMB 0.2.0. Use animal_indep() for standalone marginal diagonal animal-model terms. Paired explicit-Psi use remains accepted; use animal_latent(..., unique = TRUE) when the folded latent term itself should carry this diagonal companion.

Canonical name for the D independent animal-model random intercept on a shared relatedness matrix \(\mathbf A\). Each trait gets its own variance \(\sigma^{2}_{\text{a},t}\); traits share the same per-individual draws (rows of A act on each trait independently). Mathematical parallel to phylo_unique().

Correlated intercept + slope reaction norm

Used with an intercept+slope bar, animal_unique(1 + x | id, pedigree = ped) fits a correlated additive-genetic random-regression (reaction norm) \(\mathrm{vec}(\mathbf B) \sim N(0, \Sigma_b \otimes \mathbf A)\), where \(\Sigma_b\) is a \(2 \times 2\) (intercept, slope) covariance with a free intercept-slope correlation. This routes through the same augmented engine as phylo_unique() with a 1 + x | sp bar; no separate likelihood. For the diagonal (\(\rho = 0\)) special case use animal_indep() with the same 1 + x | id bar. Recover \(\Sigma_b\) with extract_Sigma(fit, level = "phy").

Examples

set.seed(1)
## Pedigree: ten founders (five sires, five dams) and 90 offspring.
ped <- data.frame(
  id   = paste0("i", 1:100),
  sire = c(rep(NA, 10), sample(paste0("i", 1:5), 90, replace = TRUE)),
  dam  = c(rep(NA, 10), sample(paste0("i", 6:10), 90, replace = TRUE))
)
A <- pedigree_to_A(ped)
## Two traits with their own additive-genetic variances and no genetic
## covariance: vec(bv) ~ N(0, G %x% A) with G = diag(0.6, 0.4). Residual
## noise is added; one row per (individual, trait).
G <- diag(c(0.6, 0.4))
bv <- t(chol(A)) %*% matrix(rnorm(100 * 2), 100, 2) %*% chol(G)
df <- data.frame(
  individual = factor(rep(ped$id, each = 2), levels = ped$id),
  trait      = factor(rep(c("t1", "t2"), times = 100)),
  value      = as.vector(t(bv)) + rnorm(100 * 2, sd = 0.6)
)
fit <- gllvmTMB(
  value ~ 0 + trait + animal_unique(individual, pedigree = ped),
  data = df, trait = "trait", unit = "individual",
  cluster = "individual"
)
#> Warning: ! Formula keyword `animal_unique()` is soft-deprecated as of gllvmTMB 0.2.0
#>   (compatibility syntax).
#> ℹ `unique()` / `*_unique()` are compatibility syntax while Psi moves into the
#>   latent-family grammar.
#> → For standalone diagonal tiers use `indep()` / `*_indep()`; ordinary
#>   `latent()` now carries Psi by default.
extract_Sigma(fit, level = "phy")$Sigma
#>           t1        t2
#> t1 0.7576262 0.0000000
#> t2 0.0000000 0.3325724
## The recommended spelling for a standalone diagonal term,
## animal_indep(), fits the same model:
fit2 <- gllvmTMB(
  value ~ 0 + trait + animal_indep(0 + trait | individual, pedigree = ped),
  data = df, trait = "trait", unit = "individual",
  cluster = "individual"
)
c(logLik(fit), logLik(fit2))
#> [1] -253.3543 -253.3543