Skip to contents

Builds the sparse precision matrix \(\mathbf A^{-1}\) for an animal- model pedigree using only Matrixno MCMCglmm dependency. The returned \(\mathbf A^{-1}\) is genuinely sparse (typical density \(O(1/n)\)), so the TMB fit is \(O(n)\) rather than \(O(n^3)\) – this is the canonical fast path for wild pedigrees with \(n_{\text{individuals}} > 500\). The construction is the standard Henderson (1976) / Quaas (1976) sparse inverse: inbreeding coefficients \(F\) are derived from the dense tabular relatedness matrix, then \(\mathbf A^{-1}\) is assembled directly from the per-individual Mendelian sampling variances. It reproduces MCMCglmm::inverseA(pedigree)$Ainv exactly. (The current inbreeding step forms the dense \(n \times n\) \(\mathbf A\), an \(O(n^2)\) one-time cost.)

Usage

pedigree_to_Ainv_sparse(pedigree)

Arguments

pedigree

A 3-column data frame: id (or animal), sire (or father), dam (or mother).

Value

A sparse dgCMatrix of dimension n_individuals x n_individuals with rownames and colnames equal to the individual IDs. Sparse storage; typical density is \(O(1/n)\).

Details

Usage:

Ainv <- pedigree_to_Ainv_sparse(ped)
fit  <- gllvmTMB(value ~ 0 + trait +
                   animal_scalar(id, Ainv = Ainv),
                 data = df, unit = "id", cluster = "id")

The pedigree follows the conventional (id, sire, dam) column order, OR named columns matching id/animal, sire/father, dam/mother for by-name lookup. Unknown parents are encoded as NA or 0. Founders (both parents unknown) are treated as unrelated.

References

Henderson, C. R. (1976). A simple method for computing the inverse of a numerator relationship matrix used in prediction of breeding values. Biometrics 32: 69-83.

Quaas, R. L. (1976). Computing the diagonal elements and inverse of a large numerator relationship matrix. Biometrics 32: 949-953.

Hadfield, J. D. (2010). MCMC methods for multi-response generalised linear mixed models: the MCMCglmm R package. Journal of Statistical Software 33: 1-22. (The MCMCglmm::inverseA() reference implementation this builder is validated against.)

See also

pedigree_to_A() for the dense companion; animal_scalar() and siblings for the keyword family.

Examples

if (FALSE) { # \dontrun{
ped <- data.frame(
  id   = paste0("i", 1:6),
  sire = c(NA, NA, "i1", "i1", "i3", "i3"),
  dam  = c(NA, NA, "i2", "i2", "i4", "i4")
)
Ainv <- pedigree_to_Ainv_sparse(ped)
class(Ainv)  # "dgCMatrix"
dim(Ainv)    # 6 x 6
} # }