Title: | Versatile Functions for Working with Pedigrees |
---|---|
Description: | Tools to sort, edit and prune pedigrees and to extract the inbreeding coefficients and the relationship matrix (includes code for pedigrees from self-pollinated species). The use of pedigree data is central to genetics research within the animal and plant breeding communities to predict breeding values. The relationship matrix between the individuals can be derived from pedigree structure ('Vazquez et al., 2010') <doi:10.2527/jas.2009-1952>. |
Authors: | Ana I. Vazquez, Douglas M. Bates, Paulino Perez-Rodriguez, G. de los Campos, S. Avadhanam & Gregor Gorjanc |
Maintainer: | Paulino Perez Rodriguez <[email protected]> |
License: | GPL-3 |
Version: | 0.2 |
Built: | 2025-03-04 06:18:36 UTC |
Source: | https://github.com/rpedigree/pedigreetools |
Determine the diagonal factor in the decomposition of the relationship matrix A as TDT' where T is unit lower triangular.
Dmat(ped, vector = TRUE) getD(ped, vector = TRUE) getDInv(ped, vector = TRUE)
Dmat(ped, vector = TRUE) getD(ped, vector = TRUE) getDInv(ped, vector = TRUE)
ped |
|
vector |
logical, return a vector or sparse matrix |
a numeric vector
getD()
: Mendelian sampling variance
getDInv()
: Mendelian sampling precision (= 1 / variance)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (D <- getD(ped)) (DInv <- getDInv(ped)) # Test for correctness DExp <- c(1.00, 1.00, 0.50, 0.75, 0.50, 0.46875) stopifnot(!any(abs(D - DExp) > .Machine$double.eps)) DInvExp <- 1 / DExp stopifnot(!any(abs(DInv - DInvExp) > .Machine$double.eps))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (D <- getD(ped)) (DInv <- getDInv(ped)) # Test for correctness DExp <- c(1.00, 1.00, 0.50, 0.75, 0.50, 0.46875) stopifnot(!any(abs(D - DExp) > .Machine$double.eps)) DInvExp <- 1 / DExp stopifnot(!any(abs(DInv - DInvExp) > .Machine$double.eps))
Edits a disordered or incomplete pedigree by:
1) adding labels for the sires and dams not listed as labels before and
2) ordering pedigree based on recursive calls to getGenAncestors
.
editPed(sire, dam, label, verbose = FALSE)
editPed(sire, dam, label, verbose = FALSE)
sire |
integer vector or factor representation of the sires |
dam |
integer vector or factor representation of the dams |
label |
character vector of labels |
verbose |
logical to print the row of the pedigree that the function is ordering. Default is FALSE. |
a data frame with the pedigree ordered.
ped <- data.frame(sire=as.character(c(NA,NA,NA,NA,NA,1,3,5,6,4,8,1,10,8)), dam=as.character(c(NA,NA,NA,NA,NA,2,2,NA,7,7,NA,9,9,13)), label=as.character(1:14)) ped <- ped[sample(replace=FALSE, 1:14),] ped <- editPed(sire = ped$sire, dam = ped$dam, label = ped$label) ped <- with(ped, pedigree(label = label, sire = sire, dam = dam))
ped <- data.frame(sire=as.character(c(NA,NA,NA,NA,NA,1,3,5,6,4,8,1,10,8)), dam=as.character(c(NA,NA,NA,NA,NA,2,2,NA,7,7,NA,9,9,13)), label=as.character(1:14)) ped <- ped[sample(replace=FALSE, 1:14),] ped <- editPed(sire = ped$sire, dam = ped$dam, label = ped$label) ped <- with(ped, pedigree(label = label, sire = sire, dam = dam))
Returns the additive relationship matrix for the pedigree.
getA(ped, labs = NULL)
getA(ped, labs = NULL)
ped |
|
labs |
a character vector or a factor giving individual labels to
which to restrict the relationship matrix and corresponding factor. If
|
matrix (dsCMatrix - symmetric sparse)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (A <- getA(ped)) # Test for correctness AExp <- matrix(data = c(1.0000, 0.0000, 0.5000, 0.5000, 0.5000, 0.2500, 0.0000, 1.0000, 0.5000, 0.0000, 0.2500, 0.6250, 0.5000, 0.5000, 1.0000, 0.2500, 0.6250, 0.5625, 0.5000, 0.0000, 0.2500, 1.0000, 0.6250, 0.3125, 0.5000, 0.2500, 0.6250, 0.6250, 1.1250, 0.6875, 0.2500, 0.6250, 0.5625, 0.3125, 0.6875, 1.1250), byrow = TRUE, nrow = 6) stopifnot(!any(abs(A - AExp) > .Machine$double.eps)) stopifnot(Matrix::isSymmetric(A))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (A <- getA(ped)) # Test for correctness AExp <- matrix(data = c(1.0000, 0.0000, 0.5000, 0.5000, 0.5000, 0.2500, 0.0000, 1.0000, 0.5000, 0.0000, 0.2500, 0.6250, 0.5000, 0.5000, 1.0000, 0.2500, 0.6250, 0.5625, 0.5000, 0.0000, 0.2500, 1.0000, 0.6250, 0.3125, 0.5000, 0.2500, 0.6250, 0.6250, 1.1250, 0.6875, 0.2500, 0.6250, 0.5625, 0.3125, 0.6875, 1.1250), byrow = TRUE, nrow = 6) stopifnot(!any(abs(A - AExp) > .Machine$double.eps)) stopifnot(Matrix::isSymmetric(A))
Returns the inverse of additive relationship matrix for the pedigree.
getAInv(ped)
getAInv(ped)
ped |
matrix (dsCMatrix - symmetric sparse)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (AInv <- getAInv(ped)) # Test for correctness AInvExp <- matrix(data = c( 1.833, 0.500, -1.000, -0.667, 0.000, 0.000, 0.500, 2.033, -1.000, 0.000, 0.533, -1.067, -1.000, -1.000, 2.500, 0.500, -1.000, 0.000, -0.667, 0.000, 0.500, 1.833, -1.000, 0.000, 0.000, 0.533, -1.000, -1.000, 2.533, -1.067, 0.000, -1.067, 0.000, 0.000, -1.067, 2.133), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(AInv, digits = 3) - AInvExp) > .Machine$double.eps)) AInvExp <- solve(getA(ped)) stopifnot(!any(abs(round(AInv, digits = 14) - round(AInvExp, digits = 14)) > .Machine$double.eps)) stopifnot(is(AInv, "sparseMatrix")) stopifnot(Matrix::isSymmetric(AInv))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (AInv <- getAInv(ped)) # Test for correctness AInvExp <- matrix(data = c( 1.833, 0.500, -1.000, -0.667, 0.000, 0.000, 0.500, 2.033, -1.000, 0.000, 0.533, -1.067, -1.000, -1.000, 2.500, 0.500, -1.000, 0.000, -0.667, 0.000, 0.500, 1.833, -1.000, 0.000, 0.000, 0.533, -1.000, -1.000, 2.533, -1.067, 0.000, -1.067, 0.000, 0.000, -1.067, 2.133), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(AInv, digits = 3) - AInvExp) > .Machine$double.eps)) AInvExp <- solve(getA(ped)) stopifnot(!any(abs(round(AInv, digits = 14) - round(AInvExp, digits = 14)) > .Machine$double.eps)) stopifnot(is(AInv, "sparseMatrix")) stopifnot(Matrix::isSymmetric(AInv))
Extends the pedigree according to number of selfing cycles and also optionally computes the Additive Relationship Matrix for that pedigree.
getASelfing( ID, Par1, Par2, nCycles, nCyclesDefault, sepChar = "-F", verbose = FALSE, fileNewPed = NULL, computeA = TRUE )
getASelfing( ID, Par1, Par2, nCycles, nCyclesDefault, sepChar = "-F", verbose = FALSE, fileNewPed = NULL, computeA = TRUE )
ID |
is a vector of individual IDs |
Par1 |
vector of IDs of one of the parents |
Par2 |
vector of IDs of the other parent |
nCycles |
vector that indicates number of selfing cycles for each individual. |
nCyclesDefault |
default value of nCycles |
sepChar |
character, used for expanded pedigree IDs |
verbose |
logical, print progress |
fileNewPed |
Output csv file (comma separated value) with columns 'label', 'sire', 'dam', with the full pull pedigree expanded taking into account the selfing cycles |
computeA |
Indicates if the A matrix is to be computed |
Returns A matrix computed for the extended pedigree if computeA=TRUE
Returns subset of the additive relationship matrix for the pedigree.
getASubset(ped, labs)
getASubset(ped, labs)
ped |
|
labs |
a character vector or a factor giving individual labels to
which to restrict the relationship matrix and corresponding factor using
Colleau et al. (2002) algorithm. If |
matrix (dsCMatrix - symmetric sparse)
Colleau, J.-J. An indirect approach to the extensive calculation of relationship coefficients. Genet Sel Evol 34, 409 (2002). https://doi.org/10.1186/1297-9686-34-4-409
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (A <- getA(ped)) (ASubset <- A[4:6, 4:6]) (ASubset2 <- getASubset(ped, labs = 4:6)) (ASubset3 <- A[6:4, 6:4]) (ASubset4 <- getASubset(ped, labs = 6:4)) # Test for correctness stopifnot(!any(abs(ASubset - ASubset2) > .Machine$double.eps)) stopifnot(!any(abs(ASubset3 - ASubset4) > .Machine$double.eps)) stopifnot(Matrix::isSymmetric(ASubset2)) stopifnot(Matrix::isSymmetric(ASubset4))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (A <- getA(ped)) (ASubset <- A[4:6, 4:6]) (ASubset2 <- getASubset(ped, labs = 4:6)) (ASubset3 <- A[6:4, 6:4]) (ASubset4 <- getASubset(ped, labs = 6:4)) # Test for correctness stopifnot(!any(abs(ASubset - ASubset2) > .Machine$double.eps)) stopifnot(!any(abs(ASubset3 - ASubset4) > .Machine$double.eps)) stopifnot(Matrix::isSymmetric(ASubset2)) stopifnot(Matrix::isSymmetric(ASubset4))
Counts number of generations of ancestors for one subject. Use recursion.
getGenAncestors(ped, id, ngen = NULL)
getGenAncestors(ped, id, ngen = NULL)
ped |
data.frame with a pedigree and a column for the number of generations of each subject. |
id |
subject for which we want the number of generations. |
ngen |
number of generation |
a data frame object with the pedigree and generation of ancestors for subject id.
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped <- ped2DF(ped) ped$id <- row.names(ped) ped$generation <- NA (tmp1 <- getGenAncestors(ped, id = 1)) (tmp2 <- getGenAncestors(ped, id = 4)) (tmp3 <- getGenAncestors(ped, id = 6)) # Test for correctness stopifnot(tmp1$generation[1] == 0) stopifnot(all(is.na(tmp1$generation[-1]))) stopifnot(all(tmp2$generation[c(1, 4)] == c(0, 1))) stopifnot(all(is.na(tmp2$generation[-c(1, 4)]))) stopifnot(all(tmp3$generation == c(0, 0, 1, 1, 2, 3)))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped <- ped2DF(ped) ped$id <- row.names(ped) ped$generation <- NA (tmp1 <- getGenAncestors(ped, id = 1)) (tmp2 <- getGenAncestors(ped, id = 4)) (tmp3 <- getGenAncestors(ped, id = 6)) # Test for correctness stopifnot(tmp1$generation[1] == 0) stopifnot(all(is.na(tmp1$generation[-1]))) stopifnot(all(tmp2$generation[c(1, 4)] == c(0, 1))) stopifnot(all(is.na(tmp2$generation[-c(1, 4)]))) stopifnot(all(tmp3$generation == c(0, 0, 1, 1, 2, 3)))
Get gene flow matrix from a pedigree.
getT(ped)
getT(ped)
ped |
matrix (dtCMatrix - lower unitriangular sparse)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (T <- getT(ped)) # Test for correctness TExp <- matrix(data = c(1.00, 0.000, 0.00, 0.00, 0.0, 0, 0.00, 1.000, 0.00, 0.00, 0.0, 0, 0.50, 0.500, 1.00, 0.00, 0.0, 0, 0.50, 0.000, 0.00, 1.00, 0.0, 0, 0.50, 0.250, 0.50, 0.50, 1.0, 0, 0.25, 0.625, 0.25, 0.25, 0.5, 1), byrow = TRUE, nrow = 6) stopifnot(!any(abs(T - TExp) > .Machine$double.eps))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (T <- getT(ped)) # Test for correctness TExp <- matrix(data = c(1.00, 0.000, 0.00, 0.00, 0.0, 0, 0.00, 1.000, 0.00, 0.00, 0.0, 0, 0.50, 0.500, 1.00, 0.00, 0.0, 0, 0.50, 0.000, 0.00, 1.00, 0.0, 0, 0.50, 0.250, 0.50, 0.50, 1.0, 0, 0.25, 0.625, 0.25, 0.25, 0.5, 1), byrow = TRUE, nrow = 6) stopifnot(!any(abs(T - TExp) > .Machine$double.eps))
Get inverse gene flow matrix from a pedigree.
getTInv(ped)
getTInv(ped)
ped |
matrix (dtCMatrix - lower unitriangular sparse)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (TInv <- getTInv(ped)) # Test for correctness TInvExp <- matrix(data = c( 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -0.5, -0.5, 1.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -0.5, -0.5, 1.0, 0.0, 0.0, -0.5, 0.0, 0.0, -0.5, 1.0), byrow = TRUE, nrow = 6) stopifnot(!any(abs(TInv - TInvExp) > .Machine$double.eps)) stopifnot(is(TInv, "sparseMatrix"))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (TInv <- getTInv(ped)) # Test for correctness TInvExp <- matrix(data = c( 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -0.5, -0.5, 1.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -0.5, -0.5, 1.0, 0.0, 0.0, -0.5, 0.0, 0.0, -0.5, 1.0), byrow = TRUE, nrow = 6) stopifnot(!any(abs(TInv - TInvExp) > .Machine$double.eps)) stopifnot(is(TInv, "sparseMatrix"))
Create the inbreeding coefficients according to the algorithm given in "Comparison of four direct algorithms for computing inbreeding coefficients" by Mehdi Sargolzaei and Hiroaki Iwaisaki, Animal Science Journal (2005) 76, 401–406.
inbreeding(ped)
inbreeding(ped)
ped |
the inbreeding coefficients as a numeric vector
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (F <- inbreeding(ped)) # Test for correctness FExp <- c(0.000, 0.000, 0.000, 0.000, 0.125, 0.125) stopifnot(!any(abs(F - FExp) > .Machine$double.eps))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (F <- inbreeding(ped)) # Test for correctness FExp <- c(0.000, 0.000, 0.000, 0.000, 0.125, 0.125) stopifnot(!any(abs(F - FExp) > .Machine$double.eps))
Express a pedigree as a data frame with sire
and
dam
stored as factors. If the pedigree is an object of
class pedinbred then the inbreeding coefficients are
appended as the variable F
ped2DF(x)
ped2DF(x)
x |
a data frame
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped2DF(ped)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped2DF(ped)
A simple constructor for a pedigree object. The main point for the constructor is to use coercions to make the calls easier.
pedigree(sire, dam, label)
pedigree(sire, dam, label)
sire |
integer vector or factor representation of the sires |
dam |
integer vector or factor representation of the dams |
label |
character vector of individual labels |
an pedigree object of class pedigree
sire
, dam
and label
must all have the
same length and all labels in sire
and dam
must occur
in label
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) ped
Subsets a pedigree for a specified vector of individuals up to a specified number of previous generations using recursion.
prunePed(ped, selectVector, ngen = 2)
prunePed(ped, selectVector, ngen = 2)
ped |
Data Frame pedigree to be subset |
selectVector |
Vector of individuals to select from pedigree |
ngen |
Number of previous generations of parents to select starting from selectVector. |
Returns Subsetted pedigree as a DataFrame.
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6)
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6)
Determine the right Cholesky factor of the relationship matrix
for the pedigree ped
, possibly restricted to the specific labels
that occur in labs
.
relfactor(ped, labs = NULL) getL(ped, labs = NULL)
relfactor(ped, labs = NULL) getL(ped, labs = NULL)
ped |
|
labs |
a character vector or a factor giving individual labels to
which to restrict the relationship matrix and corresponding factor using
Colleau et al. (2002) algorithm. If |
Note that the right Cholesky factor is returned, which is upper triangular, that is from A = LL' = R'R (lower (upper triangular) and not L (lower triangular) as the function name might suggest.
matrix (dtCMatrix - upper triangular sparse)
getL()
: Relationship factor from a pedigree
Colleau, J.-J. An indirect approach to the extensive calculation of relationship coefficients. Genet Sel Evol 34, 409 (2002). https://doi.org/10.1186/1297-9686-34-4-409
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (L <- getL(ped)) chol(getA(ped)) # Test for correctness LExp <- matrix(data = c(1.0000, 0.0000, 0.5000, 0.5000, 0.5000, 0.2500, 0.0000, 1.0000, 0.5000, 0.0000, 0.2500, 0.6250, 0.0000, 0.0000, 0.7071, 0.0000, 0.3536, 0.1768, 0.0000, 0.0000, 0.0000, 0.8660, 0.4330, 0.2165, 0.0000, 0.0000, 0.0000, 0.0000, 0.7071, 0.3536, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.6847), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(L, digits = 4) - LExp) > .Machine$double.eps)) LExp <- chol(getA(ped)) stopifnot(!any(abs(L - LExp) > .Machine$double.eps)) (L <- getL(ped, labs = 4:6)) (LExp <- chol(getA(ped)[4:6, 4:6])) stopifnot(!any(abs(L - LExp) > .Machine$double.eps))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (L <- getL(ped)) chol(getA(ped)) # Test for correctness LExp <- matrix(data = c(1.0000, 0.0000, 0.5000, 0.5000, 0.5000, 0.2500, 0.0000, 1.0000, 0.5000, 0.0000, 0.2500, 0.6250, 0.0000, 0.0000, 0.7071, 0.0000, 0.3536, 0.1768, 0.0000, 0.0000, 0.0000, 0.8660, 0.4330, 0.2165, 0.0000, 0.0000, 0.0000, 0.0000, 0.7071, 0.3536, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.6847), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(L, digits = 4) - LExp) > .Machine$double.eps)) LExp <- chol(getA(ped)) stopifnot(!any(abs(L - LExp) > .Machine$double.eps)) (L <- getL(ped, labs = 4:6)) (LExp <- chol(getA(ped)[4:6, 4:6])) stopifnot(!any(abs(L - LExp) > .Machine$double.eps))
Get inverse of the left Cholesky factor of the relationship
matrix for the pedigree ped
.
relfactorInv(ped) getLInv(ped)
relfactorInv(ped) getLInv(ped)
ped |
Note that the inverse of the left Cholesky factor is returned, which is lower triangular, that is from A = LL' (lower inv(A) = inv(LL') = inv(L)' inv(L) (upper triangular).
matrix (dtCMatrix - triangular sparse)
getLInv()
: Inverse relationship factor from a pedigree
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (LInv <- getLInv(ped)) solve(Matrix::t(getL(ped))) # Test for correctness LInvExp <- matrix(data = c( 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.7071, -0.7071, 1.4142, 0.0000, 0.0000, 0.0000, -0.5774, 0.0000, 0.0000, 1.1547, 0.0000, 0.0000, 0.0000, 0.0000, -0.7071, -0.7071, 1.4142, 0.0000, 0.0000, -0.7303, 0.0000, 0.0000, -0.7303, 1.4606), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(LInv, digits = 4) - LInvExp) > .Machine$double.eps)) L <- t(chol(getA(ped))) LInvExp <- solve(L) stopifnot(!any(abs(LInv - LInvExp) > .Machine$double.eps)) stopifnot(is(LInv, "sparseMatrix"))
ped <- pedigree(sire = c(NA, NA, 1, 1, 4, 5), dam = c(NA, NA, 2, NA, 3, 2), label = 1:6) (LInv <- getLInv(ped)) solve(Matrix::t(getL(ped))) # Test for correctness LInvExp <- matrix(data = c( 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.7071, -0.7071, 1.4142, 0.0000, 0.0000, 0.0000, -0.5774, 0.0000, 0.0000, 1.1547, 0.0000, 0.0000, 0.0000, 0.0000, -0.7071, -0.7071, 1.4142, 0.0000, 0.0000, -0.7303, 0.0000, 0.0000, -0.7303, 1.4606), byrow = TRUE, nrow = 6) stopifnot(!any(abs(round(LInv, digits = 4) - LInvExp) > .Machine$double.eps)) L <- t(chol(getA(ped))) LInvExp <- solve(L) stopifnot(!any(abs(LInv - LInvExp) > .Machine$double.eps)) stopifnot(is(LInv, "sparseMatrix"))