
Sparse pedigree inverse-A via Henderson-Quaas (MCMCglmm-free)
Source:R/animal-keyword.R
pedigree_to_Ainv_sparse.RdBuilds the sparse precision matrix \(\mathbf A^{-1}\) for an animal-
model pedigree using only Matrix – no 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 computed by the Meuwissen & Luo (1992) walk (no dense
\(\mathbf A\) on the fit path), then \(\mathbf A^{-1}\) is assembled
from the per-individual Mendelian sampling variances. It reproduces
MCMCglmm::inverseA(pedigree)$Ainv exactly.
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.
Meuwissen, T. H. E., and Luo, Z. (1992). Computing inbreeding coefficients in large populations. Genetics Selection Evolution 24: 305-313.
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
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"
#> [1] "dgCMatrix"
#> attr(,"package")
#> [1] "Matrix"
dim(Ainv) # 6 x 6
#> [1] 6 6
## The sparse precision inverts the dense relationship matrix:
all.equal(as.matrix(solve(Ainv)), pedigree_to_A(ped), check.attributes = FALSE)
#> [1] TRUE