Can one mixture explain how an ancient target shares alleles with multiple
reference groups? We first use the f4 model from E.2 to test two candidate
source combinations. We then estimate the proportions using local tree
sharing. A final example changes the input to IBD segments and follows two
regions through time.
Read Pritchard, Chapter 3.2, Eq. 3.21 for the frequency contrast and Fig. 3.102 for the European ancestry time series.
library(hpgR)
options(repr.plot.width = 9, repr.plot.height = 3.8)
set.seed(1203)One proportion across three reference contrasts¶
Let and . Under the two-source model, for all three contrasts. Use the numbers on qpAdm Fits One Proportion Across References.
The artificial block values below reproduce the slide’s independent normal error model, with standard deviation 0.30 per entry. The second example changes only the third target contrast.
x <- c(4, 2, -2)
y <- c(1, .5, -.3)
offset <- rbind(diag(6L), -diag(6L)) * .30 * sqrt(12 * 11 / 2)
source <- sweep(offset[, 1:3], 2, x, "+")
sameSource <- sweep(offset[, 4:6], 2, y, "+")
changedSource <- sweep(offset[, 4:6], 2, c(1, .5, .8), "+")
toy <- lapply(list(sameSource, changedSource), function(target) fitF4Mixture(source, target))
t(vapply(toy, function(a) unlist(a[c("proportion", "statistic", "p")]), numeric(3)))Test source proxies in an ancient panel¶
Use the same question as Can Other Ancient Genomes Explain the Same Signal? Source A and a widespread source B contributed to the target. The reference and proxy populations descend from related ancestral groups. Each experienced some separate drift. The third candidate, C, replaces A in a second fit.
Simulate 80 linked SNP blocks. Each of two target copies inherits a changing mosaic of A and B ancestry. At each target SNP, draw one of the two alleles to mimic pseudohaploid sampling. High-coverage source and reference panels supply several copies per site.
truth <- .25
panels <- lapply(12301:12304, function(seed) {
set.seed(seed)
simulateAdmixturePanel(position = seq(0, .16, length.out = 300L),
blocks = 80L, sourceFraction = truth, targetDiploids = 1L,
referenceCopies = 16L, redrawRate = 23)
})
fits <- lapply(panels, function(panel) {
x <- panel$contrast
lapply(c("A", "C"), function(g) fitF4Mixture(x[, , g], x[, , "T"]))
})
summary <- t(vapply(seq_along(panels), function(i) {
a <- fits[[i]][[1L]]
c(realized = panels[[i]]$realized, q = a$proportion, blockSE = a$se,
pAB = a$p, pCB = fits[[i]][[2L]]$p)
}, numeric(5L)))
print(signif(summary, 3)) realized q blockSE pAB pCB
[1,] 0.275 0.263 0.0446 0.905 9.08e-07
[2,] 0.278 0.269 0.0398 0.868 5.25e-09
[3,] 0.247 0.232 0.0405 0.150 1.35e-04
[4,] 0.245 0.204 0.0373 0.822 1.56e-05
x <- panels[[1]]$contrast
observed <- colMeans(x[, , "T"])
fitted <- rbind(observed, fits[[1]][[1]]$proportion * colMeans(x[, , "A"]),
fits[[1]][[2]]$proportion * colMeans(x[, , "C"]),
truth * colMeans(x[, , "A"]))
barplot(1000 * fitted, beside = TRUE, col = c("#262626", "#285687", "#909090", "#B22732"),
ylab = "Target contrast (per 1,000)", xlab = "Reference compared to R0",
ylim = extendrange(1000 * fitted, f = .2),
legend.text = c("Observed", "A + B fit", "C + B fit", "A + B at generating fraction"),
args.legend = list(x = "topright", bty = "n", cex = .78, y.intersp = 2.15))
The target’s measured genome fraction varies around 25%. Its estimate also depends on which SNPs and source proxies happen to be sampled. Look at all reference contrasts together. A close match to one contrast can coexist with poor predictions for the others. This is the two-source rank condition from the lecture. The test uses a block covariance and an approximate chi-squared reference distribution.
Change the reference panel¶
In the simulation, R3 and alternative proxy C share drift. Remove R3 and repeat the tests using R1 and R2. Compare the evidence against C and the precision of the source-A proportion. The target and source genotypes stay the same.
remaining <- c("R1", "R2")
withoutR3 <- lapply(panels, function(panel) {
x <- panel$contrast
list(A = fitF4Mixture(x[, remaining, "A"], x[, remaining, "T"]),
C = fitF4Mixture(x[, remaining, "C"], x[, remaining, "T"]))
})
reduced <- t(vapply(withoutR3, function(fit)
c(se = fit$A$se, p = fit$C$p), numeric(2L)))
signif(cbind(seAll = summary[, "blockSE"], seWithoutR3 = reduced[, "se"],
pCAll = summary[, "pCB"], pCWithoutR3 = reduced[, "p"]), 3)Fit a profile from simulated local trees¶
Now ask which reference lineages are closest along the genome, as in Fit the Target’s Whole Painting Profile. There are two reference copies per population. On each random interval, lineages first merge within their populations. At the split, any remaining lineages enter a common ancestral pool. The two target copies draw their source populations before these mergers. Even within one source, drift changes which reference is closest.
The input here is the set of recorded trees. The Xingyi study inferred its trees from sequence data with Relate. This calculation isolates the painting and profile fit that follow that step.
set.seed(12305)
pure <- diag(3L)
membership <- rbind(pure[rep(1:3, each = 2), ],
pure[c(1, 2), ], matrix(rep(c(truth, 1 - truth, 0), 2),
nrow = 2L, byrow = TRUE))
treeChromosomes <- seq_len(22L)
treePanels <- lapply(treeChromosomes, function(i)
simulateSplitTrees(.9 + i / 44, redrawRate = 42, membership, rep(3200, 3), 2800, 9000))
profiles <- simplify2array(lapply(treePanels, function(ancestry) {
sharing <- vapply(6:9, function(copy)
colSums(matrix(localTreeSharing(ancestry, copy, 0:5), nrow = 2L)), numeric(3L))
cbind(A = sharing[, 1], B = sharing[, 2], Target = rowMeans(sharing[, 3:4]))
}))
full <- apply(profiles, 1:2, mean)
treeEstimate <- fitSharingMixture(full[, "Target"], full[, "A"], full[, "B"])$proportion
treeLeaveOut <- vapply(treeChromosomes, function(i) {
x <- apply(profiles[, , -i], 1:2, mean)
fitSharingMixture(x[, "Target"], x[, "A"], x[, "B"])$proportion
}, numeric(1))
treeTruth <- mean(vapply(treePanels, function(tree)
sum(diff(tree$cuts) * rowMeans(tree$population[, 9:10] == 1)) / tree$sequenceLength,
numeric(1)))
rownames(full) <- paste("Reference", 1:3)
round(full, 3)
round(c(generatingA = truth, realizedA = treeTruth, inferredA = treeEstimate,
chromosomeSE = sqrt(21 * mean((treeLeaveOut - mean(treeLeaveOut))^2))), 3)Date one node on a fixed tree¶
Relate first infers the relationships in a local tree, then uses MCMC to sample branch times given the mutations. For one pair in a nonrecombining region there is only one unknown node time . Let have an exponential prior with mean . Given , draw the number of pairwise differences as Poisson with mean . A Metropolis step proposes a new and accepts or rejects it using the posterior. In this small model the posterior is gamma, so we can check the sampler directly.
set.seed(12307)
generatingTime <- 16000
mu <- 1.25e-8
bases <- 20000L
differences <- rpois(1L, 2 * mu * bases * generatingTime)
chain <- samplePairAncestorTime(differences, 10000, bases, mu, draws = 14000L)
times <- chain$time[2001:14000]
round(c(differences = differences, acceptance = chain$acceptance,
generatingTime = generatingTime, mcmcMean = mean(times),
exactMean = chain$shape / chain$rate), 2)
hist(times / 1000, freq = FALSE, breaks = 35, col = "#CAD7E8", border = "white",
main = "", xlab = "Node age (thousand generations)", ylab = "Posterior density")
curve(1000 * dgamma(1000 * x, shape = chain$shape, rate = chain$rate), add = TRUE,
col = "#285687", lwd = 2.5)
abline(v = generatingTime / 1000, col = "#B22732", lwd = 2.5)
legend("topright", c("Exact posterior", "Generating time"), col = c("#285687", "#B22732"),
lty = 1, lwd = 2.5, bty = "n", y.intersp = 1.8)
Repeated MCMC states arise when a proposal is rejected. Their distribution describes uncertainty about the node’s age conditional on the observed differences, the prior and the mutation rate. Relate dates multiple nodes subject to their order on the tree.
Follow shared haplotypes across regions and times¶
Follow IBD and the Spread of Celtic Languages. The central region’s new ancestry rises before the western region’s. On each chromosome, simulate distinct sampled copies as mosaics of older founder copies. Independent mosaics create distinct source and target haplotypes, including some shared founders across sources. Random crossovers and marker errors make a long exact match imperfect.
Estimate background sharing from separate source controls. Then fit a mixture to each cohort’s profile of matches to the two reference panels. Only the simulated marker sequences and map enter segment detection.
set.seed(12306)
epochs <- c(4000, 3400, 2800, 2200)
cohorts <- data.frame(region = rep(c("Central", "Western"), each = 4L),
year = rep(epochs, 2L), truth = c(.10, .55, .65, .65, .08, .12, .42, .58))
copiesPerCohort <- 8L
group <- rep(1:8, each = copiesPerCohort)
weights <- c(rep(1, 10), rep(0, 10), cohorts$truth[group])
reference <- list(1:5, 11:15)
controls <- list(6:10, 16:20)
chromosomes <- 1:22
chr <- lapply(chromosomes, function(i) {
position <- seq(0, .7 + i / 44, by = .0008)
founder <- matrix(rbinom(28L * length(position), 1, .5), 28L)
dna <- simulateFounderCopies(position, founder, list(c(1:12, 25:28), c(13:24, 25:28)),
weights, mixtureRate = 14, copyingRate = 13, errorRate = .002)
segments <- detectIbdSegments(dna$haplotypes, position, wordSize = 4L, minimumCm = 1.5, gap = 1L)
list(sharing = ibdReferenceProfiles(segments, reference, nrow(dna$haplotypes)),
realized = rowMeans(dna$ancestry == 1L))
})
subsets <- c(list(chromosomes), lapply(chromosomes, function(i) setdiff(chromosomes, i)))
bySubset <- vapply(subsets, function(keep) {
sharing <- Reduce("+", lapply(chr[keep], "[[", "sharing"))
groups <- c(controls, split(seq_along(group) + 20L, group))
profile <- vapply(groups, function(ids) {
value <- colMeans(sharing[ids, , drop = FALSE])
value / sum(value)
}, numeric(2L))
vapply(3:10, function(i)
fitSharingMixture(profile[, i], profile[, 1], profile[, 2])$proportion, numeric(1))
}, numeric(8L))
cohorts$estimate <- bySubset[, 1]
leaveOut <- bySubset[, -1]
cohorts$se <- sqrt(21 / 22 * rowSums((leaveOut - rowMeans(leaveOut))^2))
realized <- Reduce("+", lapply(chr, "[[", "realized"))[-(1:20)] / length(chr)
cohorts$realized <- unname(tapply(realized, group, mean))
print(cohorts, digits = 3, row.names = FALSE) region year truth estimate se realized
Central 4000 0.10 0.0891 0.0411 0.1053
Central 3400 0.55 0.5561 0.0441 0.5507
Central 2800 0.65 0.5907 0.0383 0.6601
Central 2200 0.65 0.5852 0.0280 0.6481
Western 4000 0.08 0.0567 0.0504 0.0707
Western 3400 0.12 0.0542 0.0466 0.1007
Western 2800 0.42 0.3408 0.0464 0.4344
Western 2200 0.58 0.5946 0.0538 0.5780
plot(NA, xlim = rev(range(epochs)), ylim = c(0, .85),
xlab = "Years before present", ylab = "Source 1 contribution")
palette <- c("#285687", "#008270")
for (j in seq_along(palette)) {
a <- cohorts[cohorts$region == unique(cohorts$region)[j], ]
lines(a$year, a$truth, col = "#B22732", lty = j, lwd = 2)
arrows(a$year, pmax(0, a$estimate - 2 * a$se), a$year, pmin(1, a$estimate + 2 * a$se),
code = 3, angle = 90, length = .055, col = palette[j])
lines(a$year, a$estimate, type = "b", col = palette[j], lty = j, pch = 16, lwd = 2)
}
legend("topleft", c("Central estimate", "Western estimate", "Generating histories"),
lty = c(1, 2, 1), col = c(palette, "#B22732"), lwd = 2, bty = "n", cex = .85, y.intersp = 2.0)
Compare the central and western time series, including the chromosome uncertainty at each date. The Celtic study used many more ancestry clusters and a dedicated ancient IBD caller. It compared shifts in ancestry with separate archaeological and linguistic evidence.
Harney et al., qpAdm · Wang et al., Xingyi · McColl et al., Celtic languages
- Harney, É., Patterson, N., Reich, D., & Wakeley, J. (2021). Assessing the performance of qpAdm: a statistical tool for studying population admixture. Genetics, 217(4). 10.1093/genetics/iyaa045
- Wang, T., Yang, M. A., Zhu, Z., Ma, M., Shi, H., Speidel, L., Min, R., Yuan, H., Jiang, Z., Hu, C., Li, X., Zhao, D., Bai, F., Cao, P., Liu, F., Dai, Q., Feng, X., Yang, R., Wu, X., … Fu, Q. (2025). Prehistoric genomes from Yunnan reveal ancestry related to Tibetans and Austroasiatic speakers. Science, 388(6750). 10.1126/science.adq9792
- McColl, H., Kroonen, G., Pinotti, T., Barrie, W., Koch, J., Ling, J., Demoule, J.-P., Kristiansen, K., Sikora, M., & Willerslev, E. (2026). Tracing the spread of Celtic languages using ancient genomics. Nature, 659(8142), 1031–1040. 10.1038/s41586-026-11198-9