Tinv <- makeTinv(Mrode2)
# Method for a numeric pedigree (of `nadiv` class "numPed")
nPed <- numPed(Mrode2)
Tinv2 <- makeTinv(nPed)
########
DF <- makeDiiF(Mrode2)
# manually construct the inverse of the relatedness matrix `Ainv`
Dinv <- DF$D #<-- not the inverse yet, just copying the object
Dinv@x <- 1 / DF$D@x #<-- inverse of a diagonal matrix
handAinv <- crossprod(Tinv, Dinv) %*% Tinv
# make the A-inverse directly
Ainv <- makeAinv(Mrode2)$Ainv
# Compare
handAinv
Ainv
stopifnot(all(abs((Ainv - handAinv)@x) < 1e-6))
# supply previous generation coefficients of inbreeding (f)
## to keep from re-calculating their f when analyzing subsequent generations
DF <- makeDiiF(Mrode2[, 1:3])
Mrode2$gen <- genAssign(Mrode2)
Mrode2$f_full <- DF$f
Mrode2$f_in <- with(Mrode2, c(f_full[gen <= 1], rep(NA, sum(gen > 1))))
DF2 <- makeDiiF(Mrode2[, 1:3], f = Mrode2$f_in)
stopifnot(identical(DF, DF2))
Run the code above in your browser using DataLab