Skip to main content
Molecular Biology and Evolution logoLink to Molecular Biology and Evolution
. 2016 Aug 22;33(11):3002–3027. doi: 10.1093/molbev/msw173

The Effects of Population Size Histories on Estimates of Selection Coefficients from Time-Series Genetic Data

Ethan M Jewett 1,2, Matthias Steinrücken 3, Yun S Song 1,2,4,5,6,*
PMCID: PMC5062326  PMID: 27550904

Abstract

Many approaches have been developed for inferring selection coefficients from time series data while accounting for genetic drift. These approaches have been motivated by the intuition that properly accounting for the population size history can significantly improve estimates of selective strengths. However, the improvement in inference accuracy that can be attained by modeling drift has not been characterized. Here, by comparing maximum likelihood estimates of selection coefficients that account for the true population size history with estimates that ignore drift by assuming allele frequencies evolve deterministically in a population of infinite size, we address the following questions: how much can modeling the population size history improve estimates of selection coefficients? How much can mis-inferred population sizes hurt inferences of selection coefficients? We conduct our analysis under the discrete Wright–Fisher model by deriving the exact probability of an allele frequency trajectory in a population of time-varying size and we replicate our results under the diffusion model. For both models, we find that ignoring drift leads to estimates of selection coefficients that are nearly as accurate as estimates that account for the true population history, even when population sizes are small and drift is high. This result is of interest because inference methods that ignore drift are widely used in evolutionary studies and can be many orders of magnitude faster than methods that account for population sizes.

Keywords: selection, inference, time series, diffusion, Wright–Fisher

Introduction

Methods for inferring the selection coefficient at a single genetic locus from time series data have been employed extensively in evolutionary studies of simple traits. Such methods track the frequency of an allele or Mendelian trait over multiple generations and infer the selection coefficient that best explains the observed frequency changes. Studies of selective pressures conducted using time series approaches have provided evidence for selective forces in natural populations and have helped to characterize the ways in which environmental factors influence evolution through selection (Fisher and Ford 1947; Clarke and Murray 1962; Wall et al. 1980; Lynch 1987; Stine and Smith 1990; Goudsmit et al. 1996; Harrigan et al. 1998; Cook et al. 1999; Haubruge and Arnaud 2001; Bonhoeffer et al. 2002; Reimchen and Nosil 2002; Cook et al. 2005; Labbé et al. 2009).

Because random fluctuations in allele frequencies due to genetic drift are often small compared with changes due to selective pressures, it is common practice for studies to assume that allele frequencies change deterministically over time as they would in a population of infinite size according to well-known deterministic formulas of (Fisher 1922, p. 424) and (Haldane 1927, p. 840) or related expressions (Gillespie 1998; Hartl and Clark 2007). However, because allele frequency trajectories can be heavily influenced by genetic drift when population sizes or selection coefficients are small, many methods have been developed to account for drift by explicitly modeling finite population sizes when inferring selection coefficients from observed allele frequency trajectories (Manly 1985; O’Hara 2005; Bollback et al. 2008; Malaspinas et al. 2012; Mathieson and McVean 2013; Lacerda and Seoighe 2014; Steinrücken et al. 2014; Foll et al. 2015; Ferrer-Admetlla et al. 2015; Schraiber et al. 2016) and when testing hypotheses about selection versus drift (Fisher and Ford 1947; Schaffer et al. 1977; Wilson 1980; Nishino 2013; Feder et al. 2014).

Although it is commonly assumed that estimates of selection coefficients are likely to be improved by accounting for population size histories, the expected amount of improvement is not well characterized. Even in relatively small populations, allele frequencies and other evolutionary processes behave almost deterministically if the selection coefficient or allele frequency is sufficiently high (Rouzine et al. 2001), suggesting that methods that ignore drift might perform well under these conditions. Conversely, if drift is strong allele frequency trajectories can be noisy and the accuracy of methods that ignore drift may be comparable to that of methods that account for population size, as all methods are likely to perform poorly under these conditions (Gallet et al. 2012).

If computationally fast methods that ignore drift are accurate, they could dramatically reduce the time required to infer selection coefficients in data sets with many loci. In addition to their computational efficiency, methods that ignore drift by assuming that the population size is infinite do not require estimates of effective population sizes, which can be difficult to obtain accurately. Moreover, ignoring drift can lead to simple formulas and inference procedures under complicated scenarios involving multiple populations with migration or multiple loci with recombination (Illingworth et al. 2012). Therefore, in light of the beneficial properties of methods that ignore drift and assume deterministic allele frequency trajectories, it is of interest to compare their accuracy to that of methods that account for population size histories.

The theoretical accuracy of methods for inferring selection coefficients can be difficult to derive analytically. Thus, to explore differences between methods that ignore or account for drift, one can take the approach of empirically comparing inferences made by estimators that either account for the true population size history or ignore the size history by assuming that populations are large and drift is negligible. This is the approach we take here. For our analyses, we consider maximum likelihood estimators of selection coefficients because they are typically quite accurate and have desirable statistical properties. Moreover, the majority of recently developed methods for inferring selection coefficients from time series data are maximum likelihood estimators, making them an important category of methods to evaluate.

To draw conclusions about the accuracy of maximum likelihood estimators, it is important to consider estimators based on exact likelihoods rather than approximations, so that differences in estimates can be attributed entirely to whether a method ignores or accounts for drift. Although several approximate approaches have been developed for computing the likelihood of a selection model given time series allele frequency data, only three existing methods compute probabilities that are exact under a widely accepted model. In particular, the methods of Bollback et al. (2008) and Steinrücken et al. (2014) compute exact probabilities under the diffusion approximation of the Wright–Fisher process. However, these methods do not model time-varying population size histories. The third inference method based on an exact likelihood considers time-varying population size histories under the diffusion approximation of the Wright–Fisher process (Schraiber et al. 2016); however, it uses an MCMC algorithm to perform Bayesian inference that is not easily incorporated into a unified inference algorithm that allows us to directly compare inferences made by estimators that model the true population history with those that assume a population of infinite size without drift. No existing method computes the exact probability of an allele frequency trajectory under the discrete Wright–Fisher model, as the matrix powers required for such a method are considered to be computationally inefficient.

Here, we derive the exact probability of an allele frequency trajectory in a population of piecewise constant size under two classical models: the discrete Wright–Fisher model and the diffusion approximation of the Wright–Fisher process. We then use maximum likelihood estimators obtained using these probabilities to explore how ignoring or accounting for the true population history affects estimates of selection coefficients.

Our results are useful for understanding when point estimates obtained using estimators based on deterministic allele frequency trajectories are likely to be accurate and when accounting for the true population history could improve these estimates. Our results have implications for the interpretation of existing estimates of selection coefficients and for the use of deterministic estimators in future studies. The results can also help guide the development of demography-aware estimators of selection coefficients by identifying scenarios under which such estimators are likely to improve inference accuracy.

Results

To compare the performance of estimators that ignore or account for drift, we inferred selection coefficients from allele frequency trajectories simulated under a variety of population histories of time-varying size.

The Population Model

In all of our analyses, we considered a single biallelic locus with alleles labeled a and A evolving under selection and recurrent mutation in a panmictic population comprised of L different epochs =1,,L, each with constant size N diploid individuals (fig. 1). Epoch ℓ corresponds to the time interval [τ1,τ], where time is measured continuously in units of generations and we define τ00. By varying the population sizes N across epochs, it is possible to model a variety of size-change patterns including exponential growth, bottlenecks, and rapidly oscillating population sizes.

Fig. 1.

Fig. 1.

Diagram of the model. An allele at a single locus evolves in a population of piecewise constant size with L=5 epochs spanning the time periods [τ0,τ1],,[τL1,τL], where τ00. Samples of sizes n1,,nk haplotypes are taken at times t1,,tK.

Within epoch , all mutation and selection parameters are assumed to be constant. In particular, we assume that the per-generation probability that allele a mutates to allele A is uaA() and the per-generation probability that allele A to a is uAa(). The three possible genotypes, aa, aA, and AA, have relative fitnesses given by wAA()=1+s,waA()=1+hs, and waa()=1 in epoch , where s is the selection coefficient and h is the dominance parameter.

We denote the collection of model parameters in epoch by Θ and the set of parameters across all epochs by Θ. It will also be convenient to denote the value of the model parameters at time t by Nt, uaA(t),uAa(t), st, and ht, where t is measured continuously in units of generations. The epoch in which time t lies will be denoted by t and the epoch in which sampling event k lies will be denoted by k. It will be clear from the context whether the subscript on refers to a time or a sampling event.

We denote the population-wide number of copies of allele A in generation t by ct and the population-wide frequency of allele A by yt. In practice, we do not observe the true population count of allele A. Instead, the data consist of observed counts o1,,oK of the number of times allele A is observed in K different samples of sizes n1,,nK haplotypes, taken at times t1<<tK. For simplicity, we assume that each sampling time tk is an integer for k=1,,K. The consecutive observed counts (ok,ok+1,,ok) will be denoted by o[k:k].

In general, we will denote random variables corresponding to observed quantities using capital letters (e.g., Ok, Ct, and Yt). The goal is to compute the probability PΘ{O[1:K]=o[1:K]} of the observed data, conditional on the model parameters Θ.

Probabilities of Frequency Trajectories

Several different evolutionary models can be used to describe stochastic allele frequency changes over time in a population. Discrete changes in allele frequency are often modeled using the Wright–Fisher and Moran processes, whereas continuous changes are often modeled using the diffusion approximation of the Wright–Fisher process (Karlin and Taylor 1981; Ewens 2004; Wakeley 2008) or one of several approximations of the diffusion (Feder et al. 2014; Lacerda and Seoighe 2014).

Because it is unclear which model provides the most accurate description of biological evolutionary processes, we take the approach in this paper of deriving exact probabilities of allele frequency trajectories under two different evolutionary models: the discrete Wright–Fisher process and the continuous diffusion approximation.

Under the Wright–Fisher model, the probability PΘ,W{O[1:K]=o[1:K]} of the observed allele counts can be obtained using the recursive formula presented in Procedure 1. Under the diffusion approximation, the probability PΘ,D{O[1:K]=o[1:K]} can be obtained using the recursive formula presented in Procedure 2.

In the “Deterministic allele frequency trajectories under the Wright–Fisher model” and “Deterministic allele frequency trajectories under the diffusion model” sections, we show that if drift is ignored and allele frequencies evolve deterministically, then the probabilities PΘ,W{O[1:K]=o[1:K]} and PΘ,D{O[1:K]=o[1:K]} can be reduced to the simpler approximate probabilities PΘ,W{O[1:K]=o[1:K]} and PΘ,D{O[1:K]=o[1:K]} which ignore the population history and which are computed using Procedures 3 and 4, respectively.

Different estimates of the model parameters Θ can be obtained using each of the different probabilities PΘ,W{O[1:K]=o[1:K]},PΘ,D{O[1:K]=o[1:K]},PΘ,W{O[1:K]=o[1:K]}, and PΘ,D{O[1:K]=o[1:K]} by finding the value of Θ that maximizes the given probability of the observed allele counts o[1:K]. In our analyses, we estimated the model parameters Θ separately using each of the different probabilities, yielding the estimators sˆW,sˆD,sˆW, and sˆD. The estimator sˆW accounts for drift under the discrete Wright–Fisher model, whereas drift in this model is ignored by the estimator sˆW. Similarly, the estimator sˆD accounts for drift under the diffusion model, whereas drift in this model is ignored by the estimator sˆD.

The degree to which accounting for drift can improve estimates of selection coefficients can be investigated by comparing sˆW to sˆW on trajectories simulated under the discrete Wright–Fisher model and by comparing sˆD to sˆD on trajectories simulated under the diffusion approximation.

Procedure 1. Computing PΘ,W{O[1:K]=o[1:K]}

1: Define the quantities d0=(P{C0=0},P{C0=1},,P{C0=2Nt0}) and γ(o1), where γ(ok)=(γ0(ok),γ1(ok),,γ2Ntk(ok)) with γi(ok)=(nkok)(i/2Ntk)ok(1i/2Ntk)nkok.

2: Initialize v1=d0[t=1t1Tt1,t]diag{γ(o1)}.

3: For k=2:K, compute

vk=vk1[t=tk1+1tkTt1,t]diag{γ(ok)}.

4: Compute PΘ,W{O[1:K]=o[1:K]}=i=02NtKvK,i.

______________________________________________________________________________________________

Modifications:

 If d0 is unspecified, omit Step 1and set v1=γ(o1)/2Nt1 in Step 2.

 If conditioning on the event SK that allele A is segregating in the final sample, omit Step 4 and instead compute PΘ,W{O[1:K]=o[1:K]|SK} using equation(C.1).

Procedure 2. Computing PΘ,D{O[1:K]}

1: For an initial starting frequency y0 initialize

b0=C11B1(y0),

where B(y0) is the vector of eigenfunctions of the diffusion operator given inequation (A.14) and C=diag{B,i,B,i}i=0 is given in equation (A.18).

2: For k=1:K, compute

ak = {bk1Ek(tktk1)ifk1=k,bk1F(tk1,tk;ζ)otherwise,

and

bk=akWkGkok(1Gk)nkokWk1,

where the matrices E(t),F(tk1,tk;ζ),W, and G are given byequations (A.17), (B.10), (A.15), and (A.11), respectively, and ζ is the set of Chebyshev nodes in the interval [0,1]. The matrix inverse W1=DWTC1 is computed easily using the diagonal matrices C and D in equations (A.18) and (A.19).

3: Compute

PΘ,D{O[1:K]=o[1:K]}=cK,0BK,0(0)bK,0, (1)

where cK,0=B,0,B,0=[CK]0,0 is the (0, 0) element of matrix C in equation (A.18) and BK,0(0) is the 0th element of the vector BK(0) in equation (A.14).

______________________________________________________________________________________________

Modifications:

 If y0 is unspecified, omit Step 1 and initialize b1 using equation (B.17). Then iterate over k=2:K in Step 2.

 If conditioning on the event SK that allele A is segregating in the final sample, omit Step 3 and instead compute PΘ,D{O[1:K]=o[1:K]|SK} using equation (D.1).

Procedure 3. Computing PΘ,W{O[1:K]=o[1:K]}

1: Starting with y0=y0, for t=0,,tK1,

Compute y˜t=uaA(t)+(1uAa(t)uaA(t))yt.

Compute

yt+1=[(y˜t)2(1+st)+y˜t(1y˜t)(1+htst)w¯t],

where w¯t=(y˜t)2(1+st)+2y˜t(1y˜t)(1+htst)+(1y˜t)2.

2: Compute

PΘ,W{O[1:K]=o[1:K]}=k=1K(nkok)(ytk)ok(1ytk)nkok.

______________________________________________________________________________________________

Modifications:

 If y0 is unspecified, set y=1/M for a large value M and repeat Steps 1 and 2 for the dense uniform grid of M + 1 values y0[0,y,2y,,1]. Set PΘ,W{O[1:K]=o[1:K]}=1M+1j=0MPΘ,W{O[1:K]=o[1:K];y0=jy}.

Procedure 4. Computing PΘ,D{O[1:K]=o[1:K]}

1: Fix a large integer n and set Δt=1/n.

2: Starting with y0=y0, for j=0,,ntK1, compute

y(j+1)Δt={uaA(jt)(uaA(jt)+uAa(jt))yjΔt  +yjΔt(1yjΔt)[(12yjt)hjtsjt+yjΔtsjt] }Δt.

3: Compute

PΘ,D{O[1:K]=o[1:K]}=k=1K(nkok)(ytk)ok(1ytk)nkok.

______________________________________________________________________________________________

Modifications:

 If y0 is unspecified, set y=1/M for a large value M and repeat Steps 1 and 2 for the dense uniform grid of M + 1 values y0[0,y,2y,,1]. Set PΘ,W{O[1:K]=o[1:K]}=1M+1j=0MPΘ,W{O[1:K]=o[1:K];y0=jy}.

Overview of the Experimental Design

We simulated allele frequency trajectories under a variety of selection strengths and piecewise constant population histories reflecting demographic patterns such as exponential growth, bottlenecks, rapid population size oscillations, and constant histories. We then compared the demography-aware estimates sˆW and sˆD with the estimates sˆW and sˆD that ignore drift to study the degree to which accounting for population size can improve the accuracy of inferences.

Expected Allele Frequency Trajectories

Before comparing the accuracy of the different estimators, we first explored the degree to which trajectories that ignore drift differ from trajectories that account for drift resulting from finite population sizes. Figure 2 shows the expected frequency of allele A in a discrete Wright–Fisher population of constant size for several different initial allele frequencies, selection coefficients, and effective population sizes. Figure 2 illustrates that, for any starting frequency and selection coefficient, the mean allele frequency trajectory approaches the mean trajectory in a population without drift (i.e., in a population of infinite size), as the true population size increases. Moreover, if the initial frequency is sufficiently high, the expected trajectory is close to its deterministic limit even when the population size is small and drift is high.

Fig. 2.

Fig. 2.

Expected Wright–Fisher trajectories of allele A for different initial starting counts c0, selection coefficients s, and effective population sizes N. Columns correspond to different initial starting frequencies c0/2N with c0/2N=0.01,0.1, and 0.25. The dominance parameter is set to h = ½ in all panels. Because the effects of mutation are negligible during the time periods we consider, we set uAa=uaA=0.

From figure 2, it can be seen that an effective population size of several thousand individuals is often sufficiently large to produce deterministic behavior, even when the selection coefficient and initial allele frequency are small. Thus, selection coefficient inference methods that ignore drift are likely to be accurate for a broad range of population sizes and selection coefficients. As we will see, methods that ignore drift can be almost as accurate as methods that account for drift, even within the small-parameter-value regime.

Inference Accuracy for Populations of Constant Size

To explore how accounting for drift affects inference accuracy, we first considered the accuracy of inferring selection coefficients in a population of constant finite size. Figure 3 shows the maximum likelihood estimate (MLE) of the selection coefficient for three different effective population sizes (N = 100, 500, 1000), three selection coefficients (s=0.01,0.05,0.1), and two initial allele frequencies (y0=0.01,0.1) for h = ½. In each of panels A-R, the violin plots summarize the maximum likelihood estimates for 100 different simulation replicates in which an allele frequency trajectory was simulated for 500 generations with samples of size n = 50 taken at generations t=50, 100, 150, 200, 250, 300, 350, 400, 450, and 500.

Fig. 3.

Fig. 3.

Maximum likelihood estimates of the selection coefficient s in populations of constant size. For each of three different selection coefficients (s=0.01,0.05,0.1) and effective population sizes (N = 100, 500, 1000), 100 allele frequency trajectories were simulated for 500 generations under the either the Wright–Fisher or diffusion models. Samples of 50 alleles were taken at times 50, 100, 150, 200, 250, 300, 350, 400, 450, and 500 generations. Bars in panels A-R indicate medians. Dashed lines indicate true selection coefficients. The maximum width of each violin plot is scaled to the same value for all estimators. Scatter plots S, T, U, V, W, and X compare the estimates sˆW with the estimates sˆW using the same data shown in the top modes of the distributions in Panels A, B, C, J, K, and L for the case s = 0.01. Diagonal lines in these scatter plots indicate the line sˆW=sˆW. Bimodal violin plots are due to the fact that allele frequency trajectories typically fall into one of two categories: trajectories in which allele A is lost quickly, resulting in a strong negative estimate of the selection coefficient, and trajectories in which allele A remains segregating long enough to allow a more accurate estimate of the selection coefficient.

For the discrete Wright–Fisher model, allele frequency trajectories were simulated by sampling the allele frequency in each generation from the vector of transition probabilities, conditional on the frequency in the previous generation using Procedure 5. Under the diffusion model, trajectories were sampled using the approach in Procedure 6. Maximum likelihood estimates were obtained for the Wright–Fisher trajectories using the grid search described in Procedure 7 over the likelihoods computed using Procedures 1 and 3, and maximum likelihood estimates for the diffusion trajectories were obtained using the same grid search approach over the likelihoods computed using Procedures 2 and 4. In each panel in figure 3, the estimates sˆW and sˆW were computed for the same set of 100 allele frequency trajectories simulated under the discrete Wright–Fisher model and the estimates sˆD and sˆD were computed for the same set of 100 allele frequency trajectories simulated under the diffusion model.

By comparing the estimates computed accounting for drift with the estimates obtained ignoring drift, it can be seen that all methods have similar accuracies. All methods perform well when the population size, selection coefficient, and initial frequency are sufficiently large (e.g., fig. 3I for the case y0=0.01 and Panels 3K through 3R for the case y0=0.1), and all methods have reduced accuracy, otherwise. To put this another way: the allele frequency trajectories for which selection coefficients are inferred accurately by demography-aware methods correspond to those for which the deterministic estimates are also accurate. Thus, methods that ignore or account for drift are likely to produce estimates with similar accuracy.

Moreover, it can be seen from the scatter plots (Panels 3S–3X), which compare the estimators sˆW and sˆW, that the point estimates themselves are very similar for both the demography-aware and deterministic methods. Although this similarity may be expected given that the deterministic methods differ from the demography-aware methods only in that they ignore the additional variability in the allele frequencies arising from genetic drift, it is surprising that the point estimates are so similar, as the overall expected allele frequency trajectory in the deterministic case can differ considerably from the expected trajectory accounting for drift (fig. 2A–C).

As the magnitude of the selection coefficient decreases, the point estimates of the deterministic and demography-aware estimators remain well correlated, although the accuracy of all methods decreases. This can be seen in figure 3S–X and in supplementary fig. S1, Supplementary Material online in which the estimates by the different methods remain correlated, but become more variable as the selection coefficient s decreases and an increasingly large number of trajectories drift out of the population quickly, leading to strong negative estimates of selection coefficients by both methods.

Inference Accuracy in Populations of Piecewise Constant Size

We next explored the degree to which accounting for more complicated population histories can improve maximum likelihood estimates, focusing on three scenarios, a population with a bottleneck, a population undergoing exponential growth, and a population undergoing rapid oscillations in size. Under each scenario, we simulated 100 allele frequency trajectories for an allele with selection coefficient s = 0.05, dominance parameter h = ½, and initial frequency y0=0.1 under the Wright–Fisher model and separately under the diffusion model. The parameter values in these simulations were chosen so that drift would be strong enough to affect allele frequency trajectories, but not strong enough to result in poor estimates of selection coefficients by the full-likelihood methods.

In addition to comparing estimates made by the deterministic estimators, sˆW and sˆD, with those of the exact estimators, sˆW and sˆD, that account for the true time-varying population history, we investigated the effect on accuracy of using crude, yet reasonable estimates of the population history. In particular, we also inferred selection coefficients using likelihoods computed using variants of Procedures 1 and 2 in which the population was assumed to consist of a single epoch of constant size equal to the Watterson estimate (Watterson 1975, Eqn. 1.4a; Hein et al. 2005, p.62). The Watterson estimate was obtained by computing the expected site frequency spectrum (SFS) for the multi-epoch model for a sample size of 20 alleles using the method of Kamm et al. (2016) and then inferring the effective size of a single epoch using Watterson’s estimator (Computing the Watterson estimator of Ne from the expected SFS of a piecewise constant population). The discrete Wright–Fisher and diffusion estimators based on the Watterson estimate of effective size are denoted by sˆWNe and sˆDNe, respectively.

The Case of a Bottleneck

To model populations with bottlenecks, we considered populations composed of three epochs, each of length 100 generations, with sizes N1, N2, and N3 satisfying N1=N3=5N2. Samples of size 50 were taken at times 50,100,150,200,250, and 300. Figure 4A and B shows the results for two different populations; in the population in figure 4A, we set N1=500 and in the population in figure 4B we set N1=2500.

Fig. 4.

Fig. 4.

Maximum likelihood estimates of the selection coefficient s in populations with a bottleneck, exponential growth, or rapidly oscillating population size. In each panel, the trajectory of an allele with selection coefficient s = 0.05, dominance parameter h = ½, and starting frequency y0=0.1 was simulated 100 times under the Wright–Fisher and diffusion models. Bars indicate medians. Dashed lines indicate the true selection coefficient. The maximum width of each violin plot is scaled to the same value for all estimators.

From figure 4A and B, it can be seen that all methods performed similarly. However, the deterministic estimators had significantly lower bias than the full-likelihood estimators computed using the mis-specified population history for a bottleneck of size N2=100 with N1=N3=500 (fig. 4A). In the case of the bottleneck in figure 4A, the means of the deterministic estimators sˆW and sˆD were not significantly different from the true selection coefficient s (P = 0.59 and P = 0.93 for t-tests of the null hypotheses mean(sˆW)=s and mean(sˆD)=s versus the alternative hypotheses mean(sˆW)s and mean(sˆD)s). In comparison, the means of the full likelihood estimators sˆWNe and sˆDNe with mis-specified histories were significantly different from s (P = 0.03 and P < 0.01, respectively). A similar trend was observed for the bottleneck history with larger sizes shown in figure 4B (P = 0.64 and P = 0.12 for t-tests of the null hypotheses mean(sˆW)=s and mean(sˆD)=s, compared with P = 0.13 and P = 0.01 for t-tests of the null hypotheses mean(sˆWNe)=s and mean(sˆDNe)=s). Note that, despite the tight bottleneck in figure 4A, inferences were still relatively accurate due to the larger sizes of epochs 1 and 3.

The Case of Exponential Growth

To model exponential growth, we considered populations composed of five epochs, each of length 100 generations, with effective population sizes chosen to represent 5-fold exponential growth across all five epochs. Specifically, the size in epoch ℓ was set to N=N0eητ, where we chose N0=100 and the growth constant η was chosen such that eητ5=5. Samples of size 50 were taken in generations 100, 200, 300, 400, and 500. From the results in figure 4C and D, it can be seen that all methods performed with similar accuracy in the growth scenario.

The Case of Rapidly Oscillating Population Size

Figure 4E and F shows inferences of the selection coefficient in a population with rapidly oscillating size. Such demographic histories, which are often seen in insect populations like Drosophila, have moderate arithmetic mean sizes, but small harmonic mean sizes and experience episodes of extreme drift.

In the simulations shown in figure 4E, the population size oscillates rapidly between 10 and 100 diploids every five generations. In the simulations shown in figure 4F, the population size oscillates between 100 and 500 diploids every five generations. From figure 4, it can be seen that the methods that ignore drift have similar accuracy to the methods that account for drift. However, the methods that account for drift are slightly less biased when the population size oscillates between very small values (fig. 4E) (P = 0.017 and P = 0.012, respectively, for the one-tailed t-tests of the null hypotheses sˆWsˆW and sˆDsˆD versus the alternative hypotheses sˆW<sˆW and sˆD<sˆD).

Conditioning on Segregation in the Final Sample

It is sometimes of interest to infer the selection coefficient of an allele, conditional on the event that the allele is segregating in the most recent sample. Such conditional inferences are useful if alleles are ascertained in present-day samples and their historical trajectories are subsequently investigated.

Conditioning on segregation in the final sample is also useful for estimating weak positive selection coefficients when initial allele frequencies are low. This is because a large fraction of weakly selected alleles with low initial frequencies will drift out of the population quickly resulting in large negative estimates of their selection coefficients. However, more accurate estimates can be obtained for the subset of alleles that are not lost quickly, which can be seen, for example, in figure 3B–I through I in which the part of the density corresponding to alleles that are not lost quickly from the population is localized around the true selection coefficient.

Considering only alleles that are segregating in the final sample can lead to biased estimates of selection coefficients if likelihood methods do not properly condition on segregation. For example, weakly selected alleles typically drift out of small populations quickly. Thus, weakly selected alleles that escape loss and ultimately fix generally exhibit faster-than-expected increases in frequency that are similar to the unconditional trajectories of alleles under stronger selection. Thus, if a likelihood method does not properly account for conditioning, weakly selected alleles that are segregating in the final sample will have inflated inferred selection coefficients.

Estimators that ignore drift cannot be modified to condition on the event of segregation in the final sample because they implicitly assume that alleles follow fixed trajectories whose long-term behavior in the absence of mutation is entirely determined by the selection coefficient: fixation for positively selected alleles and loss for negatively selected alleles. Thus, estimators that ignore drift are expected to produce biased estimates of selection coefficients when applied to conditioned trajectories.

In contrast, the allele frequency trajectories in likelihood methods that account for the population size are modeled stochastically, allowing likelihoods to be modified to condition on segregation in the final sample. It is expected that methods that account for the true population size can be modified to produce accurate estimates of selection coefficients, whereas methods that ignore drift will necessarily produce biased estimates.

Simulations Conditioning on Segregation

To investigate the degree to which accounting for drift can improve estimates of selection coefficients when allele frequency trajectories are conditioned on segregation in the final sample, we modified the discrete Wright–Fisher probability in Procedure 1 to compute the likelihood conditional on segregation in the final sample using results derived in the “Conditional Probabilities” section. Under a grid search, this modified likelihood yields the conditional maximum likelihood estimator sˆW|SK. We compared the estimates computed using the exact conditional estimator sˆW|SK with estimates computed using the approximate estimator sˆW that ignores drift and cannot be modified to account for conditional allele frequency trajectories.

The effect of failing to account for conditioning is evident in the violin plots in figure 5A–I corresponding to the unconditional approximate maximum likelihood estimates sˆW. As expected, when the true selection coefficient is small (s0.01), the estimates sˆW are biased upward. Conversely, when the selection coefficient is larger (s0.05), the approximate estimator sˆW produces negatively biased estimates because alleles under strong positive selection that remain segregating in the final sample show slower-than-expected increases in frequency. In contrast to the estimator sˆW, the bias is negligible in the estimator sˆW|SK, which accounts for drift and properly conditions on segregation in the final sample.

Fig. 5.

Fig. 5.

Estimates of selection coefficients, conditional on segregation. Each violin plot was computed using 100 frequency trajectories sampled over 500 generations for an allele with initial frequency y0=0.01. As in figure 3, samples of size n = 50 were taken in generations 50, 100, 150, 200, 250, 300, 350, 400, 450, and 500. In Panels A–I, trajectories were sampled conditional on the event that the selected allele was segregating in the final sample. In Panels J–R, trajectories were sampled conditional on the event that the selected allele was either segregating or fixed in the final sample. Red bars indicate medians. Dashed lines indicate the true selection coefficients. The maximum width of each violin plot is scaled to the same value for both estimators.

The results shown in figure 5A–I suggest that methods that account for drift are capable of significantly improving the accuracy of estimates of selection coefficients when allele frequency trajectories are conditioned on segregation. The differences in accuracy between methods that ignore or account for drift are visible for a range of selection coefficients and population sizes. However, the differences in accuracy between the methods diminish as the population size becomes larger.

Simulations Conditioning on Segregation or Fixation

The magnitude of the bias in the estimates sˆW is due in part to the event on which trajectories are conditioned. In cases involving positive selection in populations of moderate or large size, most alleles will be fixed in the final sample (e.g., >80% fixation within 10 generations when s = 0.1, h = ½, y0=0.01, and N = 1000). Thus, it may sometimes be more natural to condition on the event FK that a selected allele is found (segregating or fixed) in the final sample. Under this conditioning scheme, the approximate estimator sˆW will not generally produce negatively biased estimates of selection coefficients because allele frequency trajectories will not be constrained to those which exhibit slower-than-expected increases in allele frequency.

In light of these considerations, we repeated the analysis shown in figure 5A–I, simulating allele frequency trajectories conditional on the event that the allele was segregating or fixed in the final sample. To compare the estimates sˆW with maximum likelihood estimates that fully account for drift and the proper conditioning, we also modified the probability PΘ,W{O[1:K]=o[1:K]} computed in Procedure 1 to condition on the event FK of segregation or fixation in the final sample, yielding the conditional probability PΘ,W{O[1:K]=o[1:K]|FK} (eq. 21) with the associated estimator sˆW|FK.

By comparing figure 5J–R with figure 5A–I, it can be seen that the estimator sˆW has considerably less bias when conditioning on the event FK than when conditioning on SK. Although the bias is still high when the population size is small (N100), it decreases quickly as the population size increases and becomes comparable to the bias in the properly conditioned, demography-aware estimator sˆW|FK when the population size is greater than approximately N = 500 diploids. In contrast to figure 5E–I, the bias in sˆW observed in figure 5M–R is positive because the trajectories on which these estimates are based exclude only those in which the allele is lost; thus, they exhibit faster-than-expected growth on average. The results in figure 5J–R suggest that under certain conditioning schemes, methods that ignore drift can produce similar estimates to methods that account for drift.

The Effect of Sample Size on Accuracy

When the sample size is small, the variance in estimates arising from sampling noise will tend to obscure small differences between estimators that ignore or account for population size. Thus, when comparing methods, it is important to sample a sufficiently large number of alleles to ensure that the differences between the methods due to ignoring or accounting for drift are visible.

To evaluate the effects of sample size on inference accuracy, we inferred the selection coefficient for a range of sample sizes for several different combinations of the population size and selection coefficient. Figure 6 shows a plot of the variance in selection coefficients inferred using Procedures 1 and 3 for sample sizes ranging from n = 2 to n = 50. For each combination of Ne, s, and n, the trajectories of 100 alleles were simulated under the Wright–Fisher process with an initial allele frequency of y0=0.1. Samples were taken in generations 50 and 100.

Fig. 6.

Fig. 6.

The effect of sample size on inference accuracy. The variance of the estimates produced by the methods in Procedures 1 and 3 are shown for a range of sample sizes.

The plots in figure 6 suggest that variability due to small sample sizes has a strong effect on the variability in estimates only for sample sizes smaller than 10 alleles. Thus, in all of our simulations, we have used a sample size of n = 50 alleles so that differences between estimators are not likely to be obscured by the variance in estimates due to small sample sizes.

Unspecified Initial Allele Frequencies

In our simulations, we have assumed that the initial frequency y0 of allele A at time t = 0 is known. Knowledge of the initial allele frequency provides approximately the same information as an informative sample taken at time t = 0. Although this information can improve the estimate of the selection coefficient if few samples are taken, it contributes relatively little information to the estimate of s when the number of samples is moderate. However, because a lack of knowledge of the initial frequency could potentially lead to greater errors in the deterministic estimators, we also compared versions of the estimators that assume a uniform prior distribution on the allele frequency at the time of the first sampling event, and which do not incorporate information about the initial allele frequency (Computing PΘ,W{O[1:K]=o[1:K]} When d0 Is Unspecified, Computing PΘ,D{O[1:K]=o[1:K]} When y0 Is Unspecified, and Deterministic Estimators When the Initial Allele Frequency Is Unknown).

Figure 7 shows a comparison between the deterministic and exact Wright–Fisher estimates when the initial frequency is drawn uniformly from the interval y0(0,0.5] and the selection coefficient is inferred using Procedures 1 and 2 assuming no knowledge of the initial allele frequency. From figure 7, it can be seen that the deterministic and exact estimators produce similar results, even in the absence of knowledge of the initial frequency. Moreover, although the estimates produced by the two methods decrease in accuracy as the number of sampling events decreases, the accuracies of the two kinds of methods remain similar. In particular, From figure 7D–F, it can be seen that both the deterministic and exact methods are relatively accurate when allele frequency trajectories do not drift out or fix immediately due to random fluctuations.

Fig. 7.

Fig. 7.

Scatter plots comparing the estimates sˆW and sˆW when the initial allele frequency is unspecified during inference. One hundred allele frequency trajectories were simulated for 500 generations with s = 0.05, N = 100, and y0 sampled uniformly from the interval (0,0.5] as described in the “Simulations” section. Estimates sˆW and sˆW were computed using Procedures 1 and 2 using the modified procedure taken when d0 and y0 are unspecified. (A) Estimates computed using all ten samples of size n = 50 taken in generations 50,100,150,200,250,300,350,400,450, and 500. (B) Estimates computed using the five samples taken in generations 50,150,250,350, and 450. (C) Estimates computed using the two samples taken in generations 50 and 150. (D), (E), and (F) are zoomed-in versions of the plots in (A), (B), and (C). All panels correspond to the same 100 simulated trajectories. Dashed lines correspond to the true selection coefficient. Bars show means over all 100 estimates. The solid line is sˆW=sˆW.

Violation of Model Assumptions

It is possible that violations of model assumptions in real data could increase the differences in accuracy between the deterministic and demography-aware estimators. To investigate this possibility we compared the performance of the deterministic and demography-aware discrete Wright–Fisher estimators using experimentally sampled allele frequency time series data that are thought to violate several model assumptions. In particular, we considered time series data for an allele at the medionigra locus in the species Panaxia dominula, which confers a darkened wing phenotype (Cook and Jones 1996). Although these samples are thought to represent a single population that is isolated from migration events, there is evidence for temporal fluctuations in the selection coefficient, frequency dependent selection, and assortative mating. These data are also useful for our analyses because they include estimates of population sizes obtained using mark, release, and recapture. The data set, which spans over 40 years, provided important evidence for natural selection resulting from environmental pressures.

We computed the log likelihood as a function of the selection coefficient s for three different values of the dominance parameter (h=0,0.5, and 1). Figure 8 shows the log likelihood for different values of h, along with asymptotic normal approximations of 95% confidence intervals. Figure 8 shows that the log likelihood surfaces computed using Procedures 1 and 3 are qualitatively similar, yielding similar point estimates for s. However, the confidence intervals for the deterministic estimator are considerably smaller than those of the demography-aware estimator. This result is expected, given that the deterministic estimator ignores the largely symmetrical variability arising from drift and considers only variability in the sampling frequency.

Fig. 8.

Fig. 8.

The log likelihood as a function of s computed using Procedures 1 and 3 for three different values of the dominance parameter h (h=0,0.5,1). Solid vertical lines show the maximum likelihood estimates, sˆW in (A) and sˆW in (B), for the curve of the corresponding color. Dashed vertical lines indicate asymptotic normal approximations of the 95% confidence intervals for s, for the curve of the corresponding color. (A) The demography-aware likelihoods (Procedure 1). (B) The deterministic likelihoods (Procedure 3).

Note that the point estimates presented in figure 8 are similar to those estimated previously in other studies. Using a model of additive selection (h = 0.5) Cook and Jones (1996) estimated s0.16 whereas Mathieson and McVean (2013) inferred s0.12. These estimates are close to the maximum likelihood estimates that we inferred under the same model of additive selection (sˆW=0.1 and sˆW=0.09) (note that the estimates in Cook and Jones (1996) and Mathieson and McVean (2013) are reported using a different parameterization of the dominance model than the one we have used in this paper; thus, we have scaled the selection coefficients reported in these papers so that they are comparable with the ones reported here).

It is of interest to note that Mathieson and McVean (2013) found evidence that the medionigra allele is recessive, finding that the likelihood was maximized for a recessive model with a strong negative selection coefficient around s1, although they note that such a strong negative selection coefficient violates the assumptions of the Gaussian model under which their likelihoods were derived. In accordance with the result of Mathieson and McVean (2013), we find that both the deterministic and exact Wright–Fisher likelihoods we considered were also maximized for a recessive pattern of dominance (h = 0) with a large negative selection coefficient around s1.

Under a recessive model of dominance, the strongly negative selection coefficient that was inferred by the estimators in this study and by that of Mathieson and McVean (2013) is reasonable given that the allele frequency decreases rapidly, which would be unlikely under weak selection where alleles must combine in homozygotes for selection to act. Unlike the analyses of Mathieson and McVean (2013), a selection coefficient of s1 does not violate our model assumptions. Thus, our analysis provides further support that the medionigra variant is largely recessive, although there is evidence that the dominance of the variant can change over time (Cook and Jones 1996).

Computational Efficiency of Methods

As we have noted, methods that assume that allele frequency trajectories are deterministic can be considerably faster than methods that account for population size histories. Table 1 shows the average runtimes of the estimators sˆW,sˆW,sˆD, and sˆD for the computations used to produce figure 3A–I.

Table 1.

Mean Runtimes of the Methods in figure 3A–I (seconds).

Ne s sˆW sˆW sˆD sˆD
100 0.01 0.01 2.30 4.74 197.25
0.05 0.01 2.36 4.23 204.66
0.1 0.01 2.29 3.98 217.34
500 0.01 0.02 134.07 4.41 185.18
0.05 0.01 132.45 4.41 496.83
0.1 0.02 126.35 4.46 531.15
1000 0.01 0.02 175.27 4.64 196.90
0.05 0.02 191.53 4.78 815.27
0.1 0.02 199.32 4.67 1950.59

From the table, it can be seen that the runtimes are considerably faster for the estimators based on deterministic trajectories (sˆW and sˆD). Moreover, the runtimes for sˆW and sˆD do not depend on the population size or selection coefficient. In comparison, the runtimes for the estimators sˆW and sˆD increase with increasing Ne and s because these methods depend on eigenvalue decompositions or sparse matrix products, which require larger matrices or greater precision when Ne or s is large. Note that although the discrete Wright–Fisher estimator is considerably faster than the diffusion estimator for the scenarios we considered, the diffusion estimator can still be more efficient when samples are widely separated in time and the repeated matrix–vector products required by the discrete Wright–Fisher method become cumbersome.

Discussion

The results of our analyses suggest that accurate estimates of selection coefficients from allele frequency time series data can often be obtained by assuming that alleles evolve without drift in a population of infinite size. In the majority of our simulations, the estimates obtained using deterministic approximations were nearly as accurate as estimates obtained by explicitly modeling the true population history and they were sometimes more accurate than estimates obtained using crude but reasonable estimates of the population history. The latter result indicates that an overestimate of the population size, for example due to underestimation of the mutation rate or other factors, may have only small adverse effects on the accuracy of exact likelihood estimates of the selection coefficient from time series data, a result that is of interest because population size histories can be difficult to infer accurately.

Surprisingly, estimates made under the deterministic approximation were generally as accurate as estimates that accounted for drift, due to the fact that the exact maximum likelihood methods had low accuracy when drift was strong. Accounting for the true population history only resulted in significantly improved estimates of selection coefficients when conditioning on the event that the target allele was segregating in the final sample. Methods that modeled the true population history were more accurate in this case because they could be modified to model conditional trajectories, whereas methods that assumed infinite population sizes could not. These results suggest that methods that account for drift are likely to be preferable under circumstances in which conditioning on segregation is desirable. However, it is important to note that deterministic methods can perform well when population sizes are moderately large if allele frequencies are conditioned on a slightly different event: the event that an allele is found (segregating or fixed) in the final sample.

It is important to note that we have focused on estimates of the selection coefficient rather than the dominance parameter h, which is a more difficult task. However, in our analyses of the medionigra variant in the Panaxia dominula moth, we found that both the deterministic and exact likelihoods were qualitatively similar in both h and s and were both maximized for a recessive model of dominance. A comprehensive exploration of the effects of deterministic assumptions on the inference of h is deferred to future analyses.

It is also important to note that our analyses do not imply that the deterministic and exact estimators will produce exactly the same point estimate for a given allele frequency trajectory. Although the scatter plots in figures 3, 7, and supplementary figure S1, Supplementary Material online suggest that both deterministic and exact estimators often agree closely on the magnitude of the selective strength, the estimates for any given trajectory can differ by 100% or more. This result is consistent with the observation by Schraiber et al. (2016) that specifying different demographic histories led to different estimates of dominance and selection parameters for alleles affecting coat coloration in horses. Although specific point estimates can differ, our results demonstrate that deterministic and exact estimators have similar accuracies for estimating the strength of selection, even when the population size is small.

The idea that ignoring drift can lead to accurate estimates of selection coefficients is not new. In fact, inference methods based on deterministic allele frequency trajectories capitalize on exactly this idea. However, our comparison with estimators based on exact likelihoods makes it possible to characterize the relative loss in accuracy that is incurred when drift is ignored, as well as the demographic, evolutionary, and sampling scenarios under which accounting for drift is likely to be important.

The comparatively accurate estimates achieved by methods that assume deterministic allele frequency trajectories are encouraging for three primary reasons. First, a large number of studies have relied on the assumption that alleles evolve deterministically in order to infer selection coefficients from biological time series data. Our results suggest that these estimates are likely to be nearly as accurate as those obtained using the exact likelihood accounting for drift. Second, estimators based on deterministic trajectories can be considerably faster than estimators that account for drift, making them useful for inferring selection coefficients at large numbers of loci. Third, it may be easier to obtain analytical results under the assumption that allele frequencies change deterministically, simplifying the development of inference methods for inferring selection coefficients under more complicated scenarios; for example, inferring coefficients at linked loci (Illingworth et al. 2012). Finally, the ability to ignore the population size is useful in situations in which the true population history is unknown or difficult to infer.

In addition to characterizing the degree to which accounting for drift can improve estimates of selection coefficients, our results shed light on the accuracy of exact maximum likelihood methods for inferring selection coefficients from allele frequency trajectories. In accordance with predictions about the relative strengths of genetic drift and selection (Gillespie 1998, section 3.7) and experimental work (Gallet et al. 2012), our findings suggest that very small selection coefficients (s0.01) are difficult to infer if the initial allele frequency and population size are not large. Moreover, even if the population size is large, the accurate inference of a small selection coefficient may require samples taken over hundreds of generations, during which time the selection coefficient could change considerably (Felsenstein 1976; Siepielski et al. 2009).

Despite the difficulties of inferring weak selection coefficients when the population size is small, coefficients of one percent or lower can be inferred accurately if the initial allele frequency is sufficiently high. It is important to note that the selection coefficient need not be high at the time of the very first sampling event, as long as the allele has reached a sufficiently high frequency at one of the intermediate sampling events, leading to quasi-deterministic behavior between some sampling time points that can be exploited by the maximum likelihood estimator.

Although we have only considered positively selected alleles in our simulation analyses, our results apply equally well to negatively selected alleles, as it is arbitrary whether we choose to track the trajectory of the allele with higher or lower fitness. We have also focused on low initial allele frequencies (y00.1) for selected alleles; however, it is clear from figure 2 that allele frequency trajectories become increasingly deterministic as the initial allele frequency increases. Thus, the accuracy of a method that assumes a deterministic trajectory will become more similar to that of a method that accounts for drift as the initial allele frequency increases. Conversely, for negatively selected alleles, the accuracy of the deterministic method will approach that of the exact likelihood as the initial allele frequency decreases. Thus, our analyses provide a characterization of inference accuracy for both positively and negatively selected alleles for a broad range of starting frequencies.

At first glance, our finding that the population size does not strongly influence estimates of selection coefficients might appear to be at odds with the fact that population size histories can be inferred from allele frequency time series data (O’Hara 2005; Bollback et al. 2008; Ferrer-Admetlla et al. 2015). However, this is not the case. Methods for inferring the population size capitalize on information in the short-term fluctuations of the allele frequency around its expected value, arising from drift; conversely, estimators of selection coefficients capitalize on the long-term changes in allele frequency due to selection, effectively averaging over the short-term fluctuations due to drift. Our results suggest that allele frequencies often change quasi-deterministically, even in small populations. Thus, deviations around the expected trajectory can be distinguished from long-term changes, allowing effective population sizes to be inferred accurately even in small populations.

We have conducted our analyses under two different models of evolution: the discrete Wright–Fisher model and the continuous diffusion model. Although the diffusion model was developed as an approximation to the Wright–Fisher process, it also captures the limiting behavior of a large class of evolutionary models, including the Wright–Fisher process, as the population size grows to infinity and mutation and selection parameters are scaled accordingly. Thus, it is reasonable to believe that our findings will generalize to maximum likelihood estimators derived under a wide range of evolutionary models.

Taken together, our results help to characterize the properties of maximum likelihood methods for inferring selection coefficients from time series data. Because of the accuracy and beneficial properties of maximum likelihood methods, it is reasonable to believe that our results provide insight into the accuracy with which it is possible to infer selection coefficients from biological data, and the degree to which accounting for the true population history can improve these estimates. Our results also provide justification for the use of fast inference methods based on the assumption that allele frequencies evolve deterministically. Such methods can be applied to infer selection coefficients efficiently on large genomic data sets with many loci. Finally, our results provide further justification for the use of deterministic approximations in the development of statistical approaches for studying time series data.

Methods

In this section, we compute the exact probability of an allele frequency trajectory in a population of piecewise-constant size under the discrete Wright–Fisher model and under the diffusion approximation. We also describe how drift can be ignored in these probabilities, yielding approximate estimators of selection coefficients that are similar to commonly used approaches that assume deterministic allele frequency trajectories.

Computing PΘ,W{O[1:K]=o[1:K]} under the Discrete Wright–Fisher Model

To compute the probability PΘ,W{O[1:K]=o[1:K]} under the discrete Wright–Fisher model, we make use of a hidden Markov model (HMM) similar to that presented in Steinrücken et al. (2014). However, the hidden state in our discrete model is the count ct of the number of (unobserved) copies of allele A in the population at time t, rather than the continuous allele frequency yt.

In our model, the count ct of allele A evolves according to a Wright–Fisher process in which mutation occurs, followed by random mating, selection, and drift. Given that the count of allele A in generation t is ct =i, let fA|it be the frequency of allele A in the gamete pool after mutation. Then

fA|it=(i2Nt)(1uAa(t))+(1i2Nt)uaA(t)=uaA(t)+(1uAa(t)uaA(t))(i2Nt). (2)

After random mating, the fraction of zygotes with each of the genotypes AA, Aa, and aa is (fA|it)2,2fA|it(1fA|it), and (1fA|it)2, from which it follows that the fraction of genotypes of each kind remaining after selection is given by

pAA|it=(fA|it)2(1+st)w¯t,i,pAa|it=2fA|it(1fA|it)(1+htst)w¯t,i,paa|it=(1fA|it)2w¯t,i, (3)

where w¯t,i=(fA|it)2(1+st)+2fA|it(1fA|it)(1+htst)+(1fA|it)2 is the mean fitness of the population.

Immediately after selection and before drift occurs, the probability that a randomly chosen allele is of type A is given by pA|it=pAA|it+12pAa|it. Then, as the result of drift, the count of allele A in generation t + 1 is binomially distributed with mean pA|it. Thus, the probability that allele A has count j in generation t + 1, given that it had count i in generation t is

PΘ,W{Ct+1=j|Ct=i}=(2Nt+1j)(pA|it)j(1pA|it)2Nt+1j. (4)

The Wright–Fisher transition matrix Tt,t+1 from generation t to generation t + 1 is the (2Nt+1)×(2Nt+1+1) matrix with entry i, j given by

[Tt,t+1]ij=PΘ,W{Ct+1=j|Ct=i}, (5)

which can be used to obtain the allele frequency distribution at each discrete generation t given the initial distribution at some time r < t. In particular, define dt=(P{ct=0},P{ct=1},,P{ct=2Nt}), to be the distribution of the count of allele A in generation t. Using equation (5), dt can be computed recursively as

dt=dr[g=r+1tTg1,g] (6)

for r < t.

Computing the Probability PΘ,W{O[1:K]=o[1:K]}

The probability PΘ,W{O[1:K]=o[1:K]} of the observed data is computed using the forward procedure for hidden Markov models. In particular, we define the vector vk whose ith entry vk,i is the joint probability of the population-wide count of allele A at the kth sampling event and the observed sample allele counts up to sample k:

vk,i=PΘ,W{O[1:k]=o[1:k],Ctk=i}. (7)

To simplify calculations, we also define the conditional “emission probability”

γi(ok)=PΘ{Ok=ok|Ctk=i}=(nkok)(i/2Ntk)ok(1i/2Ntk)nkok (8)

of the observed allele count, conditional on the population allele count. The probability in equation (8) comes from the fact that the observed allele count at time tk can be modeled as a binomial random variable with sample size nk and probability ctk. Although the observed allele count is, strictly speaking, hypergeometric we use the binomial distribution to maintain consistency with the formulas for the diffusion model, which are often derived using a binomial sampling distribution. The binomial and hypergeometric distributions are very similar for the population and sample sizes we consider. We then construct the emission probability vector

γ(ok)=(γ0(ok),γ1(ok),,γ2Ntk(ok)). (9)

The probability of the data is then given by the forward procedure (Rabiner 1989), outlined in Procedure 1. In Procedure 1, the formula for v1 comes from the fact that

v1=(PΘ,W{O1=o1,Ct1=0},,PΘ,W{O1=o1,Ct1=2Nt1})=(γ0(o1)PΘ,W{Ct1=0},,γ2Nt1(o1)PΘ,W{Ct1=2Nt1})=dt1diag{γ(o1)}=d0[t=1t1Tt1,t]diag{γ(o1)}, (10)

where diag(γ) denotes the square matrix whose diagonal entries are given by γ.

It has been noted by several authors that computing powers of the transition matrix is computationally prohibitive, providing one motivating factor for the use of approximations of the Wright–Fisher process, such as the diffusion and Gaussian approximations (Ewens 1963; Feder et al. 2014; Lacerda and Seoighe 2014). However, the products t=tk1+1tkTt1,t in Procedure 1 do not require products of the transition matrix Tt1,t because it suffices to repeatedly compute vector–matrix products instead of multiplying full matrices together. In practice, this can be done very quickly, even for large population sizes. A similar fast procedure was carried out by Zhao et al. (2014) to simulate trajectories under the Wright–Fisher model.

Computing PΘ,W{O[1:K]=o[1:K]} When d0 Is Unspecified

When the initial distribution d0 is unspecified, the probability PΘ,W{O[1:K]=o[1:K]} can be obtained by assuming that the distribution dt1 is uniform at the time of the first sampling event. Under this assumption, it follows directly from the second to last equality in equation (10) that the value of the joint density vector v1 is given by

v1=12Nt11diag{γ(o1)}=12Nt1γ(o1), (11)

where 1 is the vector of length 2Nt1 with all entries equal to one. This form of v1 can then be substituted into Procedure 1.

Computing PΘ,D{O[1:K]=o[1:K]} under the Diffusion Approximation

The diffusion approximation models the evolution of the continuous population frequency Yt of allele A, rather than its count Ct. The time-evolution of the random frequency Yt is governed by the diffusion transition density pΘ(s,t;x,y) given by

pΘ(s,t;x,y)dy=PΘ,D{yYt<y+dy|Ys=x}, (12)

for an infinitesimal increment dy. The quantity pΘ(s,t;x,y) specifies the density of the allele frequency at time t, conditional on the value of the allele frequency at an earlier time s. For more details about the transition density function of the diffusion approximation, see Appendix A.

Using the diffusion transition density pΘ(s,t;x,y) Steinrücken et al. (2014) developed an HMM to compute the probability PΘ,D{O[1:K]=o[1:K]} of the data in a single epoch of constant size by efficiently integrating over the hidden allele frequencies {yt1,,ytK} at the set of sampling times. Here, we extend this HMM to the case of piecewise-constant population size.

To compute the probability PΘ,D{O[1:K]=o[1:K]} efficiently, Steinrücken et al. (2014) define the quantities fk(y) and gk(y) satisfying

fk(y)dy:=PΘ,D{O[1:k]=o[1:k],yYtk<y+dy}, (13)

and

gk(y)dy:=PΘ,D{O[1:k1]=o[1:k1],yYtk<y+dy} (14)

for an infinitesimal increment dy. The quantity fk(y) is the joint density of the allele frequency at time tk and the observed counts up to sampling event k. The quantity gk(y) is the joint density of the allele frequency at time tk and the observed counts up to sampling event k – 1.

It follows from the definition of fk(y) that the probability of the data is given by

PΘ,D{O[1:K]=o[1:K]}=y=01fK(y)dy. (15)

The quantity fK(y) can be obtained efficiently by recursion using the relationships

fk(y)=gk(y)(nkok)yok(1y)nkok, (16)

and

gk(y)=z=01fk1(z)pΘ(tk1,tk;z,y)dz. (17)

Equation (16) follows from the fact that the observed number of copies of allele A at sampling event k is binomially distributed with count nk and probability ytk and equation (17) follows from the law of total probability integrating over Ytk1.

Let B,i(y) (i=0,1,) be the ith eigenfunction of the backward diffusion operator and let π(y) be the speed density of in Epoch (Appendix A). Steinrücken et al. (2014) demonstrated that the recursive formulas in equations (16) and (17) can be evaluated efficiently by expressing fk(y) and gk(y) as series of the form

fk(y)=i=0bk,iπk(y)Bk,i(y)=bkπk(y)Bk(y) (18)

and

gk(y)=i=0ak,iπk(y)Bk,i(y)=akπk(y)Bk(y), (19)

where B(y)=(B,0(y),B,1(y),), and where bk=(bk,0,bk,1,) and ak=(ak,0,ak,1,) are vectors of constants that encode the densities fk(y) and gk(y). In Appendix B, we extend the results of Steinrücken et al. (2014) to derive recursive formulas for the coefficients ak and bk, resulting in Procedure 2, which computes the probability of an allele frequency trajectory under the diffusion approximation in a population of piecewise constant size.

Computing PΘ,D{O[1:K]=o[1:K]} When y0 Is Unspecified

When the initial frequency y0 is unspecified, the probability PΘ,D{O[1:K]=o[1:K]} can be obtained by assuming that the distribution of the allele frequency yt1 at the time of the first sampling event is uniform. Under this assumption, we show in Lemma B.3.2 that the coefficients b1 encoding the distribution at the time of the first sampling event are given by equation (B.17). The form of b1 in equation (B.17) is then used in Procedure 2.

Conditional Probabilities

Sometimes it is desirable to compute the probability of the observed allele counts conditional on the event SK that allele A is segregating in the final sample. In this section, we provide formulas for these conditional probabilities under the Wright–Fisher and diffusion models.

Computing PΘ,W{O[1:K]=o[1:K]|SK}

In the “Simulations Conditioning on Segregation” section, we consider the probability PΘ,W{O[1:K]=o[1:K]|SK} of the data conditional on the event SK that allele A is segregating in the final sample. In Appendix C, we show that in the case of the discrete Wright–Fisher model,

PΘ,W{O[1:K]=o[1:K]|SK}=P{SK|OK=oK}PΘ,W{SK}i=02NtKvK,i, (20)

where vk,i is defined in equation (7) and P{SK|OK=oK}=1 if 1oK<nK, or 0 otherwise. The probability PΘ,W{SK} is given in equation (C.3). Thus, if we wish to compute conditional probabilities under the Wright–Fisher model, we carry out Procedure 1, replacing step 3 with equation (20).

Computing PΘ,W{O[1:K]=o[1:K]|FK}

Similarly, for the event FK that allele A is segregating or fixed in the final sample, we show in Appendix C that

PΘ,W{O[1:K]=o[1:K]|FK}=P{FK|OK=oK}PΘ,W{FK}i=02NtKvK,i, (21)

where vk,i is defined in equation (7) and P{FK|OK=oK}=1 if 1oKnK, or 0 otherwise. The probability PΘ,W{FK} is given in equation (C.6). If we wish to compute the conditional probability PΘ,W{O[1:K]=o[1:K]|FK} under the Wright–Fisher model, we carry out Procedure 1, replacing step 3 with equation (21).

Computing PΘ,D{O[1:K]=o[1:K]|SK}

In the case of the diffusion approximation, we show in Appendix D that the conditional probability of the data given SK can be computed as

PΘ,D{O[1:K]=o[1:K]|SK}=P{SK|OK=oK}cK,0bK,0BK,0(0)cK,0b˜K,0(0)cK,0b˜K,0(nK), (22)

where P{SK|OK=oK}=1 if 1oK<nK or 0 otherwise, and

b˜K(j)={b0E1(tK)WKGKj(1GK)nKjWK1,iftK=1,b0F(0,tK;ζ)WKGKj(1GK)nKjWK1,otherwise.  (23)

Thus, if we are interested in conditional probabilities under the diffusion model, we carry out Procedure 2, replacing step 3 with equation (22).

The Probability in the Absence of Genetic Drift

If we ignore genetic drift, the allele frequency changes deterministically over time, as it would in a population of infinite size. Here, we obtain versions of Procedures 1 and 2 in the case when the changes in allele frequency arising from genetic drift are negligible relative to the changes due to selection and recurrent mutation.

Deterministic Allele Frequency Trajectories under the Wright–Fisher Model

If there is no contribution to the change in allele frequency arising from genetic drift, the allele frequency in a given generation is equal to its expectation after mutation, random mating, and selection, conditional on its value in the previous generation. Because the expectation is not necessarily integer-valued, we no longer consider discrete integer allele counts ct. Instead, we track the expected allele frequency in the absence of drift, which we denote by ytE[Yt], where the subscript ∞ denotes the expectation without drift as the effective population size tends to infinity.

The expected frequency yt in the absence of drift is obtained by combining equations (2) and (3), ignoring the drift step in equation (4), yielding

yt+1=[(y˜t)2(1+st)+y˜t(1y˜t)(1+htst)w¯t], (24)

where

y˜t=uaA(t)+(1uAa(t)uaA(t))yt (25)

and w¯t=(y˜t)2(1+st)+2y˜t(1y˜t)(1+htst)+(1y˜t)2. Equations (24) and (25) are iterated to find the allele frequency in any generation t > 0.

Equation (24) is related to equation 3.1 of Gillespie (1998), which describes the dynamics of allele frequency change in a population of infinite size without drift. The frequency trajectories described by this formula are closely approximated by logistic curves that have closed formulas (Feder et al. 2014, equation 3), which can be used to increase the speed of deterministic approaches even further. However, we have chosen to implement the exact formulas for better comparison with the exact likelihoods.

Deterministic Allele Frequency Trajectories under the Diffusion Model

Under the diffusion model in an Epoch of constant size, the allele frequency Yt obeys the stochastic differential equation (SDE)

dYt=M(Yt)dt+Yt(1Yt)dBt,t[τ1,τ], (26)

with the initial condition Yτ1=yτ1, where time is measured in units of generations and τ1 is the time at which Epoch begins (Karlin and Taylor 1981, Section 15.14; Durrett 2008, Section 7.2). The quantity Yt(1Yt) in equation (26) controls random fluctuations due to drift whereas the quantity M(y) describes the deterministic change in the mean frequency of the allele over time due to mutation and selection and is given by

M(y)=uaA()(uaA()+uAa())y+y(1y)[hs(12y)+sy]. (27)

In equation (27), we have rescaled the usual form of M so that time is measured continuously in units of generations.

If the drift term in equation (26) is negligible compared with M(Yt), then equation (26) can be approximated by the ordinary differential equation

dytdt=M(yt), (28)

where we may write yt instead of Yt because the evolution of the allele frequency is deterministic and follows its expectation in the absence of drift.

We can also suppress the explicit dependence on the epoch by defining Mt(yt)Mt(yt), yielding

dytdt=Mt(yt),y0=y0,t[0,τL], (29)

which holds for the full population history across all epochs =1,,L. Equation (29) can be solved numerically, for instance by choosing a sufficiently small time step t and iteratively computing yt+t=Mt(yt)t.

Sample Probabilities Based on Deterministic Allele Frequency Trajectories

To compute the probability PΘ{O[1:K]=o[1:K]} under either the discrete Wright–Fisher or diffusion models when drift is negligible, we note that the observations (O1,,OK) are conditionally independent of one another, given the underlying allele frequencies. Thus, in the absence of drift we have

PΘ{O[1:K]=o[1:K]}=k=1KPΘ{Ok=ok|Ytk=ytk} (30)

for both the diffusion and Wright–Fisher models, where ytk is the deterministic allele frequency at time tk, for k=1,,K. Using equations (24) and (30), the probability of the data under the Wright–Fisher model in a population without drift can be obtained using Procedure 3. Similarly, using equations (29) and (30), the probability of the data in the case of the diffusion model is given by Procedure 4.

Deterministic Estimators When the Initial Allele Frequency Is Unknown

If the initial allele frequency is unspecified, the selection coefficient can still be inferred using the deterministic estimators by integrating over the allele frequency yt1 at the time of the first sampling event, where we assume in these analyses that the initial allele frequency distribution is uniform. In practice, we perform this integration by specifying a dense grid of values yt1[0,y,2y,,1], where y=1/M for some large predetermined value M. Defining the probability of the data when the initial allele frequency is y to be PΘ,W{O[1:K]=o[1:K];y0=y}, we compute the probability of the data as

PΘ,W{O[1:K]=o[1:K]}=1M+1j=0MPΘ,W{O[1:K]=o[1:K];y0=jy}. (31)

Simulations

Allele frequency trajectories were simulated under two different models, the discrete Wright–Fisher model and the continuous diffusion model. All simulations were carried out by iteratively sampling the allele frequency at the time points t1,t2,,tK starting with a specified frequency y0 or with the initial frequency y0 sampled uniformly from the interval (0,0.5] at time t0=0.

Wright–Fisher simulations were carried out using Procedure 5. Specifically, for an initial allele frequency y0, we took the initial distribution d0 to be the standard basis vector ey0 of length 2N0+1 with element 2N0y0 set to unity and all other elements set to zero. We then sampled the population allele count ctk at each sampling time tk by iteratively propagating the allele frequency distribution dtk forward, conditional on the population count ctk1 at the previous sampling time using equation (6). The derived allele count ok in each sample k was then chosen from a binomial distribution with sample size nk and probability ctk/2Ntk. For the results in the “Inference Accuracy for Populations of Constant Finite Size”, “Inference Accuracy in Populations of Piecewise Constant Size”, “Conditioning on Segregation in the Final Sample”, and “The Effect of Sample Size on Accuracy” sections, we fixed y0=0.01 or y0=0.1 in all simulations, as indicated in the results section. In the “Unspecified Initial Allele Frequencies” section, we simulated y0 uniformly from the interval (0,0.5].

Simulations under the diffusion model were carried out using Procedure 6. Specifically, for an initial frequency y0, we computed the coefficients b0 of the expansion of the initial condition δ(yy0) in the basis functions B1 of the first epoch. In Appendix D, we show that the probability PΘ,D{Ok=i} of sampling i derived alleles at sampling event k (eq. D.3) can be obtained by computing a set of coefficients that we call b˜k(i) (eq. D.7) that specify an expansion in the basis of eigenfunctions Bk.

Thus, to sample the derived allele count o1 in the first sample, we propagated the initial coefficients b0 to obtain b˜1(i) and we used the fact that PΘ,D{O1=i}b˜1,0(i) (eq. D.3) to sample o1=i with probability b˜1(i)/i=0n1b˜1(i). Using the fact that b˜k(ok) is defined in Section D as the set of coefficients such that PΘ,D{Ok=ok,yYtk<y+dy}=b˜k(ok)πkBk(y) for an infinitesimal increment dy, we then set b1=b˜1(ok) and iterated this procedure to obtain the subsequent coefficient vectors {b˜k(i)}i=2nk and the full set of samples o[1:K]. Simulated trajectories were checked for accuracy against those obtained using the software of Jenkins and Spanò (2015), personal communication.

Grid Searches to Infer Selection Coefficients

The same iterated grid search procedure, implemented as a wrapper function and outlined in Procedure 7, was used to infer selection coefficients using each of the methods described in Procedures 1–4. The grid search is initialized by specifying lower and upper bounds on a region [s,su] over which to search for a value of the selection coefficient s that maximizes the likelihood. Assuming that the likelihood surface is convex and smooth, the grid search iteratively refines the search to the region that contains the optimum until the width of the region is smaller than a specified tolerance ϵ. In our analyses, we chose the initial region to be [s,su]=[0.99,1] and we set ϵ=2·104.

For each allele frequency trajectory simulated under the Wright–Fisher model, Procedure 7 was carried out using Procedure 1 and then subsequently for the same trajectory using Procedure 3, with or without conditioning. For each allele frequency trajectory simulated under the diffusion model, Procedure 7 was carried out using Procedure 2 and then subsequently for the same trajectory using Procedure 4, with or without conditioning. A gradient descent optimization approach produced nearly identical results and is available as an option in the software package we have released.

Computing the Watterson Estimator of Ne from the Expected SFS of a Piecewise Constant Population

In the “Inference Accuracy in Populations of Piecewise Constant Size” section, we obtain a crude constant estimate of the effective size Ne of a piecewise constant population by computing the expected unnormalized SFS for the true history and then inferring the effective size of a constant population with the same level of genetic diversity as the piecewise constant population using the Watterson estimator.

Under the assumption that any given base pair in a collection of n haplotypes from a population is at most biallelic, the unnormalized and folded SFS for the n haplotypes is a collection of counts {ξn,i}i=1n1 in which ξn,i is the number of sites with one or the other allele appearing in i out of n copies in the sample. When the expected number μ of new mutations occurring in a population within in a region of fixed length is specified, the expected SFS for n haplotypes spanning the region can be computed for a population of piecewise constant size using algorithms by Kamm et al. (2016).

The effective size of a population of constant size extending infinitely far back into the past with the same level of diversity as the piecewise constant population can be computed using the Watterson estimator (Watterson 1975, Eqn. 1.4a; Hein et al. 2005, p. 62). The information used by the Watterson estimator is the diversity in the n sampled haplotypes of specified length, combined with knowledge of the expected mutation rate μ. The Watterson estimator is given by

Nˆe=14μSi=1n1i, (32)

where S is the total number of segregating sites observed in the sample. The total number of segregating sites can be computed as S=i=1n1ξn,i, where ξn,i is the ith entry of the un-normalized folded SFS.

Thus, given the expected SFS {ξn,i}i=1n1 for a piecewise constant population computed using the algorithm of Kamm et al. (2016) and a specified mutation rate μ, we computed the Watterson estimate of the size Ne of a constant-sized population with similar diversity as

Nˆe=14μi=1n1ξn,ii=1n1i. (33)

When computing the expected SFS and the Watterson estimator, we arbitrarily chose a value of μ  = 1.

Procedure 5. Sampling Wright–Fisher trajectories

1: Optional: sample the initial population allele frequency y0 uniformly from a predetermined interval (y,yu], where 0yyu1, and set ct0=2N0y0.

2: Let d0=ect0 be the standard basis vector of length 2N0+1 with element ct0 equal to one.

3: For k=1:K,

Compute the conditional distribution d˜k at sampling event k, conditional on the distribution dk1 at time tk1 using

d˜k=dk1[t=tk1+1tkTt1,t].

Sample ctk=i with probability d˜k(i), for i=0,1,,2Ntk.

Set dk=ectk, where ectk is the standard basis vector of length 2Ntk+1 with element ctk equal to one.

4: Fork=1:K, sample OkBinomial(nk,ctk/(2Ntk)).

5: If conditioning on segregation in the final sample and oK = 0 or oK =nK, return to Step 1. Otherwise, the sampled trajectory is o[1:K].

Procedure 6. Simulating diffusion model trajectories

1: Optional: sample the initial population allele frequency y0 uniformly from a predetermined interval (y,yu], where 0yyu1.

2: For an initial starting frequency y0 initialize

b0=C11B1(y0),

where B(y0) is the vector of eigenfunctions of the diffusion operator given inequation (A.14) and C=diag{B,i,B,i}i=0 is given in equation(A.18).

3: For k=1:K,

Compute

ak ={bk1Ek(tktk1)ifk1=k,bk1F(tk1,tk;ζ)otherwise.  

For i=0,1,,nk, compute

b˜k(i)=akWkGki(1Gk)nkiWk1,

noting that b˜k,0(i)PΘ,D{Ok=i} (eq. D.3).

Sample ok = i with probability bk,0(i)/i=0nkbk,0(i).

Set bk=bk(ok).

Here, the matrices E(t),F(tk1,tk;ζ),W, and G are given by equations (A.17), (B.10), (A.15) and (A.11), respectively and ζ is the set of Chebyshev nodes in the interval [0,1]. The matrix inverse W1=DWTC1 is computed easily using the diagonal matrices C and D in equations (A.18) and (A.19).

4: If conditioning on segregation in the final sample and oK = 0 or oK =nK, return to Step 1. Otherwise, the sampled trajectory is o[1:K].

Procedure 7. Grid search

1: Specify the bounds s and su of an interval [s,su]in which to search.

2: Specify the stopping tolerance ε.

3: While sus>ε:

Evaluate the likelihood at the points {s(0),s(1),s(2),s(3),s(4),s(5)}={s+iδ}i=05, where δ=(sus)/5.

Let smax=argmaxi{s(i)}.

If smax=0, set s=s(0) and su=s(1).

Else, if smax=5, set s=s(4) and su=s(5).

Else, set s=s(smax1) and su=s(smax+1).

4: Return sˆ=(s+su)/2.

Supplementary Material

Supplementary figure S1 is available at Molecular Biology and Evolution online (http://www.mbe.oxfordjournals.org/).

Supplementary Data

Acknowledgments

This research was supported by the National Institutes of Health (grant number R01-GM094402) and by a Packard Fellowship for Science and Engineering. We would also like to thank Jeffrey Spence, Joshua Schraiber, and an anonymous reviewer for their helpful comments on this manuscript.

Appendix A

Diffusion Transition Densities: Background

The equations in the “Computing PΘ,D{O[1:K]=o[1:K]} under the Diffusion Approximation” section were derived under a model in which the selected allele A evolves under the diffusion approximation in a population of piecewise constant size. Given that allele A has frequency x at a fixed time s, the density at a later time t is given by the transition density of the diffusion approximation (eq. 12). Steinrücken et al. (2014) derived a formula for the density for the case of a single population of constant size. Here, we review this derivation to provide background and notation for the derivation of the diffusion model probability computed in Procedure 2.

The Diffusion Approximation in a Population of Constant Size

Let p(s,t;x,y) denote the transition density restricted to a specific epoch of constant size with s,t. The density p(s,t;x,y) is the unique solution of the Kolmogorov backward equation,

p(s,t;x,y)t=12NLp(s,t;x,y) (A.1)

satisfying the terminal condition ρs(y)=δ(yx), where δ(·) is the Dirac delta distribution and L is the Kolmogorov backward operator in the epoch defined in equation (A.2). The factor 1/2N in equation (A.1) is introduced so that the time-scaling is the same in all epochs, and time is measured continuously in units of generations.

The Kolmogorov backward operator is defined in terms of the scaled mutation and selection parameters β=4NuaA(),α=4NuAa(), and σ=Ns as

L=12ξ2(x)2x2+μ(x)x, (A.2)

where the quantity

ξ2(x)=x(1x) (A.3)

captures the contribution to the change in allele frequency arising from genetic drift and

μ(x)=12[β(β+α)x]+2x(1x)[hσ(12x)+σx] (A.4)

captures the contribution from recurrent mutation and selection.

Song and Steinrücken (2012) showed that p(s,t;x,y) can be expressed as an expansion in the eigenfunctions of L of the form

p(s,t;x,y)=n=0eλ,n(ts)/2Nπ(y)B,n(x)B,n(y)B,n,B,nπ, (A.5)

where {B,n(x)}n=0 are the eigenfunctions of with associated eigenvalues {λ,n}n=0 and the function π(y) is given by

π(y)=eσ¯(y)yβ1(1y)α1, (A.6)

where σ¯(y)=4hσy(1y)+2σy2. The inner product f,gω with respect to a weight function ω(x) in equation (A.5) is defined for two functions f and g on an interval [a,b] by

f,gω=abf(x)g(x)ω(x)dx. (A.7)

In equation (A.5), the inner product ·,·π is taken over the interval [0,1] with respect to π(y).

Expressions for the Quantities in Equation (A.5)

Expressions for the eigenvalues {λ,n}n=0, eigenfunctions {B,n(y)}n=0, and inner products {B,n,B,n}n=0 in equation (A.5) can be obtained using a matrix formulation developed by Steinrücken et al. (2014). In particular, the eigenfunctions {B,n(y)}n=0 can be expressed as

B,n(y)=m=0w,n,meσ¯(y)/2Rm(β,α)(y), (A.8)

where Rm(α,β)(y)=pm(β1,α1)(2y1) and pm(a,b)(y) is the mth classical Jacobi polynomial (Abramowitz and Stegun 1972, Chapter 22). The vector w,n=(w,n,0,w,n,1,) is the nth left eigenvector of the infinite-dimensional matrix

M:=(Υ(α,β)+r=04q,rGr) (A.9)

corresponding to the nth eigenvalue λ,n, where Υ(α,β)=diag(υ0(α,β),υ1(α,β),) is the diagonal matrix with elements given by υn(α,β)=12n(n+α+β1) and the quantities q,r are given by

q,0=αkhσ,q,1=(2+3α+β2hσ)hσ+(1+α)σ,q,2=(2+2α+2β+4σ10hσ)hσ(1+α+β)σ,q,3=16h2σ2+2σ2(16h),q,4=2σ2(12h)2. (A.10)

The matrix Gr in equation (A.9) has elements given by

[G]n,m ={(n+α1)(n+β1)(2n+α+β1)(2n+α+β2),ifm=n1andn>0,12β2α22(βα)2(2n+α+β)(2n+α+β2),ifm=nandn0,(n+1)(n+α+β1)2(2n+α+β)(2n+α+β1),ifm=n+1andn0,0,otherwise,  (A.11)

which correspond to the coefficients of the three-term recurrence relation satisfied by the Jacobi Polynomials.

Matrix Expressions for the Transition Density

It is computationally and notationally simpler to express the eigenfunctions of L and the transition density as products of matrices. In particular, we can express equation (A.8) as

B,n(y)=eσ¯(y)/2w,nR(α,β)(y), (A.12)

where

R(α,β)(y)=(R0(α,β)(y),R1(α,β)(y),)T (A.13)

and we can express the vector B(y) of eigenfunctions as

B(y)=(B,0(y),B,1(y),)T=eσ¯(y)/2WR(α,β)(y), (A.14)

where

W=[w,0w,1] (A.15)

is the matrix whose rows are the left eigenvectors of the matrix M in equation (A.9).

Using equations (A.5) and (A.14), the transition density in a single epoch ℓ can then be expressed as the matrix product

p(s,t;x,y)=π(y)BT(x)C1E(ts)B(y), (A.16)

where

E(t)=diag{eλ,0t/2N,eλ,1t/2N,} (A.17)

and C=diag{B,n,B,nπ}n=0. Steinrücken et al. (2014) showed that the matrix C in equation (A.16) can be expressed as

C=WDWT, (A.18)

where

D=diag{d0(α,β),d1(α,β),} (A.19)

and

di(α,β)=Γ(i+α)Γ(i+β)(2i+α+β1)Γ(i+α+β1)Γ(i+1). (A.20)

Thus, the transition density in a single epoch can be computed by constructing matrix M, computing its eigenvectors W and eigenvalues (λ,0,λ,1,), and plugging these into the components of equation (A.16). In practice, because the matrix M has infinite dimension, we approximate it by truncating its dimensions at some large integer M yielding approximate eigenvectors {w˜,n}n=0M and eigenvalues {λ˜,n}n=0M. We also truncate the length of the vector B(y) at a large integer N. Although these truncations lead to approximate values of the transition density, the approximation can be made arbitrarily precise by taking NM to be sufficiently large.

Appendix B

Recursions for the Coefficients ak and bk

Discussion of the Problem

Here, we extend the HMM of Steinrücken et al. (2014) to accommodate populations of piecewise constant size. As we noted in the “Computing PΘ,D{O[1:K]=o[1:K]} under the Diffusion Approximation” section, the probability PΘ,D{O[1:K]=o[1:K]} of the data under the diffusion model can be obtained using the equation

PΘ,D{O[1:K]=o[1:K]}=y=01fK(y)dy, (B.1)

where the quantity fK(y) is obtained by recursively evaluating equations (16) and (17). Because fk(y) and gk(y) can be expressed as the series fk(y)=πk(y)bkBk(y) and gk(y)=πk(y)akBk(y) (eqs. 18 and 19), determining fk(y) and gk(y) amounts to determining the coefficients ak and bk. Thus, it is useful to develop analogs of the recursions (15) and (16) that apply to the coefficients themselves.

Equations for Propagating Coefficients

From equation (16), it can be seen that obtaining fk(y) from gk(y) involves only multiplication by a polynomial in y. Thus, the formula for obtaining the coefficients bk from the coefficients ak does not depend on the population history and, therefore, it can be obtained from results in Steinrücken et al. (2014) who derived formulas for the recursion for the case of a population of constant size. However, the formula for obtaining gk(y) from fk1(y) (eq. 17) involves the transition probability pΘ(tk1,tk;z,y), which depends on the population parameters Θ. Thus, it is necessary to account for the population history when computing the coefficients ak from the coefficients bk1.

To obtain ak from bk1, we first consider the more general problem of obtaining the generalized vector of coefficients ak(t) from bk1, where ak(t) is defined as the vector of coefficients of the expansion of the generalized density gk(y,t) defined by

gk(y,t)dy:=PΘ,D{O[1:k1]=o[1:k1],yYt<y+dy}=πt(y)ak(t)Bt(y), (B.2)

i.e., the joint density of the observed data up to sample k – 1 and the allele frequency at time t, where we assume tk1t so that the time t at which gk(y,t) is evaluated occurs later than the time tk1 at which fk(y) is evaluated. The density gk(y)=gk(y,tk) defined in equation (14) is a special case of the generalized density gk(y,t) obtained when t = tk.

To obtain ak(t) from bk1, there are two scenarios to consider: the case in which both tk1 and t lie within the same epoch and the case in which tk1 and t lie within distinct epochs. Our derivations of these separate cases provide the results necessary for step 2 of Procedure 2.

The Case tk1=t=

If both tk1 and t lie within the same epoch , then the transition density is given by equation (A.16) and we have

π(y)ak(t)B(y)=gk(y,t)=01fk1(z)p(tk1,t;z,y)dz=01π(z)bk1B(z)π(y)BT(z)C1×E(ttk1)B(y)dz=π(y)bk1[01π(z)B(z)BT(z)dz]×C1E(ttk1)B(y)=π(y)bk1E(ttk1)B(y), (B.3)

where the first equality follows from the definition of gk(y,t) (eq. B.2) and the second equality follows from equation (17). In the fifth equality we have used the fact that 01π(y)B(y)BT(y)dy=C. Because the eigenfunctions {B,n(y)}n=0 form a complete basis of the Hilbert space defined with respect to the inner product ·,·π, the coefficients in the expansion on the left-hand side of equation (B.3) must equal those on the right-hand side. Thus,

ak(t)=bk1E(ttk1),iftk1=t. (B.4)
The Case When tk1t

If the times tk1 and t lie in different epochs, tk1 and t, then the transition density is no longer given by equation (A.16). Instead, we must use a formula for the transition density across multiple epochs of different sizes. Steinrücken et al. (2015) showed that if the allele frequency density ρ,s(y) at time s in epoch is given by the expansion

ρ,s(y)=π(y)r,sB(y), (B.5)

where r,s=(r,s,0,r,s,1,) are the coefficients encoding the density at time s in the basis of the eigenfunctions {B,n(y)}n=0, then at time t in epoch +1, the allele frequency density is given by ρ+1,t(y)=π+1(y)r+1,tB+1(y), where the coefficients r+1,t are given by

r+1,t=r,sZ(τs;ζ)E+1(tτ), (B.6)

where τ is the time of the terminating boundary of epoch , and

Z(τ;ζ)=E(τ)WR(ζ)H,+1(ζ)R+11(ζ)W+11. (B.7)

In equation (B.7), R(ζ) and H,+1(ζ) are given by

R(ζ)=[R(α,β)(ζ0),R(α,β)(ζ1),], (B.8)

where Rα,β(y) is defined in equation (A.13) and

H,+1(ζ)=diag {π(ζ0)eσ¯(ζ0)/2π+1(ζ0)eσ¯+1(ζ0)/2,  π(ζ1)eσ¯(ζ1)/2π+1(ζ1)eσ¯+1(ζ1)/2,}, (B.9)

for an arbitrary collection of distinct values ζ=(ζ0,ζ1,)[0,1]. In practice, we take ζ to be the Chebyshev nodes (Steinrücken et al. 2015).

By repeated application of equation (B.6), it follows that if the coefficients rs,s encode the density ρs(y) at time s in epoch s, then the coefficients rt,t encoding the density ρt(y) at time t in epoch t>s are given by rt,t=rs,sF(s,t;ζ), where

F(s,t;ζ)=Zs(τss;ζ)[i=s+1t1Zi(τiτi1;ζ)]×Et(tτt1). (B.10)

Moreover, if we define rs,s(x) to be the vector of coefficients encoding the density ρ(y)=δ(yx), then it follows from equation (B.10) that the transition density pΘ(s,t;x,y) for times s < t lying in distinct epochs s<t is given by

pΘ(s,t;x,y)=πt(y)rs,s(x)F(s,t;ζ)Bt(y),ifs<t. (B.11)

For the initial condition ρ,s(y)=δ(yx), it was shown in Proposition 1 of Steinrücken et al. (2014) that the coefficients rs,s(x) are given by

rs,s(x)=(Bs,0(x)Bs,0,Bs,0πs,Bs,1(x)Bs,1,Bs,1πs,)=Bs(x)TCs1, (B.12)

yielding

pΘ(s,t;x,y)=πt(y)Bs(x)TCs1F(s,t;ζ)Bt(y),ifs<t, (B.13)

which is obtained by plugging equation (B.12) into equation (B.11).

We can now plug equation (B.13) into equation (17) to obtain a relationship between ak(t) and bk1 when times tk1 and t lie in different epochs:

πt(y)ak(t)Bt(y)=gk(y,t)=01fk1(z)pΘ(tk1,t;z,y)dz=01πk1(z)bk1Bk1(z)πt(y)Bk1(z)TCk11F(tk1,t;ζ)Bt(y)dz=πt(y)bk1 [01πk1(z)Bk1(z) Bk1(z)Tdz]Ck11F(tk1,t;ζ)Bt(y)=πt(y)bk1F(tk1,t;ζ)Bt(y), (B.14)

where we have again used the fact that 01π(z)B(z)B(x)Tdy=C. Finally, by the uniqueness of expansions in the Hilbert basis {Bt,n}n=0, we have

ak(t)=bk1F(tk1,t;ζ),iftk1t. (B.15)

The results derived in the “Equations for Propagating Coefficients” section provide the machinery necessary to propagate the coefficients ak and bk in the HMM over time. These results can now be used to compute the probability of observing a set of sampled allele frequencies under the diffusion model.

Derivation of Lemmas Necessary for Procedure 2

We now obtain three lemmas that provide the steps in Procedure 2.

Lemma B.3.1

If the initial frequency density ρ0(y) at time t0=0 is ρ0(y)=δ(yx), then the value of the initial vector b0 encoding the quantity f0(y) is given by

b0=(B1,0(x)c1,0,B1,1(x)c1,1,)=C11B1(x), (B.16)

where B(x) is given in equation (A.14) and C is the diagonal matrix given in equation (A.18).

Proof

Because b0 depends only on the parameters Θ1 in the first epoch, the proof of Lemma B.3.1 is the same whether we consider a population composed of a single epoch, or a population composed of multiple epochs. The equation for fk(y) (eq. 18) is the same as equation 2.14 of Steinrücken et al. (2014). Thus, the coefficients bk in this paper correspond to the coefficients bk in Steinrücken et al. (2014) who proved Lemma B.3.1 for the case of a population of constant size. Thus, the first equality in Lemma B.3.1 follows directly from Proposition 1 of Steinrücken et al. (2014). The matrix representation in the second equality follows directly from the definitions of C and B(x). □

Lemma B.3.2

If the initial frequency density ρ0(y) at time t0=0 is unspecified and we instead assume a uniform prior on the allele frequency at the time of the first sampling event, then the coefficients b1 encoding the density at time t1 are given by

b1=1Beta(o1+1,n1o1+1)B(σ1,o1+1,n1o1+1),0(0)×C(σ1,o1+1,n1o1+1)W(σ1,o1+1,n1o1+1)×D(σ1,o1+1,n1o1+1)W(σ1,o1+1,n1o1+1)T×Z(σ1,o1+1,n1o1+1),(σ1,α1,β1)(0;ζ), (B.17)

where C(σ,α,β),D(σ,α,β), and W(σ,α,β) are obtained by replacing σ,α, and β in equations (A.18), (A.19), and (A.15) with σ, α, and β. Similarly, Z(σ,α,β),(σ˜,α˜,β˜)(τ;ζ) is obtained by replacing σ,σ+1,α,α+1,β, and β+1 in equation (B.7) with σ, σ˜, α, α˜, β, and β˜, respectively, B(σ,α,β)(0) is the eigenfunction in equation (B.23) with σ,α, and β replaced with σ, α, and β, and W(σ,α,β) is the matrix given in equation (A.15) whose rows are the left eigenvectors of M(σ,α,β), i.e., the matrix in equation (A.9) with σ,α, and β replaced with σ, α, and β. Finally, Beta(α,β)=Γ(α)Γ(β)/Γ(α+β) is the normalizing constant of the beta distribution with parameters α and β.

Proof

If the initial density ρ0(y) of the allele frequency is unspecified, then the density of Yt1 at the time t1 of the first sampling event, conditional on the observed number o1 of copies of allele A is given by Bayes Theorem:

fYt1|O1(y|o1)=P{O1=o1|Yt1=y}fY1(y)P{O1=o1}. (B.18)

If we suppose that fYt1(y) is uniform on the interval [0,1] then equation (B.18) becomes

fYt1|O1(y|o1)=(n1o1)yo1(1y)n1o1y=01P{O1=o|Yt1=y}fYt1(y)dy=(n1o1)yo1(1y)n1o1y=01(n1o1)yo1(1y)n1o1dy=yo1(1y)n1o1y=01yo1(1y)n1o1dy=yo1(1y)n1o1Beta(o1+1,n1o1+1), (B.19)

where, in the final equality, we have used the fact that yo1(1y)n1o1 is the unnormalized beta distribution with parameters o1+1 and n1o1+1. Thus, conditional on the first observation o1, we see that Yt1|O1 has a beta distribution with parameters o1+1 and n1o1+1.

Steinrücken et al. (2014) showed in Appendix C of their paper that the distribution ρ(y)=yα1(1y)β1Beta(α,β) has coefficients given by

bσ,α,β=1Beta(α,β)B(σ,α,β),0(0)C(σ,α,β)W(σ,α,β)D(σ,α,β)W(σ,α,β)T

in an epoch with selection parameter σ and mutation parameters α and β. Thus, using the change of basis in equation (B.6), we see that the distribution ρ(y)=yα1(1y)β1Beta(α,β) has coefficients given by bσ,α,βZ(σ,α,β),(σ,α,β)(0;ζ) in the basis of eigenfunctions {B,n(y)}n=0 corresponding to an epoch with parameters σ,α, and β, proving the result in equation (B.17). □

Lemma B.3.3

Let G,W,E(t), and F(s,t;ζ) denote the matrices defined in equations (A.11), (A.15), (A.17), and (B.10), respectively, where ζ=(ζ0,ζ1,) is a set of distinct values arbitrarily chosen such that {ζ0,ζ1,}[0,1]. Then the coefficient vectors ak and bk satisfy the recursive relationships

bk=akWkGkok(1Gk)nkokWk1, (B.20)
ak={bk1Elk(tktk1)ifk1=k,bk1F(tk1,tk;ζ)otherwise, (B.21)

where W1=DWTC1.

Proof

The relationship in equation (B.21) is obtained immediately by setting t = tk in equations (B.4) and (B.15), which follows because ak(tk)=ak. The relationship in equation (B.20) does not depend on the population parameters Θ; therefore, equation (B.20) is the same as that derived in Steinrücken et al. (2014), who considered a population of constant size (see Steinrücken et al. 2014, Theorem 2). □

Lemma B.3.4

The probability PΘ,D{O[1:K]=o[1:K]} of observing the allele counts o[1:K], given the population parameters Θ is

PΘ,D{O[1:K]=o[1:K]}=cK,0BK,0(0)bK,0, (B.22)

where c,0=[C]0,0 is element 0, 0 of the matrix C in equation (A.18) and

B,0(0)=m=0(1)m[W]0,mΓ(m+α)Γ(m+1)Γ(α). (B.23)

The quantity [W]i,j in equation (B.23) is element i, j of the matrix W given in equation (A.15).

Proof

Equation (B.22) can be obtained by integrating over the joint density fK(y) of the data O[1:K] and the allele frequency YtK at the final sampling time:

PΘ,D{O[1:K]=o[1:K]}=01fK(y)dy=01n=0bK,nπK(y)BK,n(y)dy=n=0bK,n01πK(y)BK,n(y)dy=n=0bK,n01πK(y)BK,n(y)BK,0(y)BK,0(0)dy=bK,0cK,0BK,0(0), (B.24)

where cK,0=[CK]0,0BK,0,BK,0πK. In the fourth equality we have used the fact that B,0(y)=B,0(0) is a constant function in y. To see why B,0(y) is constant, note that the eigenvalues λ,0,λ,1, are non-negative and strictly increasing. Thus, all terms in equation (A.5) must vanish in the limit s, except possibly the term n = 0. Because p(s,t;x,y) approaches the stationary density in the limit s, it must be the case that λ,0=0, so at least one term does not vanish. Thus, we have

limspθ(s,t;x,y)=π(y)B,0(x)B,0(y)B,0,B,0ππ(y), (B.25)

where we have used the fact that π(y) is proportional to the stationary density of the diffusion equation in Epoch . It follows from equation (B.25) that B,0(y) is constant. Thus, we obtain the result, proving equation (B.22). Equation (B.23) follows directly from the proof of Proposition 3 in Steinrücken et al. (2014). □

Appendix C

Conditional Probabilities: The Wright–Fisher Model

Under the Wright–Fisher model, the probability PΘ,W{O[1:K]=o[1:K]|SK} of the observed allele counts, conditional on the event SK that allele A is segregating in the final sample can be computed using the fact that

PΘ,W{O[1:K]=o[1:K]|SK}=j=02NtKPΘ,W{O[1:K]=o[1:K],ctK=j|SK}=j=02NtKPΘ,W{SK|O[1:K]=o[1:K],ctK=j}PΘ,W{SK}×PΘ,W{O[1:K]=o[1:K],ctK=j}=P{SK|OK=oK}PΘ,W{SK}×j=02NtKPΘ,W{O[1:K]=o[1:K],ctK=j}=P{SK|OK=oK}PΘ,W{SK}i=02NtKvK,i, (C.1)

where the third equality in equation (C.1) follows from the fact that the conditional probability PΘ,W{SK|O[1:K]=o[1:K],ctK=j} depends only on the allele count oK and the final equality in equation (C.1) follows from the definition of vk. The probability P{SK|OK=oK} in equation (C.1) is given by

P{SK|OK=oK}={1,if1oK<nK,0,otherwise  (C.2)

and the probability PΘ,W{SK} is given by

PΘ,W{SK}=i=02NtKP{SK|CtK=i}PΘ,W{CtK=i}=i=02NtK [1P{OK=0|CtK=i} P{OK=nK|CtK=i}]×PΘ,W{CtK=i}=i=02NtK[1(1i2NtK)nK(i2NtK)nK]×PΘ,W{ctK=i}, (C.3)

where, as before, PΘ,W{CtK=i} is given by the ith element of dt=d0t=1tKTt1,t.

Note that it is easy to condition on other configurations of the final sample using a procedure similar to that used to derive equation (C.1). For example, for the event FK that allele A is segregating or fixed in the final sample, which we consider in the “Simulations Conditioning on Segregation or Fixation” section, the probability PΘ,W{O[1:K]=o[1:K]|FK} is given by

PΘ,W{O[1:K]=o[1:K]|FK}=P{FK|OK=oK}PΘ,W{FK}i=02NtKvK,i, (C.4)

where

P{FK|OK=oK}={1,if1oKnK,0,otherwise (C.5)

and

PΘ,W{FK}=i=02NtK[1P{OK=0|CtK=i}]PΘ,W{CtK=i}=i=02NtK[1(1i2NtK)nK]PΘ,W{ctK=i}. (C.6)

Other probabilities can be obtained in a similar fashion.

Appendix D

Conditional Probabilities: Diffusion Model

Under the diffusion approximation, the probability PΘ,D{O[1:K]=o[1:K]|SK} of the observed allele counts conditional on the event SK that allele A is segregating in the final sample can be computed using the fact that

PΘ,D{O[1:K]=o[1:K]|SK}=y=01PΘ,D{O[1:K]=o[1:K],YtK=y|SK}dy=y=01P{SK|OK=oK}PΘ,D{SK}fK(y)dy=P{SK|OK=oK}PΘ,D{SK}01fK(y)dy=P{SK|OK=oK}PΘ,D{SK}PΘ,D{O[1:K]=o[1:K]}=P{SK|OK=oK}PΘ,D{SK}cK,0BK,0(0)bK,0, (D.1)

where the second equality follows from the fact that the conditional probability P{SK|OK=oK,YtK=y} depends only on the allele count oK in the final sample, and the final equality follows from equation (B.22).

The probability PΘ,D{SK} can be computed as

PΘ,D{SK}=1PΘ,D{OK=0}PΘ,D{OK=nK}. (D.2)

In equation (D.2), the probability PΘ,D{OK=j} can be found easily by noting that if the only sampling time is tK, at which OK =j lineages are observed, then the probability computed using Procedure 2 is precisely the probability PΘ,D{OK=j}.

Consider the problem in which the only sampling occurs at time tK and denote the coefficient vectors for this related problem by a˜k and b˜k. Then, by equation (B.22), we see that

PΘ,D{OK=j}=cK,0BK,0(0)b˜K,0(j), (D.3)

where b˜K(j) is obtained by computing the steps in Procedure 2. In Step 1, we compute

b˜0=b0, (D.4)

which follows because the initial vector b0 depends only on the initial frequency. In Step 2, we compute

a˜K= {b˜0E1(tK),iftK=1,b˜0F(0,tK;ζ),otherwise, (D.5)

which follows because the coefficients are propagated directly from time t0=0 to time tK. Finally, in Step 3 we have

b˜K(j)=a˜KWKGKj(1GK)nKjWK1. (D.6)

Combined together, equations (D.4), (D.5), and (D.6) yield

b˜K(j) = {b0E1(tK)WKGKj(1GK)nKjWK1,iftK=1,b0F(0,tK;ζ)WKGKj(1GK)nKjWK1,otherwise. (D.7)

Plugging equations (D.2) and (D.3) into equation (D.1) gives

PΘ,D{O[1:K]=o[1:K]|SK}=P{SK|OK=oK}cK,0bK,0BK,0(0)cK,0b˜K,0(0)cK,0b˜K,0(nK), (D.8)

where

P{SK|OK=oK}={1,if1oK<nK,0,otherwise. (D.9)

Note that it is easy to condition on other configurations of the final sample by computing the probabilities P{VK|OK=ok} and PΘ,W{VK} for some other event VK.

References

  1. Abramowitz M., Stegun I. A., editors. 1972. Handbook of mathematical functions with formulas, graphs, and mathematical tables. 9th ed. New York: Dover. [Google Scholar]
  2. Bollback JP, York TL, Nielsen R. 2008. Estimation of 2Nes from temporal allele frequency data. Genetics 179:497–502. [DOI] [PMC free article] [PubMed] [Google Scholar]
  3. Bonhoeffer S, Barbour AD, De Boer RJ. 2002. Procedures for reliable estimation of viral fitness from time-series data. Proc R Soc Lond B 269:1887–1893. [DOI] [PMC free article] [PubMed] [Google Scholar]
  4. Clarke B, Murray J. 1962. Changes in gene-frequency in Cepaea nemoralis (L.): the estimation of selective values. Heredity 17:467–476. [Google Scholar]
  5. Cook LM, Jones DA. 1996. The medionigra gene in the moth Panaxia dominula: the case for selection. Phil Trans R Soc Lond B. 351:1623–1634. [Google Scholar]
  6. Cook LM, Cowie RH, Jones JS. 1999. Change in morph frequency in the snail Cepaea nemoralis on the Marlborough Downs. Heredity 82:336–342. [DOI] [PubMed] [Google Scholar]
  7. Cook LM, Sutton SL, Crawford TJ. 2005. Melanic moth frequencies in Yorkshire, an old English industrial hot spot. J Hered. 96:522–528. [DOI] [PubMed] [Google Scholar]
  8. Durrett R. 2008. Probability models for DNA sequence evolution. New York: Springer Science & Business Media. [Google Scholar]
  9. Ewens WJ. 1963. Numerical results and diffusion approximations in a genetic process. Biometrika 50:241–249. [Google Scholar]
  10. Ewens WJ. 2004. Mathematical population genetics: I. 2nd ed. New York: Springer. [Google Scholar]
  11. Feder AF, Kryazhimskiy S, Plotkin JB. 2014. Identifying signatures of selection in genetic time series. Genetics 196:509–522. [DOI] [PMC free article] [PubMed] [Google Scholar]
  12. Felsenstein J. 1976. The theoretical population genetics of variable selection and migration. Annu Rev Genet. 10:253–280. [DOI] [PubMed] [Google Scholar]
  13. Ferrer-Admetlla A, Leuenberger C, Jensen JD, Wegmann D. 2015. An approximate Markov model for the Wright-Fisher diffusion. Genetics 203:831–846. [DOI] [PMC free article] [PubMed] [Google Scholar]
  14. Fisher RA. 1922. On the dominance ratio. Proc R Soc Edin. 42:321–341. [Google Scholar]
  15. Fisher RA, Ford EB. 1947. The spread of a gene in natural conditions in a colony of the moth Panaxia dominula L. Edinnburgh: Oliver & Boyd.
  16. Foll M, Shim H, Jensen JD. 2015. WFABC: a Wright–Fisher ABC-based approach for inferring effective population sizes and selection coefficients from time-sampled data. Mol Ecol Resour. 15:87–98. [DOI] [PubMed] [Google Scholar]
  17. Gallet R, Cooper TF, Elena SF, Lenormand T. 2012. Measuring selection coefficients below 103: method, questions, and prospects. Genetics 190(1):175–186. [DOI] [PMC free article] [PubMed] [Google Scholar]
  18. Gillespie JH. 1998. Population genetics: a concise guide. Baltimore: JHU Press. [Google Scholar]
  19. Goudsmit J, De Ronde A, Ho DD, Perelson AS. 1996. Human Immunodeficiency Virus fitness in vivo: calculations based on a single zidovudine resistance mutation at codon 215 of reverse transcriptase. J Virol. 70:5662–5664. [DOI] [PMC free article] [PubMed] [Google Scholar]
  20. Haldane JBS. 1927. A mathematical theory of natural and artificial selection, Part V: selection and mutation. Math Proc Cambridge. 23:838–844. [Google Scholar]
  21. Harrigan PR, Bloor S, Larder BA. 1998. Relative replicative fitness of zidovudine-resistant Human Immunodeficiency Virus Type 1 isolates in vitro. J Virol. 72:3773–3778. [DOI] [PMC free article] [PubMed] [Google Scholar]
  22. Hartl DL, Clark AG. 2007. Principles of population genetics. 4th ed. Sunderland: (MA): Sinauer Associates. [Google Scholar]
  23. Haubruge E, Arnaud L. 2001. Fitness consequences of malathion-specific resistance in Red Flour Beetle (Coleoptera: Tenebrionidae) and selection for resistance in the absence of malathion. J Econ Entomol. 94(2):552–557. [DOI] [PubMed] [Google Scholar]
  24. Hein J, Schierup MH, Wiuf C. 2005. Gene genealogies, variation and evolution. Milton Keynes (United Kingdom): Oxford University Press. [Google Scholar]
  25. Illingworth CJR, Parts L, Schiffels S, Liti G, Mustonen V. 2012. Quantifying selection acting on a complex trait using allele frequency time series data. Mol Biol Evol. 29:1187–1197. [DOI] [PMC free article] [PubMed] [Google Scholar]
  26. Jenkins PA, Spanò D. 2015. Exact simulation of the Wright-Fisher diffusion. arXiv:1506.06998, http://arxiv.org/abs/1506.06998.
  27. Kamm JA, Terhorst J, Song YSS. 2016. Efficient computation of the joint sample frequency spectra for multiple populations. J Comput Graph. Stat. http://dx.doi.org/10.1080/10618600.2016.1159212. [DOI] [PMC free article] [PubMed] [Google Scholar]
  28. Karlin S, Taylor H. 1981. A second course in stochastic processes. 2nd ed. New York: Academic Press. [Google Scholar]
  29. Labbé P, Sidos N, Raymond M, Lenormand T. 2009. Resistance gene replacement in the mosquito Culex pipiens: fitness estimation from long-term cline series. Genetics 182:303–312. [DOI] [PMC free article] [PubMed] [Google Scholar]
  30. Lacerda M, Seoighe C. 2014. Population genetics inference for longitudinally-sampled mutants under strong selection. Genetics 198:1237–1250. [DOI] [PMC free article] [PubMed] [Google Scholar]
  31. Lynch M. 1987. The consequences of fluctuating selection for isozyme polymorphisms in daphnia. Genetics 115:657–669. [DOI] [PMC free article] [PubMed] [Google Scholar]
  32. Malaspinas A, Malaspinas O, Evans SN, Slatkin M. 2012. Estimating allele age and selection coefficient from time-serial data. Genetics 192:599–607. [DOI] [PMC free article] [PubMed] [Google Scholar]
  33. Manly BF. 1985. The statistics of natural selection. London: Chapman & Hall. [Google Scholar]
  34. Mathieson I, McVean G. 2013. Estimating selection coefficients in spatially structured populations from time series data of allele frequencies. Genetics 193:973–984. [DOI] [PMC free article] [PubMed] [Google Scholar]
  35. Nishino J. 2013. Detecting selection using time-series data of allele frequencies with multiple independent reference loci. G3 3:2151–2161. [DOI] [PMC free article] [PubMed] [Google Scholar]
  36. O’Hara RB. 2005. Comparing the effects of genetic drift and fluctuating selection on genotype frequency changes in the scarlet tiger moth. Proc Roy Soc Lond B. 272:211–217. [DOI] [PMC free article] [PubMed] [Google Scholar]
  37. Rabiner LR. 1989. A tutorial on Hidden Markov Models and selected applications in speech recognition. Proc IEEE. 77:257–286. [Google Scholar]
  38. Reimchen TE, Nosil P. 2002. Temporal variation in divergent selection on spine number in Threespine Stickleback. Evolution 56:2472–2483. [DOI] [PubMed] [Google Scholar]
  39. Rouzine IM, Rodrigo A, Coffin JM. 2001. Transition between stochastic evolution and deterministic evolution in the presence of selection: general theory and application to virology. Microbiol Mol Biol R. 65:151–185. [DOI] [PMC free article] [PubMed] [Google Scholar]
  40. Schaffer HE, Yardley D, Anderson WW. 1977. Drift or selection: a statistical test of gene frequency variation over generations. Genetics 87:371–379. [DOI] [PMC free article] [PubMed] [Google Scholar]
  41. Schraiber JG, Evans SN, Slatkin M. 2016. Bayesian inference of natural selection from allele frequency time series. Genetics 203:493–511. [DOI] [PMC free article] [PubMed] [Google Scholar]
  42. Siepielski AM, DiBattista JD, Carlson SM. 2009. Its about time: the temporal dynamics of phenotypic selection in the wild. Ecol Lett. 12(11):1261–1276. [DOI] [PubMed] [Google Scholar]
  43. Song YS, Steinrücken M. 2012. A simple method for finding explicit analytic transition densities of diffusion processes with general diploid selection. Genetics 190(3):1117–1129. [DOI] [PMC free article] [PubMed] [Google Scholar]
  44. Steinrücken M, Bhaskar A, Song YS. 2014. A novel spectral method for inferring general diploid selection from time series genetic data. Ann Appl Stat. 8(4):2203–2222. [DOI] [PMC free article] [PubMed] [Google Scholar]
  45. Steinrücken M, Jewett EM, Song YS. 2015. Spectraltdf: transition densities of diffusion processes with time-varying selection parameters, mutation rates and effective population sizes. Bioinformatics 32(5):795–797. [DOI] [PMC free article] [PubMed] [Google Scholar]
  46. Stine OC, Smith KD. 1990. The estimation of selection coefficients in afrikaners: Huntington disease, porphyria variegata, and lipoid proteinosis. Am J Hum Genet. 46:452–458. [PMC free article] [PubMed] [Google Scholar]
  47. Wakeley J. 2008. Coalescent theory: an introduction. Greenwood Village, CO: Roberts & Company Publishers. [Google Scholar]
  48. Wall S, Carter MA, Clarke B. 1980. Temporal changes of gene frequencies in cepaea hortensis. Biol J Linn Soc. 14(3–4):303–317. [Google Scholar]
  49. Watterson G. 1975. On the number of segregating sites in genetic models without recombination. Theor Popul Biol. 7:256–276. [DOI] [PubMed] [Google Scholar]
  50. Wilson SR. 1980. Analyzing gene-frequency data when the effective population size is finite. Genetics 95:489–502. [DOI] [PMC free article] [PubMed] [Google Scholar]
  51. Zhao L, Lascoux M, Waxman D. 2014. Exact simulation of conditioned wright–fisher models. J Theor Biol. 363:419–426. [DOI] [PubMed] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

Supplementary Data

Articles from Molecular Biology and Evolution are provided here courtesy of Oxford University Press

RESOURCES