Skip to contents

Calculates tree-length and segregating-site moments under piecewise constant demography by numerically tracking the expected total branch length and its second moment through successive population-size epochs.

Usage

predictSegSitesMoments(n, Ne, bp, mutRate, histNe, histGen, tolerance = 1e-05)

Arguments

n

Number of sampled haplotypes (an integer of at least two). For outbred diploid individuals, use twice the number of individuals.

Ne

Current diploid effective population size.

bp

Length of the region in base pairs. Use 1 for a single base pair.

mutRate

Mutation rate per base pair per generation.

histNe

Historical diploid effective population sizes, ordered backward in time, as in runMacs2.

histGen

Increasing numbers of generations ago at which the sizes in histNe take effect. Must have the same length as histNe. The oldest size applies indefinitely. Set both historical vectors to numeric(0) or NULL for a constant population size.

tolerance

Positive numerical integration tolerance, smaller than 1. This controls local numerical error in the scaled first and second tree-length moments; it is not a guaranteed relative error bound on the returned variance. The default, 1e-5, favors speed. Lower this value for higher accuracy.

Value

A named list with four numeric components:

expectedTc

Mean total tree length over the region in generations (divide by \(2N_0\) to obtain coalescent units)

varianceTc

Variance of total tree length over the region in generations squared (divide by \((2N_0)^2\) to obtain squared coalescent units)

expectedS

Mean number of segregating sites in the region

varianceS

Variance of the number of segregating sites in the region

Similar approaches can be used to calculate moments of other summary statistics under the same demographic model, including pairwise nucleotide diversity and the allele frequency spectrum. These extensions require additional development.

Details

Theory for segregating-site counts under piecewise constant demography is described in (Živković and Wiehe 2008) . This function implements and extends the theory by approximately solving differential equations of how the first and second moments of total tree length change over time under a piecewise constant population size model. First and second tree-length moments are calculated numerically from backward coalescent reward equations, including covariance between lineage waiting times.

Total tree length \(T_c\) is the sum of branch lengths over all sampled lineages until their most recent common ancestor. With the moments of total tree length, the expected number of segregating sites are calculated using \(E(S) = (\theta/2) E(T_c)\) and \(Var(S) = E(S) + (\theta^2/4)Var(T_c)\), where \(\theta = 4 N_0 \mu L\), with \(\mu\) mutation rate per base pair per generation, \(N_0\) present-time effective population size, and \(L\) the length of the region in base pairs. In these identities, \(T_c\) is in coalescent units (time in units of \(2N_0\) generations).

These results follow from Poisson mutation counts conditional on tree length under an infinite-sites model with a single genealogy of the genome region. Recombination changes the variance by averaging correlated genealogies along the region, but not the expected site count under the same demography. The returned variance assumes no recombination and should not be used as the chromosome variance for simulations with recombination.

References

Živković D, Wiehe T (2008). “Second-Order Moments of Segregating Sites Under Variable Population Size.” Genetics, 180(1), 341–357. doi:10.1534/genetics.108.091231 .

Examples

# GENERIC demographic model, with the same defaults as runMacs2()
predictSegSitesMoments(n=20, Ne=100, bp=1e8, mutRate=1e-8,
  histNe=c(500,1500,6000,12000,100000),
  histGen=c(100,1000,10000,100000,1000000))
#> $expectedTc
#> [1] 7382.598
#> 
#> $varianceTc
#> [1] 92450442
#> 
#> $expectedS
#> [1] 7382.598
#> 
#> $varianceS
#> [1] 92457824
#> 

# Constant population size
predictSegSitesMoments(n=20, Ne=100, bp=1e8, mutRate=1e-8,
  histNe=numeric(0), histGen=numeric(0))
#> $expectedTc
#> [1] 1419.096
#> 
#> $varianceTc
#> [1] 254986.1
#> 
#> $expectedS
#> [1] 1419.096
#> 
#> $varianceS
#> [1] 256405.2
#>