calculate_kinship.RdThis function calculates pairwise kinship coefficients for all individuals in a pedigree using a faster C++ implementation. The kinship coefficient between two individuals is the probability that a randomly chosen allele from one individual is identical by descent to a randomly chosen allele from the same locus in the other individual.
calculate_kinship(pedigree, sparse = FALSE, threshold = 1e-08)A data frame containing pedigree information with the following columns:
id: Unique identifier for each individual
mother: ID of the individual's mother (0 or NA for unknown/founder)
father: ID of the individual's father (0 or NA for unknown/founder)
Logical. If TRUE, returns a sparse matrix from the Matrix package. Default is FALSE, returning a dense matrix.
numeric. When sparse=TRUE, values smaller than this threshold will be treated as zero. Default is 1e-8.
A symmetric matrix of kinship coefficients where:
Row and column names are individual IDs
i,i contains the inbreeding coefficient + 0.5 for individual i
i,j contains the kinship coefficient between individuals i and j
# Create a simple pedigree with 3 individuals
ped <- data.frame(
id = c(1, 2, 3),
mother = c(0, 0, 2),
father = c(0, 0, 1)
)
kinship_matrix <- calculate_kinship(ped)