avg_kinship_subpops {popkin} | R Documentation |
Calculate a kinship matrix between subpopulations by averaging individual data
Description
This function calculates a kinship matrix between subpopulations, whose values are the average kinship values between all individual pairs where one individual is in the first subpopulation and the other individual is in the second subpopulation.
To estimate coancestry instead of kinship, which is recommended to get more interpretable diagonal values, the input kinship matrix should be transformed using inbr_diag()
.
Usage
avg_kinship_subpops(kinship, subpops, subpop_order = unique(subpops))
Arguments
kinship |
A symmetric |
subpops |
The length- |
subpop_order |
The optional order of subpopulations in the output matrix.
|
Value
The symmetric K
-by-K
kinship matrix between subpopulations, where K
is the number of unique subpopulations in subpops
, ordered as in subpop_order
.
Examples
# a toy kinship matrix with 5 individuals belonging to 2 subpopulations
kinship <- matrix(
c(
0.7, 0.4, 0.4, 0.1, 0.0,
0.4, 0.7, 0.4, 0.2, 0.1,
0.4, 0.4, 0.7, 0.2, 0.0,
0.1, 0.2, 0.2, 0.6, 0.1,
0.0, 0.1, 0.0, 0.1, 0.6
),
nrow = 5,
ncol = 5
)
subpops <- c(1, 1, 1, 2, 2)
# calculate mean kinship between (and within) subpopulations
# a 2x2 matrix
avg_kinship_subpops( kinship, subpops )
# calculate coancestry estimate instead (difference is diagonal)
avg_kinship_subpops( inbr_diag( kinship ), subpops )