Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Population Size and History from Present-Day DNA

Can DNA sampled today distinguish a founder event from recent growth? We generate one population with mutation, recombination and changing size. The simulator records each generation. Estimators receive the final DNA, an external mutation rate and a genetic map.

Diversity, LD and IBD give constant-size summaries. We compare specified demographic histories and check their predictions on reserved chromosomes. The simulation uses small population sizes and elevated rates so that its probability model can be inspected directly. Install hpgR before running.

Start with the final DNA from a simulated founding and expansion. Estimate effective size and compare candidate histories using 64 diploid people across eight chromosomes. The next two notebooks use smaller subsets of these same sequences to study ancestry and the frequency spectrum.

The final sample and its calibration

The saved forward sample contains 64 diploid people, represented by 128 haploid sequences, across eight chromosomes of 10,000 sites each. Every site, including invariant sites, is included. Consecutive haplotype rows are the two homologs of one person. Alleles are coded 0 and 1.

Each chromosome spans 0.2 Morgans. The mutation probability is u=v=2.5×10−5u=v=2.5\times10^{-5} per site per generation for both 0-to-1 and 1-to-0 changes. Recurrent and reverse mutation are possible, so the frequency spectrum uses minor allele counts. Allele 1 is simply a sequence state.

Keep the three RDS files at their paths under data/population_history/.

observed contains the final DNA. calibration contains the mutation rate and map. prediction_data contains independent R simulation predictions for candidate histories. It contains no generation records from the observed sample.

Source

Run the forward model

Begin with 100 diploid individuals carrying allele 0 at every site. Mutation and reproduction run for 1,000 ancestral generations before the founder sample is taken. This burn-in lets diversity build and fluctuate near its mutation-drift equilibrium.

Then sample 20 founders, keep the population at 20 for 20 generations, and expand exponentially to 1,000 over 40 generations. Every generation uses the R-translated simuPOP operators in the same order.

  1. Each parental allele flips with probability u=vu=v.

  2. Each gamete chooses a parental diploid uniformly, with replacement.

  3. The gamete switches between that parent’s homologs at the supplied recombination fractions. Different chromosomes assort independently.

  4. Two gametes form each offspring. Selfing is allowed in this neutral Wright-Fisher model.

For adjacent sites separated by dd Morgans, the switch probability is r=(1−e−2d)/2r=(1-e^{-2d})/2. hpgR implements mutation and transmission in R; the notebook specifies the demographic schedule.

At one site, the copying step has the marginal probability model Kℓ,g+1∣p~ℓ,g∼Binomial⁡(2Ng+1,p~ℓ,g)K_{\ell,g+1}\mid\widetilde p_{\ell,g}\sim \operatorname{Binomial}(2N_{g+1},\widetilde p_{\ell,g}), where p~ℓ,g\widetilde p_{\ell,g} is the frequency after parental mutation. Recombination determines which neighboring sites travel in the same gamete.

The R simulation reproduced the supplied final sample.
plot without title

The dashed line marks the low-mutation approximation 4N0u=0.014N_0u=0.01. The next plots show population records for this realization. Founder sampling can change frequencies immediately; new mutations add variation during growth. The two values at generation 0 show the population before and after the instantaneous founder sample.

plot without title

Analyze only the final DNA

From here onward the estimation functions use observed, calibration and the candidate prediction banks. They do not receive simulation, parental identities, recorded frequencies or the generating sizes.

The matrix displays the first 12 haplotypes at 12 common polymorphic sites on chromosome 1. Labels give physical positions in bases. The complete analysis uses all 80,000 sites and all 128 haplotypes.

 diploid_people haplotypes analyzed_sites segregating_sites pairwise_diversity
             64        128          80000              5152          0.0073229
plot without title

Diversity counts differences between pairs of sequences. The folded SFS counts sites at each minor allele count, from 1 through 64 among 128 copies. The chromosomes differ because they have different realized copying and recombination histories. They remain parts of the same sampled population.

plot without title

SNP discovery in the same chromosome

Use all variants in H1–H12, then keep only variants that differ between H1 and H2. This changes the observed SFS without changing the sampled people or population. The red prediction uses the generating size schedule; its infinite-sites expectation approximates the recurrent forward mutation model.

       all_variants discovered_variants 
                276                  75 
plot without title

Estimate effective size using diversity and mutation rate

Apply the mutation-drift relation from Lecture 8 to the final DNA. If kℓk_\ell of the n=128n=128 sampled copies carry allele 1, then

H^=1L∑ℓ2kℓ(n−kℓ)n(n−1),N^e,H=H^4u.\widehat H=\frac{1}{L}\sum_\ell \frac{2k_\ell(n-k_\ell)}{n(n-1)},\qquad \widehat N_{e,H}=\frac{\widehat H}{4u}.

Here L=80,000L=80{,}000 includes invariant sites. The inverse assumes a neutral, constant-size population and rare mutation. With changing population size, it summarizes accumulated ancestral time; it need not equal today’s census.

 pairwise_diversity mutation_rate Ne_rare_mutation Ne_symmetric_mutation
         0.00732294       2.5e-05          73.2294               74.8197
plot without title

The symmetric-mutation correction gives 74.8, compared with 73.2 from the rare-mutation relation. Both invert constant-size equilibrium models. Population size changed during this example.

The box and points show chromosome-specific estimates within this one sample. They show regional variation; they are not independent population replicates or a confidence interval for the pooled estimate. Red labels give the generating sizes, which are withheld from estimation.

Estimate effective size using LD and recombination

Use one fixed chromosome copy from each of the same 64 people, giving n=64n=64 known-phase haplotypes. At sites A,BA,B, let XA,XB∈{0,1}X_A,X_B\in\{0,1\} indicate allele 1 on the same haplotype. Their correlation is ρAB=Corr⁡(XA,XB)\rho_{AB}=\operatorname{Corr}(X_A,X_B); its square measures LD.

The neutral constant-size, weak-LD model from Lecture 8 separates population LD from the additional contribution of study sampling:

E ⁣(ρAB 2^)≈γ(r)Ne+1n,γ(r)=(1−r)2+r22r(2−r).E\!\left(\widehat{\rho_{AB}^{\,2}}\right) \approx\frac{\gamma(r)}{N_e}+\frac{1}{n},\qquad \gamma(r)=\frac{(1-r)^2+r^2}{2r(2-r)}.

Finite sampling makes the observed squared correlation positive on average even when the population correlation is zero. Here the approximate sampling contribution is 1/64=0.0156251/64=0.015625. Subtract it before estimating effective size:

m^=ρAB 2^‾−1n,N^e,LD≈γ(r)‾m^.\widehat m=\overline{\widehat{\rho_{AB}^{\,2}}}-\frac{1}{n},\qquad \widehat N_{e,\mathrm{LD}}\approx\frac{\overline{\gamma(r)}}{\widehat m}.

m^\widehat m estimates mean population squared LD. Bars average over the same selected SNP pairs, whose recombination fractions can differ.

Each simulated chromosome spans 0.20 Morgans. We choose a lower pair-distance cutoff of 0.03 Morgans to exclude the tightest pairs, where strong LD can make the approximation inaccurate. These are pairwise separations of 3–20 cM. Require sample minor-allele frequency at least 0.10 to reduce rare-allele bias. For Poisson crossovers, the map converts pair distance dd to the recombination fraction r=(1−e−2d)/2r=(1-e^{-2d})/2.

The sample correction is approximate for this finite, paired-diploid population sample. Population simulations below use the same sampling design when calibrating predictions.

 lowerMorgan upperMorgan pairs  meanRho2 correctedRho2      Ne
        0.03        0.07 19111 0.0384455    0.02282047 232.198
        0.07        0.12 16267 0.0203700    0.00474498 560.981
        0.12        0.20 10085 0.0189476    0.00332265 501.337
Pooled LD estimate: 295.1 
plot without title

The 45,463 selected within-chromosome SNP pairs give

N^e,LD≈γ(r)‾ρAB 2^‾−1/64=3.549390.0276527−1/64≈295.\widehat N_{e,\mathrm{LD}}\approx \frac{\overline{\gamma(r)}}{\overline{\widehat{\rho_{AB}^{\,2}}}-1/64} =\frac{3.54939}{0.0276527-1/64} \approx295.

The function samples at most 500,000 candidate SNP pairs before restricting them to the same chromosome and the chosen distance range. Each selected pair contributes once to both means. Bin-specific inverses apply the same approximation to different distances. They are not estimates for distinct historical epochs. Linked pairs share sites and chromosomes.

Estimate effective size using IBD lengths

Use the same fixed haplotype from each of 64 people. Match common markers (minor-allele frequency at least 0.10), and analyze matches at least 8 cM long. The expanded marker panel reduces chance long matches. Phase is known and the simulation has no genotyping error.

For bin bb, sum matching segment lengths and divide by the total analyzed map length G=160G=160 cM and the number of compared haplotype pairs P=(642)P=\binom{64}{2}:

f^b=∑s: ℓs∈bℓsPG.\widehat f_b=\frac{\sum_{s:\,\ell_s\in b}\ell_s}{P G}.

As previously discussed, predict these fractions from inheritance and recombination. Here we restrict that model to a constant size NN:

N^e,IBD=arg⁡min⁡N∑b[log⁡f^b−log⁡fb(N)]2.\widehat N_{e,\mathrm{IBD}}=\arg\min_N\sum_b [\log\widehat f_b-\log f_b(N)]^2.

expectedIbdLength() translates the finite-chromosome expectation from Dan Nachun’s demographyTools. estimateIbdSize() uses the positive-bin criterion described by Carmi et al. (2014). It fits a constant-size summary, rather than a free size trajectory.

 lowerCm upperCm count sharedCm    fraction
       8      10   543 4849.081 0.015033113
      10      14   297 3344.362 0.010368187
      14     Inf    97 1635.964 0.005071812
Constant-size IBD fit: 164.1 
plot without title

The expanded DNA panel gives 937 matches of at least 8 cM and a constant-size fit of approximately 164. The observed length distribution and the constant-size prediction have different shapes. The next comparison lets population size vary through time.

In a separate validation replay, about 97.7% of matched length had the same recorded founder-copy label. Independently shuffling each marker preserved allele counts and produced no matches of at least 8 cM in that control. These checks support the chosen matching threshold. They do not establish perfect segment boundaries or eliminate mutation and chance-matching error.

Check the constant-size assumption

Change the length threshold and binning while using the same detected segments. The fitted scalar can change because different lengths weight different ancestral generations. A changing history also changes the shape of the length distribution, as the observed-versus-fitted plot shows.

         length_bins     Ne
 8-10, 10-14, 14+ cM 164.14
        8-14, 14+ cM 205.22
       10-14, 14+ cM 234.80
       12-14, 14+ cM 309.05
               method estimate
 Diversity + mutation  73.2294
   LD + recombination 295.1005
          IBD lengths 164.1379
Plot with title “Same final DNA”

The same DNA gives different constant-size summaries: diversity 73.2, LD 295, and IBD lengths 164. Each calculation inverts a different relationship under a constant-size model. With changing size, the estimators weight ancestral generations differently and also respond to sampling, marker selection and approximation error. None identifies one historical date.

The founder event leaves many variants on 40 chromosome copies. During the 40 generations of expansion, new mutations continue to arise. Recorded population diversity rises from 0.006544 to 0.007288, while the number of variable sites rises from 1,756 to 13,138. Rare new variants contribute little to pairwise diversity. Growth reduces drift loss immediately; a new diversity equilibrium takes much longer.

plot without title

Estimate ancestral size when the recent history is known

Suppose independent information specifies the entire recent size trajectory: 20 founders, 20 generations at size 20, then 40 generations of growth to 1,000. Only the constant ancestral effective size is unknown. The mutation rate is also known. This is a different inference problem from the constant-size summaries above.

For the symmetric parental-mutation model, write a=2μ(1−μ)a=2\mu(1-\mu) and b=(1−2μ)2b=(1-2\mu)^2. Iterating the forward diversity recurrence gives

E(Hnow)=A+BHanc,At+1=(1−12Nt)(a+bAt),Bt+1=(1−12Nt)bBt,E(H_{\mathrm{now}})=A+B H_{\mathrm{anc}},\qquad A_{t+1}=\left(1-\frac{1}{2N_t}\right)(a+bA_t),\quad B_{t+1}=\left(1-\frac{1}{2N_t}\right)bB_t,

starting at A0=0,B0=1A_0=0,B_0=1. Here NtN_t is the known parental size. AA is the contribution of recent mutations; BB is the weight on ancestral diversity. A random founder sample without replacement preserves expected pairwise diversity under this exchangeable-copy model; it changes realized frequencies. Recombination affects variability among sites, rather than this one-site mean.

Invert the mean relation using the observed diversity:

H^anc=H^now−AB.\widehat H_{\mathrm{anc}}=\frac{\widehat H_{\mathrm{now}}-A}{B}.

If the ancestor was at mutation-drift equilibrium, then

N^e,anc=a+bH^anc2a(1−2H^anc).\widehat N_{e,\mathrm{anc}}= \frac{a+b\widehat H_{\mathrm{anc}}} {2a(1-2\widehat H_{\mathrm{anc}})}.

This is an estimate conditional on the supplied recent history. Event dates alone would leave the intervening sizes unknown.

  observed_H recent_mutation_A ancestral_weight_B inferred_ancestral_H equilibrium_ancestral_Ne
 0.007322944       0.002466508           0.459924           0.01055921                 108.3729
 finite_burnin_ancestral_Ne
                   109.4045
plot without title

The conditional estimate is about 108, compared with the generating ancestral size of 100. The observed population and DNA sample fluctuate around the forward expectation. Accounting for the actual 1,000-generation ancestral run from identical sequences gives about 109.

The earlier diversity estimate of 73 summarized the whole changing history under a constant-size equilibrium model. The new estimate concerns the ancestor after fixing the complete recent trajectory. Neither calculation recovers an unrestricted size at every generation from one diversity value. Next, relax the supplied recent history and compare explicit alternatives.

Compare explicit population histories

All candidates begin at 100, end at 1,000, and use the same mutation rate, map, sequence length and sampling design. The plot shows the 120 generations before the final sample at time 0.

  • The recent founder events occur 60 generations before sampling. Population size stays at 20 or 40 until 40 generations before sampling, then expands.

  • The older event occurs 100 generations before sampling. Population size stays at 20 until 80 generations before sampling, then expands for 80 generations.

These are competing hypotheses for one sample, not additional example populations. We compare which declared trajectory predicts the sample best; the comparison does not estimate arbitrary founder numbers or dates.

plot without title

Fit with chromosomes 1-6 and reserve chromosomes 7-8 for a predictive check. For each candidate history, 40 independent forward simulations predict seven SFS groups, six LD-distance bins and three IBD-length bins. Another 40 simulations per history test whether the comparison identifies their known histories. These 320 seeds differ from the observation seed.

Dots in the next plots show prediction means. Intervals show the central 90% of simulated datasets; black horizontal marks show the observed DNA.

Standardized Euclidean distance

Let xbx_b be observed summary bb, and mb(η)m_b(\eta) its predicted mean under history η\eta. Divide each difference by its simulation standard deviation:

d(η)=∑b=116[xb−mb(η)sb]2.d(\eta)=\sqrt{\sum_{b=1}^{16} \left[\frac{x_b-m_b(\eta)}{s_b}\right]^2}.

The common sb2s_b^2 is the average of the four within-history simulation variances. Use the same summaries and scales for every candidate, then choose the smallest distance. This is a choice of comparison rule; its accuracy is measured with independent simulations whose generating histories are known.

plot without title
plot without title
plot without title
          history distance
 shallow_founding   5.7323
  recent_founding   5.9100
   older_founding  14.0624
   expansion_only  15.8253
                  selected
generating         expansion_only shallow_founding recent_founding older_founding
  expansion_only               40                0               0              0
  shallow_founding              0               40               0              0
  recent_founding               0                2              38              0
  older_founding                0                0               0             40
          history correct validation_datasets accuracy lower95 upper95
   expansion_only      40                  40     1.00  0.9119  1.0000
 shallow_founding      40                  40     1.00  0.9119  1.0000
  recent_founding      38                  40     0.95  0.8308  0.9939
   older_founding      40                  40     1.00  0.9119  1.0000
Correct histories: 158 of 160 (98.75%)
plot without title

Among the 160 independent validation populations, the rule identifies 158 generating histories correctly (98.75%). Two of the 40 datasets generated with 20 founders are assigned to the 40-founder history. The per-history binomial intervals show the uncertainty from using 40 validation datasets. These rates apply to these four specified histories and this observation design.

The classroom DNA is close to that same boundary: its distances are 5.73 for 40 founders and 5.91 for 20 founders. Both candidates go forward to the reserved chromosomes. A distance measures closeness to a predicted mean; the validation counts measure how often this rule identifies a generating history.

        candidate distance
 shallow_founding   6.7837
  recent_founding   4.0877
Plot with title “Reserved (7-8)”

The means predicted by 40 founders are slightly closer on chromosomes 1-6. The reserved chromosomes are closer to the 20-founder prediction (4.09 versus 6.78). These are comparisons of this one sample with fixed candidate histories. The independent validation above measures the rule’s identification accuracy.

The simulations preserve the shared pedigree across chromosomes. Reserved chromosomes provide additional genetic information within that pedigree.

What if the historical parameters are unknown?

Forward models can estimate historical parameters as well as compare fixed candidates. Pritchard, Section 3.3, describes computing expected SFS probabilities by simulation or diffusion theory and fitting them to the observed spectrum. Gutenkunst et al. (2009) provide a forward-diffusion example with a composite likelihood. Linkage affects the uncertainty and must be accounted for when assessing the fit.

Additional summaries and historical constraints can identify more parameters, subject to the information in the data. The coalescent model organizes the same inference through the ancestors of sampled copies. It gives another tractable representation of the process; identifying a unique history still requires assumptions and informative data.

Read the final sample’s results together

The same DNA gives constant-size summaries of about 73 from diversity, 295 from LD and 164 from IBD lengths. These summarize different features of a history whose size changed.

The candidate comparison uses standardized Euclidean distance. In independent validation, it identifies 158 of 160 generating histories; two 20-founder populations are assigned to 40 founders. Those are the two close candidates for the classroom sample as well. Reserved chromosomes are closer to the 20-founder prediction. The validation rate describes recovery among the four specified histories under the chosen rates, map and observation design.

Plot with title “Same final DNA”

Rebuild the cache

The observations and all prediction/calibration replicates use hpgR’s R functions with the recorded design and seeds. From the package source:

system2("Rscript", c("tools/rebuild_population_cache.R", "/path/to/cache", "4"))

The saved inputs let you run the estimates without rebuilding the prediction library.

Sources

Pritchard, Sections 2.1-2.3 and 3.3; Peng et al. (2012), Forward-Time Population Genetics Simulations; Hill (1981); Handbook of Statistical Genomics, Section 16.2.2; Carmi et al. (2014); Browning and Browning (2015).

IBD matching and length expectations are translated from Daniel Nachun’s supplied demographyTools. Simulation and inference interfaces are documented in hpgR.

Beaumont et al. (2002), simulation-based comparison of standardized summaries; Csilléry et al., independent model-recovery checks in the abc documentation. Here candidates are compared by distance to their simulated means; no ABC posterior is computed.

Gutenkunst et al. (2009), forward-diffusion demographic inference.