Methods
Twigstats
Twigstats takes the Relate32 output format as input and allows the 
computation of f -statistics directly on genealogies, by using the 
inferred expected number of mutations on each branch as input, 
which is computed as the product of a prespecified average muta -
tion rate per base per generation, the branch length and the num -
ber of bases each tree persists 43. Importantly, Twigstats computes 
f2-statistics ascertained by an upper date threshold, such that only 
branches younger than this threshold are used. If a branch crosses 
the threshold, we use only the proportion of the branch under -
neath the threshold. Twigstats additionally enables us to specify a 
minimum derived allele frequency and lower date threshold. Twig-
stats can also compute f 2-statistics on age-ascertained mutations, 
which is particularly convenient for individuals not built into the  
genealogies.
The computed f2-statistics are fed into ADMIXTOOLS270 to com-
pute derived statistics. ADMIXTOOLS2 implements computation of 
genome-wide f2-, f3- and f4-statistics, as well as qpgraph and qpAdm 
models. We implement the sample size correction as detailed in ref. 21.  
The f2-statistics are computed in blocks, typically of prespecified cen-
timorgan size or of prespecified physical distance. These blocks are 
used downstream in ADMIXTOOLS2 to compute standard errors using 
a block-jackknife approach. By default, we compute f-statistics only 
on internal branches and exclude singleton tip branches to increase 
robustness against sample age.
The optimal Twigstats time cut-off is a priori unknown; however, we 
develop a theory that predicts the optimal choice in a simple two-way 
admixture as a function of the admixture date, source split time and 
admixture proportion (Supplementary Note). In this case, the optimal 
cut-off equals approximately 1.4 times the split time between admixing 
source groups, depending on exact parameters in the model (Fig. 1b,c 
and Extended Data Fig. 2).
Non-negative least squares ancestry modelling. We implement 
an approach that uses genealogies to emulate the chromosome 
painting technique of identifying closest genetic relatives along the  
genome1,2 to fit admixture weights. When applied to true genea-
logies in simulations, this approach represents an idealized version of  
this idea.
We implement this function in Twigstats, which, given known assign-
ment of each sample to a population, identifies, at each position in 
the genome, the population with which a sample coalesces first. Our 
implementation takes a list of reference populations as input, such 
that any coalescences that do not involve these reference populations 
are ignored when traversing back in time through genealogical trees. 
If the first coalescence involves multiple different reference popula-
tions, this coalescence event will be assigned to each population with 
a weight proportional to the number of samples in each population 
involved in that event.
We then implement a second function in Twigstats to compute, for 
each target population and putative source populations, the propor-
tion of the genome ‘painted’ by each of the reference populations. 
Given k reference populations, we denote by ai the vector of length k 
storing these proportions for population i. We fitted our target popu-
lation as a mixture of putative source populations using a non-negative 
least squares approach that finds a solution to the optimization prob-
lem min || −| |Σ0≤ ≤1 target 2aA ββ/uni2113 , where A is a matrix storing /uni2113a  for puta-
tive source populations as its column vectors with /uni2113 indexing source 
populations and β are non-negative mixture weights.
Admixture simulations. We use msprime71 to simulate genetic vari-
ation data to test our approach. All simulation scripts are available at 
https://github.com/leospeidel/twigstats_paper.
f4-ratio admixture simulation. Our simulation in Fig. 1b and Extended