# 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 )
Run the code above in your browser using DataLab