## Total IBD and fraction of IBD for a cousin relationship
ped_fc <- pedtools::cousinPed()
# total IBD length for 100 cM
dist_length <- total_ibd_dist(ped_fc, chromosome_length = 100)
dist_length
plot(dist_length)
# fraction IBD for 100 cM
dist_fraction <- total_ibd_dist(ped_fc, chromosome_length = 100,
fraction = TRUE)
dist_fraction
plot(dist_fraction)
# distribution of total length across three chromosomes (150, 200, 250 cM)
plot(total_ibd_dist(ped_fc, chromosome_length = c(150, 200, 250)))
# a quick approximation with reasonable accuracy (with just 256 gridpoints)
plot(total_ibd_dist(ped_fc, chromosome_length = c(150, 200, 250),
number_of_gridpoints_exponent = 8))
## Difference between IBD distributions between half-sibs, uncle-nephew
## and grandparent-grandchild relationships
# kappa1 is 1/2 for half sibs, uncle-nephew and grandparent-grandchild
# but the distribution of the fraction of a chromosome that is in this
# state differs between the relationships
# define pedigrees and verify kappa1
ped_gp <- pedtools::linearPed(n = 2)
ped_av <- pedtools::avuncularPed()
ped_hs <- pedtools::halfSibPed()
stopifnot(all.equal(1/2,
d_ibd(1, ped_av),
d_ibd(1, ped_hs),
d_ibd(1, ped_gp, ids = c(1,5))))
# Compute IBD distributions
d_av <- total_ibd_dist(ped_av)
d_hs <- total_ibd_dist(ped_hs)
d_gp <- total_ibd_dist(ped_gp, ids = c(1,5))
# the point masses are different
d_av
d_hs
d_gp
# plot the continuous densities
x0 <- seq(0, 267.77, length.out = 200)
df <- data.frame(cM = rep(x0, 3),
y = c(d(d_av)(x0), d(d_hs)(x0), d(d_gp)(x0)),
Relationship = rep(c("Avuncular", "Half-Sibling",
"Grandparent"), each = length(x0)))
require(ggplot2)
ggplot(df, aes(x = cM, y = y, color = Relationship)) + geom_line()
Run the code above in your browser using DataLab