## Convolution of IBD distributions for half siblings at chromosome 1 and 2
# define half sib pedigree
ped_hs <- pedtools::halfSibPed()
# obtain chromosome-wise distributions
d1 <- total_ibd_dist(pedigree = ped_hs, chromosome_length = 267.77)
d2 <- total_ibd_dist(pedigree = ped_hs, chromosome_length = 251.73)
convolve_total_ibd_dists(d1, d2) # 4 point masses
## Accuracy of convolution depends on number of gridpoints
L <- c(267.77, 251.73, 218.31, 202.89, 197.08, 186.02, 178.4, 161.54,
157.35, 169.28, 154.5, 165.49, 127.23, 116, 117.32, 126.59, 129.53,
116.52, 106.35, 107.76, 62.88, 70.84)
# obtain chromosome-wise distributions for half siblings
hs <- total_ibd_dist(pedigree = ped_hs,
chromosome_length = L, convolve = FALSE)
# obtain moments of the sum by summing the moments..
mean_hat <- sum(sapply(hs, E))
sd_hat <- sqrt(sum(sapply(hs, var)))
# .. or by summing the distributions with varying numbers of gridpoints
k <- 6:10
sd_hat_by_k <- sapply(k, function(k) sd(convolve_total_ibd_dists(hs,
number_of_gridpoints_exponent = k)))
mean_hat_by_k <- sapply(k, function(k) E(convolve_total_ibd_dists(hs,
number_of_gridpoints_exponent = k)))
plot(k, mean_hat_by_k)
abline(h = mean_hat, lty = 2)
plot(k, sd_hat_by_k)
abline(h = sd_hat, lty = 2)
Run the code above in your browser using DataLab