Scope and decision rule
We use qpAdm to estimate the proportions in which specified source proxies can account for a target population's allele-frequency relationships to a set of reference populations, often called outgroups. The fit is a linear combination of those sources under the proposed model. With a prespecified threshold of 0.05, we retain fits whose rank-test p-value is at least 0.05 as statistically compatible with the constraint for that design.
Several sets of proxies can be compatible with the same data. Each p-value measures fit under its own model and references. To choose among compatible proxies, we compare resolution, uncertainty and independent evidence about source dates and relationships. The walkthrough starts with a runnable package example and then follows the analysis of a local genotype panel.
Allele-frequency contrasts and rank
An f4 statistic averages the product of two allele-frequency differences across SNPs. For a shared set of sites, the population expression has the form below. The software estimates these averages from samples, using the SNPs and finite-sample conventions for the selected input regime.
f₄(A,B;C,D) = mean[(pA − pB) × (pC − pD)]
A positive value means the two differences tend to have the same sign. Reversing either pair reverses the sign. We use genomic blocks to estimate uncertainty because nearby SNPs can be correlated. A result close to zero within its uncertainty leaves the two sides of the contrast unresolved at the available coverage.
With k sources and r right populations, choose one right population R0 as the baseline. Form one row of contrasts for each source Si against the target T, with one column for each remaining reference Rj. The entry is f₄(T,Sᵢ;R₀,Rⱼ). If a weighted combination of the sources accounts for the target across those contrasts, the weights sum to one and the weighted combination of the rows is zero under the model. The resulting k × (r − 1) matrix has rank at most k − 1. The rank restriction is a necessary condition. A mixture also requires a solution that can be normalized to feasible weights.
qpAdm tests that rank restriction using the covariance estimated from genomic blocks. The p-value is the probability, under the rank null, of obtaining a test statistic at least as large as the one observed. For the model rank k − 1, the reference chi-square test has r − k degrees of freedom. Positive residual degrees of freedom require more references than sources. More references can help when they add informative contrasts, and shared ancestry between references can leave the existing contrasts nearly redundant. Harney et al. (2021) · qpWave and qpAdm vignette.
Analysis workflow
Complete the installation with the bundled example. The subsequent steps use an AADR-derived panel with named populations and checked SNP orientation.
Evidence figure
Order of analysis
- Verify the genotype build, alleles and sample roster.
- Record the sources, reference panel and decision rule.
- Compute SNP blocks and examine individual contrasts.
- Fit the declared models and test specified alternatives.
- Save the outputs with fit, precision and feasibility decisions.
1. Install and test ADMIXTOOLS 2
Use a local R session on Linux, macOS or WSL. This walkthrough was checked with ADMIXTOOLS 2.0.10 at the revision below. Install it once, then start a clean session for each analysis.
install.packages("remotes")
remotes::install_github(
"uqrmaie1/admixtools",
ref = "2f6957a36224c15884abf84c543aefddf46352f0"
)
library(admixtools)
packageVersion("admixtools")The package includes precomputed blocks for a small example. Use them to check the installation and inspect the shape of the outputs before downloading data. The population labels in this exercise are for an interface check.
library(admixtools)
data("example_f2_blocks", package = "admixtools")
demo <- qpadm(
example_f2_blocks,
target = "Switzerland_Bichon.SG",
left = c("Russia_Ust_Ishim.DG", "Mbuti.DG"),
right = c("Chimp.REF", "Altai_Neanderthal.DG", "Denisova.DG", "Vindija.DG"),
verbose = FALSE
)
print(demo$weights)
print(demo$rankdrop)For the next steps, obtain the AADR v66 release and its annotation. Select a release panel and record the genome build, release version and date, input checksums, software versions and filters. The R examples assume EIGENSTRAT or packed ancestry map files with a common .geno, .snp and .ind prefix.
2. Prepare the local genotype panel
Raw consumer genotypes are identifying data. Keep them out of public repositories, cloud build logs, screenshots, and web upload forms. Work locally and publish aggregate outputs only.
For a 23andMe text export, PLINK 1.9 can import the autosomal calls into a local binary dataset. Substitute the file path for your export. Record its genome build before import and retain PLINK's import log.
umask 077
mkdir -p local-genotypes
plink --23file /path/to/23andme.txt TARGET TARGET \
--autosome --make-bed --out local-genotypes/chip
plink --bfile local-genotypes/chip --missing \
--out local-genotypes/chip-qcUse an importer that understands the export format for the specific test provider. Before merging, match sites by chromosome and position in the same build and verify the allele pair and strand. Lift positions with a pinned chain when the builds differ. Exclude unresolved A/T and C/G sites, discordant allele pairs and duplicate positions, then record the remaining overlap. The public AADR samples and the local target should use consistent allele coding. Keep the sample and SNP manifests with those decisions. PLINK 1.9 import reference.
The fitting commands below start from a harmonized merged panel. Start R in the working directory where you will keep the population lists and results, with the panel prefix set in your shell.
export QPADM_PREFIX=/absolute/path/to/harmonized-panel
R --vanillaUse the .snp and .ind files to verify the recorded site count and unique individual IDs. In the annotation, inspect the population assignments and apply your roster rule for duplicate assays and relatives.
prefix <- Sys.getenv("QPADM_PREFIX")
stopifnot(nzchar(prefix))
files <- paste0(prefix, c(".geno", ".snp", ".ind"))
stopifnot(all(file.exists(files)))
ind <- read.table(files[3], col.names = c("sample_id", "sex", "population"))
snp <- read.table(files[2], stringsAsFactors = FALSE)
stopifnot(!anyDuplicated(ind$sample_id))
stopifnot(!anyDuplicated(snp[1]), !anyDuplicated(snp[c(2, 4)]))
print(table(ind$population))
print(nrow(snp))
print(tools::md5sum(files))When a person has two chip assays, we compare their fits as technical sensitivity checks on that individual. A merged view uses a documented rule for discordant calls and still represents the same individual. Report per-view overlap and review platform ascertainment when ancient capture data and consumer arrays contribute to the same estimate. The companion essay records the settings for its cross-platform comparisons.
3. Declare sources and references
Write one population label per line in target.txt, sources.txt and right.txt. Use exact labels from the analysis panel, including any alias mapping. Save the order, dates, relatedness exclusions and sample counts for each group. Record the fitted models, a minimum overlap appropriate to the design and the rule for comparing sensitivities before inspecting p-values.
read_set <- function(path) scan(path, what = character(), quiet = TRUE)
target <- read_set("target.txt")
sources <- read_set("sources.txt")
right <- read_set("right.txt")
alpha <- 0.05
stopifnot(length(target) == 1L, length(sources) >= 2L)
stopifnot(length(right) > length(sources))
stopifnot(!anyDuplicated(c(target, sources, right)))
stopifnot(all(c(target, sources, right) %in% ind$population))Choose rights for differential relatedness to the source lineages you want to distinguish. Examine alternative histories that would change the fitted contrasts, including gene flow between reference and source-related populations after their relevant splits. The ordered CORE12 manifest documents the fixed reference panel used by the July screen. The Andronovo comparison uses the same panel with ONG, Iran_GanjDareh_N and Russia_KrasnoyarskKrai_MLBA_Andronovo as sources.
A fixed-right comparison varies the sources and holds the references constant. In a rotating-right design, eligible candidates omitted from the source panel can enter the right set. That changes which population relationships are tested. We record both designs when comparing their results. Harney et al. (2021), base and rotating reference sets.
4. Extract and load SNP blocks
Prepare steppe-candidates.txt in the same directory with eligible replacements for the third source in the three-way South Asian example. The cache uses a fresh directory for each extraction. With maxmiss = 0, it retains SNPs with data in every selected population. A larger extraction panel can change which SNPs enter the cache even when the fitted left and right lists stay fixed.
stopifnot(length(sources) == 3L)
steppe_candidates <- unique(c(sources[3], read_set("steppe-candidates.txt")))
stopifnot(length(steppe_candidates) >= 2L)
stopifnot(all(steppe_candidates %in% ind$population))
stopifnot(!any(steppe_candidates %in% c(target, sources[1:2], right)))
analysis_pops <- unique(c(target, sources, right, steppe_candidates))
f2_dir <- tempfile("f2-", tmpdir = getwd())
extract_f2(
pref = prefix, outdir = f2_dir, pops = analysis_pops,
maxmiss = 0, blgsize = 0.05, auto_only = TRUE,
adjust_pseudohaploid = TRUE, afprod = TRUE, overwrite = FALSE
)
saveRDS(
list(populations = analysis_pops, maxmiss = 0, blgsize = 0.05,
auto_only = TRUE, adjust_pseudohaploid = TRUE, afprod = TRUE,
input_md5 = tools::md5sum(files)),
file.path(f2_dir, "extraction.rds")
)
product_blocks <- f2_from_precomp(f2_dir, pops = analysis_pops, afprod = TRUE)
distance_blocks <- f2_from_precomp(f2_dir, pops = analysis_pops, afprod = FALSE)
print(count_snps(product_blocks))Record the map and the block construction. In this version, blgsize = 0.05 uses a 5 cM block size when the input has genetic-map distances. The cached SNP count above is a summary of block-size labels. For genotype-direct fits with per-contrast SNP selection, report the counts for those contrasts when available.
The cache stores block summaries, including allele-frequency products when extraction requests them. Load the products with afprod = TRUE for qpAdm and f4. Load f2 distances with afprod = FALSE for admixture f3. The walkthrough's cache uses the declared complete-population filter. The companion study uses its separately recorded f2_rot21 cache. ADMIXTOOLS 2 extraction reference.
5. Check individual f-statistic contrasts
Before fitting, test whether the data separate the proxies on the axes under study. A significantly negative admixture f3 supports mixture in the target involving populations related to its two references. The example uses a diploid target. For pseudohaploid targets, document the heterozygosity and site filters used for f3. A focused f4 evaluates one difference in allele sharing. Specify the order of all four populations when you report its sign.
alternative <- setdiff(steppe_candidates, sources[3])[1]
f3_result <- f3(
distance_blocks, pop1 = target, pop2 = sources[1], pop3 = sources[3]
)
f4_result <- f4(
product_blocks, pop1 = right[1], pop2 = target,
pop3 = sources[3], pop4 = alternative
)
print(f3_result)
print(f4_result)Use at least two distinct proxies when evaluating separability. If two candidates have similar contrasts with wide uncertainty, the analysis has limited power to distinguish them on that axis. The July contrasts below give a measured example across two chip assays.
6. Fit, rotate and refit
Pass the source labels in left and the target separately. We inspect the unconstrained weights so estimates outside the interval from zero to one remain visible. The rank row at the number of sources minus one contains the full model p-value.
fit <- qpadm(
product_blocks, left = sources, right = right, target = target,
constrained = FALSE
)
rank <- length(sources) - 1L
model_test <- subset(fit$rankdrop, f4rank == rank)
stopifnot(nrow(model_test) == 1L)
print(model_test[c("f4rank", "dof", "chisq", "p", "p_nested")])
print(fit$weights)
print(fit$popdrop)In rankdrop, p tests the specified rank against the unrestricted alternative. The separate p_nested compares adjacent ranks within the same set of contrasts. In popdrop, a one in the pat string marks the omission of the source at that position. These subset results use the full fit's SNP basis. For a declared comparison across alternative source lists, refit each with the stated right set and SNP regime and record any change in available sites.
reduced_sources <- sources[1:2]
reduced <- qpadm(
product_blocks, left = reduced_sources, right = right, target = target
)
print(subset(reduced$rankdrop, f4rank == length(reduced_sources) - 1L))In the walkthrough's three-source screen, we hold the first two source proxies fixed and substitute candidates for the third. The fixed-right fits keep the same reference panel. The rotating-right fits add the unused Steppe candidates to it. Preserve each run's exact populations alongside its output.
fit_grid <- function(rotate_rights = FALSE) {
setNames(lapply(steppe_candidates, function(candidate) {
left_run <- c(sources[1:2], candidate)
right_run <- if (rotate_rights) {
c(right, setdiff(steppe_candidates, candidate))
} else {
right
}
list(
left = left_run,
right = right_run,
fit = tryCatch(
qpadm(product_blocks, left = left_run, right = right_run, target = target),
error = function(error) list(error = conditionMessage(error))
)
)
}), steppe_candidates)
}
fixed_grid <- fit_grid()
rotated_grid <- fit_grid(rotate_rights = TRUE)To compare site selection on the same harmonized genotype input, give qpAdm the genotype prefix. With allsnps = FALSE, it uses SNPs jointly available across the fitted populations. With allsnps = TRUE, each f4 uses SNPs available to its quartet. These two direct fits hold the genotype input and population lists fixed. The cache filters across the larger extraction panel, which also includes candidates omitted from the fit. ADMIXTOOLS 2 qpAdm reference.
fit_direct <- function(use_available_snps) {
qpadm(prefix, left = sources, right = right, target = target,
allsnps = use_available_snps, constrained = FALSE)
}
shared_fit <- fit_direct(FALSE)
available_fit <- fit_direct(TRUE)
print(subset(shared_fit$rankdrop, f4rank == rank))
print(subset(available_fit$rankdrop, f4rank == rank))7. Evaluate fit and feasibility
Apply the rank-test threshold to the chosen reference design, then evaluate whether the point estimates are feasible and precise enough to interpret. Record the two decisions for each fitted model.
| Check | Decision |
|---|---|
| Rank-test fit | Reject the stated model below the prespecified p-value threshold. Record the tested rank, statistic and degrees of freedom. |
| Feasibility | Flag unconstrained weights outside [0,1]. If uncertainty spans a boundary, report the estimate and evaluate a reduced or constrained fit as a separate analysis. |
| Precision | Inspect the block-jackknife standard errors and sensitivity to a change in reference panel or genomic block selection. |
| Chronology | Compare dates for literal ancestral candidates, and label younger related groups as proxies. |
| Sample roster | Record duplicate assays and close relatives, and compare results with one member omitted where appropriate. |
weights <- fit$weights
in_bounds <- all(is.finite(weights$weight)) &&
all(weights$weight >= 0 & weights$weight <= 1)
decision <- data.frame(
model_p = model_test$p,
passes_rank_threshold = is.finite(model_test$p) & model_test$p >= alpha,
feasible_point_estimates = in_bounds
)
print(decision)The full-CORE12 Srubnaya model in the companion analysis gives p = 0.546. Its unconstrained weight for the fourth source, Austria_N_LBK, is −5.5 ± 2.9 percentage points. We record the fit as compatible at the rank threshold and flag the coefficient as outside the feasible range. Archived four-source fit.
8. Interpret the fitted proportions
We use the block jackknife to estimate standard errors by recomputing the fit with one genomic block omitted at a time. These errors describe sampling variation across blocks conditional on the chosen proxies, references and genotype panel. Uncertainty in proxy choice or the archaeological interpretation needs separate comparisons.
Closely related proxies can support similar weights when the references separate their aggregate ancestry from the other sources. To distinguish candidates within that aggregate, we look for rights that relate differently to the candidates and check the relevant f4 contrasts. A weakly estimated fourth coefficient calls for an estimate of the design's resolving power on that axis.
Report the whole model grid with its dependence on data and reference choice. A grid shares samples and often shares most of its fitted populations. Specify the error criterion and any multiplicity correction in advance. With the same grid, a lower rejection threshold reduces false rejection at the cost of retaining more inadequate fits. Interpret the surviving panels using dates, alternative reference sets and uncertainty. Flegontova et al. (2025).
9. Save the analysis record
Keep all fitting results with the input metadata and frozen design. For each fit, record the target, the source and reference order, the genotype regime and reported overlap, the weights and standard errors, and the rank and subset tables. Retain the full grid with failures and record the criteria used to interpret its survivors.
dir.create("qp-results", showWarnings = FALSE)
write.csv(fit$weights, "qp-results/weights.csv", row.names = FALSE)
write.csv(fit$rankdrop, "qp-results/rankdrop.csv", row.names = FALSE)
write.csv(fit$popdrop, "qp-results/popdrop.csv", row.names = FALSE)
write.csv(decision, "qp-results/decision.csv", row.names = FALSE)
saveRDS(
list(fixed = fixed_grid, rotated = rotated_grid, reduced = reduced,
direct_shared = shared_fit, direct_available = available_fit),
"qp-results/grid.rds"
)
saveRDS(
list(target = target, left = sources, right = right, cache_dir = f2_dir,
alpha = alpha, maxmiss = 0, afprod = TRUE,
blgsize = 0.05, input_md5 = tools::md5sum(files)),
"qp-results/design.rds"
)
writeLines(capture.output(sessionInfo()), "qp-results/session.txt")For publication, prepare a separate aggregate receipt with the right and source manifests and cite the row that generated each reported number. Review exported tables and logs for personal identifiers and local paths.
Worked example with Andronovo
The companion analysis fits three proxies for one Punjabi genome, with Onge, Ganj Dareh Neolithic and Andronovo on the left and the full CORE12 on the right. Both reported fits use those populations in the same order. The runs use different genotype merges as well as different f-statistic regimes, so the two receipts measure sensitivity across the published workflows.
The cached afprod=TRUE fit estimates 42.8 ± 3.1% Andronovo-related ancestry and gives p = 0.060 at rank two.
The genotype-direct allsnps=TRUE fit estimates 43.4 ± 3.1% and gives p = 0.043 at the same rank.
| Source proxy | Cached fit | Direct fit |
|---|---|---|
| Onge | 24.0 ± 1.8 | 23.6 ± 1.7 |
| Ganj Dareh | 33.2 ± 3.5 | 33.0 ± 3.5 |
| Andronovo | 42.8 ± 3.1 | 43.4 ± 3.1 |
Evidence figure
Ancestry weights in the two Andronovo fits
The Andronovo weights differ by about 0.6 percentage points. With the prespecified threshold of 0.05, we retain the cached fit and reject the direct fit. The full-fit rank test uses nine degrees of freedom, with three sources and twelve references.
Evidence figure
The rank-test threshold for the Andronovo fits
The expanded source models in the companion essay use two reference configurations. The temporal European-farmer CSV uses CORE12 without Turkey_N. The raw European-farmer dumps use the full CORE12. Check the right list before comparing their rank tests or signed coefficients. Companion methodology · Temporal fit grid.
In a separate genotype-direct screen of the merged chip view, we counted each declared proxy pair once. With Mbuti as the reference, 29 of 528 within-Steppe pairs met the absolute Z threshold of 3, as did 422 of 627 comparisons between Steppe and farmer proxies. The counts apply to this target and proxy roster. Proxy roster and recount.
Evidence figure
Proxy contrasts in the larger f₄ screen
Primary references
- Maier et al. (2023) document ADMIXTOOLS 2 and the resolution of population-history models.
- Harney et al. (2021) assess qpAdm with simulations and provide a user guide.
- Flegontova et al. (2025) evaluate qpAdm screening under complex population histories.
- The Allen Ancient DNA Resource supplies the public genotype panels and annotations.