Next Article in Journal
Four Novel Disease-Causing Variants in the NOTCH3 Gene in Russian Patients with CADASIL
Previous Article in Journal
Complete Genomic Sequence Analysis of a Sugarcane Streak Mosaic Virus Isolate from Yunnan Province of China
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A General Framework for Neutrality Tests Based on the Site Frequency Spectrum

by
Sebastián E. Ramos-Onsins
1,*,†,
Giacomo Marmorini
2,3,†,
Guillaume Achaz
4 and
Luca Ferretti
5,*
1
Centre for Research in Agricultural Genomics (CRAG) CSIC-IRTA-UAB-UB, 08193 Bellaterra, Spain
2
Department of Physics and Mathematics, Aoyama Gakuin University, Sagamihara 252-5258, Japan
3
Department of Physics, Nihon University, Tokyo 156-8550, Japan
4
Institut de Systématique, Evolution, Biodiversité, UMR 7205, MNHN and Centre Interdisciplinaire de Recherche en Biologie, UMR 7241, Collége de France, 75231 Paris, France
5
Pandemic Sciences Institute and Big Data Institute, Nuffield Department of Medicine, University of Oxford, Oxford OX1 3AZ, UK
*
Authors to whom correspondence should be addressed.
These authors contributed equally to this work.
Genes 2023, 14(9), 1714; https://doi.org/10.3390/genes14091714
Submission received: 21 July 2023 / Revised: 25 August 2023 / Accepted: 26 August 2023 / Published: 28 August 2023
(This article belongs to the Section Population and Evolutionary Genetics and Genomics)

Abstract

:
One of the main necessities for population geneticists is the availability of sensitive statistical tools that enable to accept or reject the standard Wright–Fisher model of neutral evolution. A number of statistical tests have been developed to detect specific deviations from the null frequency spectrum in different directions (e.g., Tajima’s D, Fu and Li’s F and D tests, Fay and Wu’s H). A general framework exists to generate all neutrality tests that are linear functions of the frequency spectrum. In this framework, it is possible to develop a family of optimal tests with almost maximum power against a specific alternative evolutionary scenario. In this paper we provide a thorough discussion of the structure and properties of linear and nonlinear neutrality tests. First, we present the general framework for linear tests and emphasise the importance of the property of scalability with the sample size (that is, the interpretation of the tests should not depend on the sample size), which, if missing, can lead to errors in interpreting the data. After summarising the motivation and structure of linear optimal tests, we present a more general framework for the optimisation of linear tests, leading to a new family of tunable neutrality tests. In a further generalisation, we extend the framework to nonlinear neutrality tests and we derive nonlinear optimal tests for polynomials of any degree in the frequency spectrum.

1. Introduction

Since the development of molecular genetics techniques allowed to obtain nucleotide sequences for the study of populations genetics [1], a number of neutrality tests have been developed with the objective to facilitate the interpretation of an increasing volume of molecular data. Statistical tests for neutrality have been generated exploiting the different properties of the stationary neutral model. Examples of tests are the HKA [2], which takes advantage of the polymorphism/divergence relationship across independent loci in a multilocus framework, and the Lewontin–Krakauer test [3], which looks for an unexpected level of population differentiation in a locus in relation to other loci. Additionally, another family of popular tests are the ones related to linkage disequilibrium, such as the one developed by [4], which detects long haplotypes at unusual elevated frequencies in candidate regions.
An important family of these tests, often used as summary statistics, is built on the frequency spectrum of biallelic polymorphisms. This family includes the well known tests by Tajima [5], Fu and Li [6], and Fay and Wu [7]. If an outgroup is available, these tests are based on the unfolded spectrum ξ i , that is, the number of segregating sites with a derived allele frequency of i in a sample of (haploid) size n. Without an outgroup, it is not possible to distinguish derived and ancestral alleles and the only available data correspond to the folded spectrum η i , that is, the number of segregating sites with a minor allele frequency of i. The quantities ξ i and η i are all positive and the range of allele frequencies is 1 i n 1 for the unfolded spectrum, 1 i n / 2 for the folded spectrum. The average spectra for the standard Wright–Fisher neutral model are given by:
E ( ξ i ) = 1 i θ L , E ( η i ) = n i ( n i ) ( 1 + δ i , n i ) θ L ,
where L is the length of the sequence and θ = 2 p μ N e , where μ is the mutation rate per base, p is the ploidy and N e is the effective population size. Note that we define θ as the rescaled mutation rate per base and not per sequence. Apart from this, we follow the notation of [8,9]. Note that the spectra are proportional to θ .
A general framework for linear tests was presented in [8]. The general tests proposed there were of the form:
T Ω = i = 1 n 1 i Ω i ξ i Var j = 1 n 1 j Ω j ξ j , T Ω * = i = 1 n / 2 i Ω i * η i Var j = 1 n / 2 j Ω j * η j
that are centred (i.e., they have a null expectation value) if the weights Ω i , Ω i * satisfy the conditions i = 1 n 1 Ω i = 0 and i = 1 n / 2 Ω i * = 0 . This framework allows the construction of many new neutrality tests and has been used to obtain optimal tests for specific alternative scenarios [10]. However, the original framework does not take into account the dependence of the tests on the sample size, as emphasised in [10]. It is important to choose this dependence in order to obtain results that are as independent as possible on sample size. Moreover, the framework presented in [8] covers just a large subfamily of neutrality tests based on the frequency spectrum, that is, the class of tests that are linear functions of the spectrum. This subfamily contains almost all the tests that can be found in the literature with the exception of the G ξ , G η tests of Fu [11], which are second order polynomials in the spectrum whose form is related with Hotelling statistics. Since these G ξ , G η tests were shown to be quite effective in some scenarios, it would be interesting to build a general framework for these quadratic (and more generally nonlinear) tests. New optimal tests based on extensions of the site frequency spectrum [12,13] were recently applied successfully to the detection of selection pressure on human chromosomal inversions [14].
In this work we provide a detailed study of the properties of the whole family of tests based on the site frequency spectrum, i.e., focus on the structure and the properties of neutrality tests that consider the frequency of the variants per position. Technical details and proofs can be found in Appendix A and Appendix B.
We begin with the discussion of the most interesting case, i.e., linear tests. Achaz [8] developed a general framework for constructing linear tests comparing two different estimators of variability, which are based on linear combinations of the frequency, each one containing different weights. We summarise his approach in the Section 2.1.
In Section 2.2, we discuss the importance of scaling the weights with the aim to avoid a dependence with the sample size. This allows us to interpret the information of the test in the same way for any sample size analysed. We provide a thorough analysis of a simple proposal for the scaling of the tests with the sample size. Different scaling strategies (including alternatives to scaling) are analysed and evaluated, demonstrating the importance but also the suitability of different weighting methods depending on the nature of the statistic.
In Section 2.3, we present and expand the theory of optimal tests, i.e., tests that have maximum power to detect an alternative scenario versus a null scenario, introduced in [10]. We show that generic linear tests cannot detect arbitrary deviations from the neutral spectrum, and why tests must be optimised with respect to a specific alternative scenario. A geometrical interpretation of neutrality test is developed, showing how these tests depend on the differences between the null and the alternative scenario, clarifying the theoretical basis for these tests.
In Section 2.4, we extend this approach to nonlinear tests that consider different moments of the frequency spectrum combined in generic polynomials or in power series. In contrast to linear tests, nonlinear tests are dependent on the level of variability θ and thus need an accurate estimation of θ to have good statistical properties (e.g., unbiased, high statistical power). These tests are classified in strongly and weakly centred (that is, having null expectation value). Strongly centred tests are those tests that are centred for any value for any estimate of θ , even if this estimate is far from the actual value, and thus are more robust to deviations of θ estimates than weakly centred tests (simulations shown already in the Results section (Section 3)). Instead, weakly centred tests are only centred if the θ estimate is equal to the actual value, but this feature also makes the tests more powerful if the inference of θ is reliable.
In Section 3.1 in the Results, we see some consequences of the framework outlined in Methods; it is possible to optimise neutrality tests following a general maximisation approach that depends on the proxy used for the power to reject the null model in the alternative scenario, which depends on the mean spectra, the covariance matrices, and the critical p-value used. Moreover, we show that under some conditions, the power maximisation can be always achieved by tuning a parameter in a new family of linear “tunable” optimal tests developed here, which depend only on the mean spectra of the alternative model.
In Section 3.2, we present the results for the power to detect deviations from the neutral spectrum in coalescent simulations. We show how linear optimal tests have more power than usual neutrality tests such as Tajima’s D, nonlinear optimal tests are more powerful than linear ones, and weakly centred tests are more powerful than strongly centred ones if θ is known.
In summary, our research augments the understanding of neutrality tests, encompassing weight normalisation, optimal test formulation, and both linear and nonlinear paradigms. The outcome not only enriches theoretical foundations but also provides novel methodologies for increasing power and effectiveness of neutrality tests across diverse scenarios.

2. Material and Methods

2.1. Linear Neutrality Tests

General Framework

As discussed by Achaz [8], the general form for linear tests based on the unfolded spectrum can be written as:
T Ω = i = 1 n 1 i Ω i ξ i Var j = 1 n 1 j Ω j ξ j
where Ω i is a set of weights satisfying the condition:
i = 1 n 1 Ω i = 0 .
This is the most general form if we require that the test is centred and with variance 1, that is, E ( T Ω ) = 0 and Var ( T Ω ) = 1 . The condition of intendedness can be obtained substituting the spectrum with its average in the standard neutral model, given by the Equation (1).
Alternatively, it is sufficient to choose any pair of unbiased estimators of θ based on the unfolded spectrum:
θ ^ ω = 1 L i = 1 n 1 i ω i ξ i , θ ^ ω = 1 L i = 1 n 1 i ω i ξ i
with weights ω i , ω i that obey the conditions:
i = 1 n 1 ω i = 1 , i = 1 n 1 ω i = 1
to obtain a new test for neutrality:
T Ω = θ ^ ω θ ^ ω Var ( θ ^ ω θ ^ ω ) = i = 1 n 1 i ( ω i ω i ) ξ i Var j = 1 n 1 j ( ω j ω j ) ξ j = i = 1 n 1 i Ω i ξ i Var j = 1 n 1 j Ω j ξ j
that is equivalent to the definition (3) with Ω i = ω i ω i . Therefore a test T Ω is defined by real vectors Ω or ω , ω satisfying the above normalisation conditions.

2.2. Sample Size Independent Tests

2.2.1. Scaling of Weights with Sample Size

In this section we would like to remark that there are conditions that have to be imposed on the weights Ω i or ω i , ω i to ensure that these tests are consistent and meaningful in their interpretation. In fact, the values (and even the number!) of these weights depend explicitly on sample size n. Since every conceivable test should be applied to samples of different sizes, then its definition involves a whole family of weights Ω i ( n ) or ω i ( n ) , ω i ( n ) with n = 2 , 3 and to define a test it is necessary to specify how these weights scale with n.
As an example of the weird effects of some choices of scaling, we consider the test for admixture of [8]. The weights of this test are ω i = n i 2 n ( 1 2 n + 1 ) 1 and ω i = 1 / ( n 1 ) . Suppose that the population under study shows an excess of alleles of frequency f between 0.3 and 0.4. The average weight of these frequencies, rescaled by the sample size, is 0.5 for n = 10 , but it reduces to −0.75 for n = 100 and to −1.0 for n = 1000 . These weights are largely different, even in sign, therefore a strong excess of alleles in this range of frequency would show itself as either a positive or a negative value for this test, depending on the sample size! The reason can be understood by noticing that for n large, the binomial can be approximated by a Gaussian function of the allele frequencies f = i / n centred in f = 1 / 2 and with variance 1 / 4 n . Therefore this weight function has a strong dependence on n when considered as a function of f and n. The changes of this weight function with sample size are apparent in the plot of Figure 1, which shows the actual function (rescaled by sample size) for n = 101,001,000.
In this example it is apparent that the interpretation of the results of this test depends on n. This means that the calibration of the test should be different for each possible sample size.
The weight-consistency requirement that we propose is that the result of the test should be almost independent of sample size. This requirement is equivalent to a condition on the scaling of the weights Ω i ( n ) with n. Our proposal for a reasonable requirement on this scaling is the following: the relative weight of different frequencies in the population should remain approximately constant while varying the size of the sample. This condition ensures that at least for sufficiently large n, the average values of the test on samples of different size from the same population should be approximately independent on sample size, i.e., that the test should be weight-consistent. Note that this requirement has to do with the interpretation of the test, rather than with the usual definition of statistical consistency. Tests that are not weight-consistent could be statistically consistent, but the interpretation of results in the left and right tails would not be assured to be independent of sample size.
To determine the scaling, we note that in limit of large n, the frequency spectrum approaches a continuum and we can define the weights as functions Ω ( f ) or ω ( f ) , ω ( f ) with f ( 0 , 1 ) and 0 1 d f Ω ( f ) = 0 , 0 1 d f ω ( f ) = 0 1 d f ω ( f ) = 1 . Since the ratio of the derived allele count and the sample size i / n is an unbiased estimator of the frequency f of the allele in the population (because E ( i ) = n f ), a simple scaling that satisfies the above requirement is:
Ω i ( n ) Ω ( i / n ) or ω i ( n ) ω ( i / n ) , ω i ( n ) ω ( i / n )
as proposed by some of the authors in [10].
In order to have the above approximate scaling while obeying the condition i = 1 n 1 Ω i = 0 , there are two simple weight-consistent forms for the weights:
Ω i ( n ) = Ω i n 1 n 1 j = 1 n 1 Ω j n
where the last term is a (typically small) correction that enforce centredness of the test, or:
Ω i ( n ) = ω i ( n ) ω i ( n ) = ω i n j = 1 n 1 ω j n ω i n j = 1 n 1 ω j n
where the denominators are normalisation factors.
Typically, this second form (10) for the scaling is more consistent in practice and it is implicitly assumed for most of the existing tests. However, the above expressions give similar numerical results for most choices of the functions Ω ( f ) = ω ( f ) ω ( f ) . In fact, if Ω ( f ) is a limited and piecewise-continuous function, the difference between (9) and (10) is of order O ( Ω ) / n (since it is a factor coming from the discretisation of the frequencies) and it does not have a relevant impact on the results of the test. Therefore, in these cases the two scaling relations (9) and (10) are practically equivalent.
Note that all the tests involving the Watterson estimator (that corresponds to ω ( f ) 1 / f ) have additional subtleties that are discussed in the next section.

Example: Fay and Wu’s H test

This test was proposed in [7] to look for an excess of high-frequency derived alleles as a signal of selection. It can be defined by the weight functions ω ( f ) = 2 ( 1 f ) and ω ( f ) = 2 f or alternatively ω ( f ) = 1 and ω ( f ) = 2 f . The weights can be found following Equation (10). The resulting test is:
T H = 1 n 1 i = 1 n 1 i ξ i 2 n ( n 1 ) i = 1 n 1 i 2 ξ i Var 1 n 1 j = 1 n 1 j ξ j 2 n ( n 1 ) j = 1 n 1 j 2 ξ j
The scaling defined in Equation (9), with weight function Ω ( f ) = ω ( f ) ω ( f ) = 1 2 f , gives precisely the same result.

Example: F ( r , r ) tests of Fu [15]

This large class of test is based on the comparison of two estimators with weights:
ω i = i r j = 1 n 1 j r , ω i = i r j = 1 n 1 j r
that in the case r , r < 1 correspond precisely to the scaling (10) suggested above, with weight functions ω ( f ) = ( 1 r ) f r and ω ( f ) = ( 1 r ) f r . This can be easily verified by multiplying both the numerator and the denominator of ω i , ω i by a factor ( 1 r ) / n r , ( 1 r ) / n r respectively. The test by Fay and Wu corresponds actually to F ( 0 , 1 ) .
The cases with r 1 or r 1 involve weight functions with divergent integrals and will be discussed in the next section.
Note that the same weight functions with the scaling (9) would give rise to a slightly different test with weights:
Ω i = ( 1 r ) i n r ( 1 r ) i n r ( 1 r ) j = 1 n 1 j r ( n 1 ) n r ( 1 r ) j = 1 n 1 j r ( n 1 ) n r
that is not weight-consistent for weights of low frequency alleles, i.e., with i / n n 2 / max ( r , r ) , and is therefore less interesting.

Example: Test for bottleneck of Achaz [8]

This test is another example of a test with an unwanted scaling:
ω i = e α i j = 1 n 1 e α j , ω i = 1 n 1
The weight function for this test is e α n f α n / ( 1 e α n ) 1 that depends strongly on n, therefore this test is not weight-consistent in the above sense.
It is easy to build an equivalent test with the correct scaling by choosing the functions ω ( f ) = β e β f / ( 1 e β ) , ω ( f ) = 1 . The resulting weights with the scaling (10) are:
ω i = e β i / n j = 1 n 1 e β j / n = 1 e β / n 1 e β ( 1 1 / n ) e β ( i 1 ) / n , ω i = 1 n 1
as discussed before. The optimal value reported in [8] is α 0.9 for n = 30 . This value corresponds to β 27 .
The test can also be implemented by choosing the scaling (9) and the weight function Ω ( f ) = ω ( f ) ω ( f ) = β e β f / ( 1 e β ) 1 . The resulting weights are:
Ω i = β e β i / n 1 e β 1 1 n 1 β ( 1 e β ( 1 1 / n ) ) ( 1 e β ) e β / n ( 1 e β / n ) ( n 1 ) = = β ( 1 e β ( 1 1 / n ) ) ( 1 e β ) e β / n ( 1 e β / n ) · 1 e β / n 1 e β ( 1 1 / n ) e β ( i 1 ) / n 1 n 1
that are equivalent to the weights (15) up to an irrelevant multiplicative factor (see Theorem A1). Therefore, in this case the two choices of scaling give precisely the same result.

2.2.2. Divergent Weights

As discussed above, the two choices of scaling in Equations (9) and (10) do not usually obtain sensibly different numerical results. However, there are important choices of Ω ( f ) for which this approximate equivalence between (9) and (10) does not hold. These critical cases correspond to functions that diverge as 1 / f or faster near f = 0 (or f = 1 ). This divergence is not a real feature of the distribution, because the integral has a natural cutoff at the scale of the inverse population size f m i n = 1 / N (more precisely, the effective population size 1 / N e , but this does not affect the discussion). However, in this case the integral 1 / N 1 d f Ω ( f ) has a strong dependence on the cutoff 1 / N and therefore the function Ω ( f ) itself should depend strongly on N to ensure proper normalisation.
If this dependence is contained in a multiplicative term in front of ω ( f ) or ω ( f ) or both, then the second term in Equation (9) is not a small correction of order 1 / n as it happens with simple functions Ω ( f ) , but rather it represents a relevant correction with a strong dependence on sample size n and population size N. The denominators in Equation (10) also show a strong dependence on n (that could not be avoided anyway) but not on N, and therefore this second scaling form should be used. The dependence on sample size is as strong as the dependence of the divergent integral from the cutoff. This can be easily understood by noticing that the sample size n plays the role of the cutoff in the sum over the frequencies that are present in the sample, which is the same role played by the population size N for the whole population; more formally, the denominator in Equation (10) can be bounded from above and from below by the divergent integral, and therefore the divergence of the denominator as n will be the same as the divergence of the integral as its inverse cutoff (that is, N) goes to infinity). For functions diverging as f k with k 1 , the dependence on n goes as n 1 k if k > 1 or log ( n ) for k = 1 . This case always occurs when the test is built by comparing an estimator of θ with the Watterson estimator, which corresponds to ω ( f ) 1 / f and therefore has a logarithmic dependence on n given by the usual harmonic factor a n = j = 1 n 1 1 / j log ( n ) + γ + O ( 1 / n ) . A well-known example of this case is Tajima’s D [5].
If the dependence of Ω ( f ) on N is contained in an additive term that does not depend on f, it is the correction in (9) that does not depend on N and therefore the first scaling form is more appropriate. We do not know examples of tests of this kind in the literature, even if the test by Zeng et al. [16] can be interpreted also in this way.

Example: Tajima’s D test

This is the most known test for neutrality based on the frequency spectrum. It is given by the difference between the Tajima estimator Π [17] based on the nucleotide pairwise diversity Π and the Watterson estimator θ W [18] based on the number S of segregating sites, therefore it can be defined by the weight functions ω ( f ) = 2 ( 1 f ) for Π and ω ( f ) = 1 / f log ( N ) for the Watterson estimator. The latter function has an integral that diverges logarithmically near f = 0 , and the corresponding dependence on N is contained in the factor 1 / log ( N ) that multiplies ω ( f ) , therefore the scaling (10) should be used. The result is the usual test:
T D = i = 1 n 1 2 i ( n i ) n ( n 1 ) ξ i S / a n Var j = 1 n 1 2 j ( n j ) n ( n 1 ) ξ j S / a n = Π S / a n Var Π S / a n

Example: Test of Zeng et al. [16]

This test was proposed to look for an excess of high-frequency derived alleles compared to low-frequency alleles. It is defined by the weight functions ω ( f ) = 1 / f log ( N ) and ω ( f ) = 1 , the former corresponding to the Watterson estimator. Proceeding as in the above example, the result is:
T E = S / a n i = 1 n 1 i ( n 1 ) ξ i Var S / a n j = 1 n 1 j ( n 1 ) ξ j
Note that, exceptionally, the scaling of this test can also be defined by (9), without modifying the result. This is a consequence of the two equivalent forms for the weight function, Ω ( f ) = 1 / f log ( N ) 1 or Ω ( f ) = 1 / f log ( N ) .

2.2.3. Weights of Singletons

The above scaling (8) is valid in principle for all weights. However, in practice there is an important exception, that is, the weight Ω 1 of singletons. This is due to the fact that for n N , the number of derived singletons ξ 1 is the only estimator that is affected by very rare derived alleles (and often by sequencing errors, see [19]). More precisely, ξ 1 is actually the only estimator sensitive to the deviations from neutrality in alleles of frequency 1 / N < f < 1 / n , which represent a vast majority of the SNPs in the population and can contain interesting biological information. Therefore, if the contribution of these alleles is relevant for the test, we can enhance (or reduce) the weight Ω 1 by adding a factor Ω d s .
In the approach detailed in the previous sections, this additional contribution to Ω 1 is needed to take into account a contribution Δ Ω ( f ) to Ω ( f ) of the form Δ Ω ( f ) = Ω d s I ( f < ϕ ) / ϕ with ϕ 1 . As far as the maximum sample size never exceeds in practice n m a x 2 / ϕ , this function weights positively only alleles that appear as singletons.
Similarly, ω 1 and ω 1 can be enhanced by ω d s , ω d s that correspond to contributions Δ ω ( f ) = ω d s I ( f < ϕ ) / ϕ , Δ ω ( f ) = ω d s I ( f < ϕ ) / ϕ . The test of Fu and Li [6] fall into this case.
A similar argument applies also to the weights of the number of ancestral singletons, that is, Ω n 1 , ω n 1 , ω n 1 that can be enhanced by factors Ω a s , ω a s , and ω a s respectively. However, this case is more rare, the only interesting example being the tests of Achaz [19] that avoid sequencing errors by neglecting both derived and ancestral singletons.
Summarising the results up to this section, a test T Ω is completely defined by a function Ω ( f ) and two parameters Ω d s , Ω a s (that could depend on n) satisfying the conditions:
Ω d s + Ω a s + 0 1 d f Ω ( f ) = 0
and determining the weights through the formula:
Ω i ( n ) = Ω i n + Ω d s δ i , 1 + Ω a s δ i , n 1 1 n 1 Ω d s + Ω a s + j = 1 n 1 Ω j n
or by a pair of functions ω ( f ) , ω ( f ) and parameters ω d s , ω d s , ω a s , ω a s satisfying:
ω d s + ω a s + 0 1 d f ω ( f ) = ω d s + ω a s + 0 1 d f ω ( f ) = 1
and resulting in this formula for the scaling of the weights:
Ω i ( n ) = ω d s δ i , 1 + ω a s δ i , n 1 + ω i n ω d s + ω a s + j = 1 n 1 ω j n ω d s δ i , 1 + ω a s δ i , n 1 + ω i n ω d s + ω a s + j = 1 n 1 ω j n
As showed in the examples above and below, most of the tests in the literature have this general scaling, with the only exceptions the ones contained in [8] that are not weight-consistent in the above sense.

Example: Fu and Li’s F test

This test looks for an excess of very rare derived alleles as a possible signature of negative selection [6]. The only nonzero weights are ω d s = 1 and ω ( f ) = 1 / f log ( N ) , while ω ( f ) = ω d s = ω a s = ω a s = 0 . The resulting test is:
T F = ξ 1 S / a n Var ξ 1 S / a n
Note that this test has both singleton weights and a divergent weight function.

Example: Error-corrected tests of Achaz [19]

This class of tests is an attempt to correct for sequencing errors and biases in the data by removing the alleles where most of the problems manifest themselves, i.e., singletons (both ancestral and derived). With a slight generalisation of the proposal in [19], the weights of the singletons are chosen in such a way to cancel precisely the contributions of the weight functions:
Ω d s = Ω 1 n , Ω a s = Ω 1 1 n
or:
ω d s = ω 1 n , ω a s = ω 1 1 n , ω d s = ω 1 n , ω a s = ω 1 1 n
therefore, the final weights of derived or ancestral singletons are zero. These corrections can be applied in principle to any weight function.

2.2.4. Alternative Choices of Scaling

The choice of scaling discussed in the previous sections represents a quite simple and effective way to fix the dependence on n of a newly devised test. However, other choices are possible whose weights differ from the above ones for small n. The reason is that for n not too large, both the variance of order f ( 1 f ) / n i ( n i ) / n 3 in the estimation of the frequency f = i / n and the related uncertainty about how the frequencies are actually weighted in the test become important. This uncertainty originates from the (binomial) sampling of individuals from the population and there is some degree of arbitrariness in deciding how to account for it. Moreover, tests that take it into account could be inconsistent in the above sense.
A possible choice of scaling that uses the binomial sampling is the following: considering ω ( f ) , ω ( f ) as frequency distributions, the weights ω i , ω i are assigned from ω ( f ) , ω ( f ) through the same binomial sampling that is done for allele spectra, that is:
ω i = 0 1 d f n i f i ( 1 f ) n i ω ( f ) 0 1 d f ( 1 f n ( 1 f ) n ) ω ( f )
ω i = 0 1 d f n i f i ( 1 f ) n i ω ( f ) 0 1 d f ( 1 f n ( 1 f ) n ) ω ( f )
A simple example of this scaling (but with an highly divergent weight function) is given by the test for admixture [8] discussed previously. Optimal tests also follow this scaling.

Example: Test for admixture of Achaz [8]

This test is apparently not consistent and it does not follow the scaling (8). However, it follows another scaling related to the allele sampling. To understand this, consider the weight functions ω ( f ) = δ ( f 1 / 2 ) , ω ( f ) = 1 where δ ( f 1 / 2 ) is a Dirac delta function centred in 1 / 2 . (The Dirac delta δ ( f a ) is a function whose value is 0 if f a and + if f = a . The integral δ ( f a ) g ( f ) d f is g ( a ) if a is inside the range of integration and 0 otherwise. Technically speaking it is not a mathematical function, but a distribution, i.e., an element of a dual space of regular functions.) If we scale the weights according to (26) and (27), that is:
ω i = 0 1 d f n i f i ( 1 f ) n i ω ( f ) 0 1 d f ( 1 f n ( 1 f ) n ) ω ( f ) = n i 2 n 1 2 n + 1
ω i = 0 1 d f n i f i ( 1 f ) n i ω ( f ) 0 1 d f ( 1 f n ( 1 f ) n ) ω ( f ) = 1 n 1
then the corresponding test is precisely the one proposed by Achaz. Note that the strong dependence of the test from sample size does not come only from the choice of scaling, but also from the weight function chosen, that is highly divergent.

2.3. Optimal Tests

2.3.1. On the Existence of Generic Tests

An interesting question on the way to build good linear tests is the following: do there exist generic tests? A completely generic test for neutrality should be able to detect any deviation from the spectrum of the null model that is sufficiently large. Unfortunately, these tests do not exist. In fact, for every test defined by a set of weights Ω i it is possible to find a spectrum ξ i = α / i a n + ( 1 α ) Δ i that is maximally different from the standard spectrum at least in a range of frequencies and is nevertheless undetectable by the test because its average value on this spectrum is zero. This is expressed in a more formal way in the following theorem, which shows that even the complete lack of alleles in some range of frequencies could not be always detected.
Theorem 1. 
For every set of n real weights Ω i with i Ω i = 0 , there is a set of n real numbers Δ i c o n s t / i and a parameter α [ 0 , 1 ] that satisfy the conditions:
i i Ω i Δ i = 0 , min i [ 1 , n 1 ] α 1 i a n + ( 1 α ) Δ i = 0
The above limitation is not a consequence of the small sample size. This can be seen for example in the framework of the scaling theory discussed in this paper. In fact, for large sample sizes, the weights can be approximated by a weight function Ω ( f ) . In this context it is possible to prove the next theorem, that is a continuous equivalent of the previous one.
Theorem 2. 
For every piece-wise continuous weight function Ω ( f ) L [ 1 / N , 1 ] 1 such that 1 / N 1 Ω ( f ) d f = 0 , there is a smooth function Δ ( f ) c o n s t / f and a parameter α [ 0 , 1 ] that satisfy the conditions:
1 / N 1 d f f Ω ( f ) Δ ( f ) = 0 , inf f [ 0 , 1 ] α 1 f log ( N ) + ( 1 α ) Δ ( f ) = 0
Note that in principle this problem can be solved using multiple tests. In fact, multiple tests should be able to detect any strong deviation from the null spectrum, provided that the number of these tests is large enough, as can be seen from the following theorem.
Theorem 3. 
Given at least n 2 linearly independent sets of n 1 real weights Ω i with i Ω i = 0 , it is not possible to find a set of real numbers Δ i c o n s t / i such that i i Ω i Δ i = 0 .
This last theorem is only a formal result and the requirement of n 2 independent tests is too strong. In practice, a small (but good) set of tests can detect most of the reasonable and interesting deviations for realistic spectra.
The above theorems can be extended to the folded spectrum. In this section and the next ones, we will consider only tests based on the unfolded spectrum. The generalisation of the discussion to the folded spectrum is usually straightforward after substituting ξ i ( i = 1 n 1 ) with η i ( i = 1 n / 2 ).

2.3.2. Optimal Tests and Their Geometric Structure

From the theorems of the previous section, it is clear that a single test cannot detect all the possible deviations occurring in complicated evolutionary scenarios. However, it is still possible to optimise neutrality tests for a specific alternative evolutionary scenario. A simple optimality condition has been proposed by some of the authors in [10] in order to maximise the power of the test to detect a fixed alternative scenario. We use a different notation E ( ) and E ( ) for the expected value with respect to the null scenario (neutral model) E ( ) and the alternative scenario E ( ) . If the null spectrum is E ( ξ i ) = θ L ξ i 0 and the expected spectrum of the alternative scenario is E ( ξ i ) = θ L ξ ¯ i (note that it may include an average of frequencies in a number of different related scenarios, e.g., averaging over some of the parameters of the scenario), the condition for optimal tests is the maximisation of the average result of the test under the alternative scenario:
E ( T Ω ) = i = 1 n 1 Ω i θ L ξ ¯ i / ξ i 0 Var j = 1 n 1 Ω j ξ j / ξ j 0
This condition is based on the observation that the tests have mean zero and variance 1; therefore, if the distributions of the results of the tests are similar, the maximisation of the average value of the test should correspond to the maximisation of the average power of the test. It is also possible to maximise directly the power of the test, taking into account the different distribution of the results under the null and the alternative model; this possibility will be pursued in Section 3.1.
Interestingly, optimal tests show a geometric structure which becomes apparent after defining the scalar product between spectra:
ξ , ξ i , j ξ i c i j 1 ξ j
where c i j 1 is the inverse of the covariance matrix Cov ( ξ i , ξ j ) . Since Cov ( ξ i , ξ j ) is symmetric and positive, its inverse is also symmetric and positive, i.e., it is a positive bilinear form, therefore, the above expression defines a scalar product. Then, the optimal test for an alternative spectrum ξ ¯ can be written in the elegant form:
T O = ξ , ξ ¯ ξ , ξ 0 ξ 0 , ξ ¯ / ξ 0 , ξ 0 ξ ¯ , ξ ¯ ξ 0 , ξ ¯ 2 / ξ 0 , ξ 0
This expression can be easily obtained as a special case of the general formula (50) that we will discuss later in the context of nonlinear tests. A direct proof of this result can be found in [10] after substituting the scalar products with the definition (33).
The numerator of the test is actually the matrix element between ξ ¯ and ξ of the linear operator 1 P ξ 0 , where P ξ 0 is the projection operator along ξ 0 . In other words, it is proportional to the difference between the length of the projection of ξ on ξ ¯ and the length of the projection on ξ ¯ of the spectrum obtained by the projection of ξ on ξ 0 , as illustrated in Figure 2.
From this geometrical interpretation it is clear that if the spectrum ξ corresponds to the null spectrum θ L ξ 0 , then the two projections are equal and the result of the test is zero. On the other side, if the spectrum is the alternative spectrum θ L ξ ¯ , then the value of the test is:
T O ( m a x ) = θ L ξ ¯ , ξ ¯ ξ 0 , ξ ¯ 2 ξ 0 , ξ 0
which is the maximum value over all possible tests in the alternative scenario. The same expression, but with a minus sign, corresponds to the minimum value.
The denominator of the test is the square root of the matrix element of the linear operator 1 P ξ 0 between ξ ¯ and itself. Note that both the numerator and the denominator of the test do not change by adding any (possibly negative) multiple of ξ 0 to ξ ¯ , because ξ 0 lies in the kernel of 1 P ξ 0 . This means that optimal tests depend only on the expected deviations from the null spectrum in the alternative scenario. The result of the test is maximum when the deviations of the data from the null spectrum correspond exactly to the expected ones, and it is minimum when they are opposite to the expected ones.

2.4. Beyond Linear Neutrality Tests

2.4.1. Quadratic and Nonlinear Tests

Almost all the neutrality tests proposed in the literature are linear in the spectrum ξ i . As far as we know, there is only one exception, namely the G ξ test of Fu [11]. This test is a quadratic polynomial reminiscent of Hotelling’s t 2 statistics for the different components of the spectra:
G = i , j = 1 n 1 c i j 1 ( ξ i θ L ξ i 0 ) ( ξ j θ L ξ j 0 )
where c i j 1 is the inverse of the covariance matrix Cov ( ξ i , ξ j ) . Actually, the test proposed by Fu is an approximation to this test with a different normalisation, namely:
G ξ = 1 n 1 i = 1 n 1 ( ξ i θ L ξ i 0 ) 2 Var ( ξ i )
In this approximation, the off diagonal terms in the covariance can be neglected [9,11]. For large samples, the distribution of the results of the test G tends to a χ 2 distribution with n 1 degrees of freedom.
Fu’s approach cannot be extended to general quadratic or higher order tests, because the distribution of the results of the test would be generally unknown and not positive definite. For this reason we propose to rescale the tests to have zero mean and variance 1. With this normalisation, we expect that the distribution would asymptotically converge to a Gaussian N ( 0 , 1 ) for all tests. As an example, the (re)normalised version of Fu’s test would be:
T G = i , j = 1 n 1 c i j 1 ( ξ i θ L ξ i 0 ) ( ξ j θ L ξ j 0 ) ( n 1 ) Var i , j = 1 n 1 c i j 1 ( ξ i θ L ξ i 0 ) ( ξ j θ L ξ j 0 ) ( n 1 )
Since the only difference between this test and the original one is the normalisation and a shift by a constant factor n 1 , the power of the test is the same.
Now we present a systematic discussion of nonlinear tests that are generic polynomials (or eventually power series) in the spectrum ξ i . All the tests are rescaled to be centred (i.e., to have zero mean) and have variance 1. We denote by μ i j k the moments of the spectrum under the null model, that is, μ i j k = E ( ξ i ξ j ξ k ) . With this definition, μ i = θ L ξ i 0 . Note that all these moments depend on θ . In the approximation of unlinked (independent) sites and small θ , the second moments are equal to μ i j = θ L ξ i 0 δ i j + θ 2 L 2 ξ i 0 ξ j 0 .
The weights of general nonlinear tests can depend explicitly on θ , as seen in the previous example. To compute the values of the tests, the (unknown) parameter θ is substituted with an estimator θ ^ . Unlike the linear case, in this case there are two different classes of tests, related to the dependence on θ ^ of the centredness: strongly centred and weakly centred tests.
Strongly centred tests are tests that are always centred for any value of θ ^ , even if it is different from the actual value of θ . The general form for strongly centred tests is:
T Ω = i = 1 n 1 Ω i ( 1 ) ξ i + i , j = 1 n 1 Ω i j ( 2 ) ξ i ξ j + i , j , k = 1 n 1 Ω i j k ( 3 ) ξ i ξ j ξ k + Var i = 1 n 1 Ω i ( 1 ) ξ i + i , j = 1 n 1 Ω i j ( 2 ) ξ i ξ j + i , j , k = 1 n 1 Ω i j k ( 3 ) ξ i ξ j ξ k +
with the real symmetric weights Ω i j k ( n ) satisfying the set of conditions:
0 = i = 1 n 1 Ω i ( 1 ) μ i ( m ) + i , j = 1 n 1 Ω i j ( 2 ) μ i j ( m ) + , m = 1 , 2 , 3
where we denote by μ i j k ( p ) the p-th term of the Taylor expansion with respect to θ L of μ i j k (in other words, μ i j k = p θ p L p μ i j k ( p ) , where the coefficients μ i j k ( p ) are independent on θ ). The sum can be limited to polynomials of some finite order in ξ i or it can be a (convergent) power series. If we introduce the notation I = i j k to denote a group of n I indices, we can rewrite the test in the simpler form:
T Ω = I Ω I ( n I ) ( ξ ξ ) I Var I Ω I ( n I ) ( ξ ξ ) I
with the conditions:
0 = I Ω I ( n I ) μ I ( m ) , m = 1 , 2 , 3
If we constrain these tests to be first order polynomials in ξ i , we recover the linear case with Ω i ( 1 ) = Ω i / ξ i 0 . Note that linear tests are always strongly centred. In fact, in the infinite site model the spectrum is always proportional to θ , which consequently factorises out by linearity and therefore has no effect on the centredness.
Weakly centred tests are tests that are centred but not strongly centred, i.e., they are centred if and only if θ ^ = θ . The general form for weakly centred tests is:
T Γ = γ + i = 1 n 1 Γ i ( 1 ) ξ i + i , j = 1 n 1 Γ i j ( 2 ) ξ i ξ j + i , j , k = 1 n 1 Γ i j k ( 3 ) ξ i ξ j ξ k + Var γ + i = 1 n 1 Γ i ( 1 ) ξ i + i , j = 1 n 1 Γ i j ( 2 ) ξ i ξ j + i , j , k = 1 n 1 Γ i j k ( 3 ) ξ i ξ j ξ k +
with the condition:
0 = γ + i = 1 n 1 Γ i ( 1 ) μ i + i , j = 1 n 1 Γ i j ( 2 ) μ i j + i , j , k = 1 n 1 Γ i j k ( 3 ) μ i j k +
where the Γ i j k are real symmetric weights, possibly dependent on θ . We can simplify these expressions using the same notation as above, obtaining the simpler form:
T Γ = γ + I Γ I ( n I ) ( ξ ξ ) I Var γ + I Γ I ( n I ) ( ξ ξ ) I
with the condition:
0 = γ + I Γ I ( n I ) μ I
Additionally, for this class of tests the sum can be limited to polynomials of fixed order or extended to power series. Note that the rescaled version of the G test by Fu presented above belongs to this class.
The important difference between strongly and weakly centred tests is related to the robustness with respect to a biased estimation of θ . Since the class of weakly centred tests is much larger than the class of strongly centred ones, it should be easier to find powerful tests in the former class than in the latter. However, even if weakly centred tests could be more powerful, they would not be centred in scenarios where the value of θ could not be estimated precisely. On the other side, strongly centred tests are robust with respect to a bad estimation of θ and therefore they would be preferable in scenarios where an unbiased estimation of θ is troublesome.
The scaling rule (8) can be generalised to nonlinear tests in terms of functions Ω ( n I ) ( f 1 , f 2 f n I ) for strongly centred and Γ ( n I ) ( f 1 , f 2 f n I ) for weakly centred tests:
Ω I ( n I ) 1 n n I Ω ( n I ) i n , j n , k n
Γ I ( n I ) 1 n n I Γ ( n I ) i n , j n , k n
Fixing the precise scaling is more ambiguous than in the linear case because there are many different ways to preserve centredness. For this reason, the choice of scaling would be different for strongly and weakly centred tests and will not be discussed here.
All the possible nonlinear neutrality tests based on the frequency spectrum fall into one of the two classes presented in this section and have the form (41) and (42), or (45) and (46). Since both these classes contain an infinite number of possible choices of weights, the only reasonable criterion to study general nonlinear tests is to select the most powerful or interesting ones. Apart from the Hotelling choice of Fu [11], the most interesting choice is apparently the subclass of nonlinear optimal tests, which will be discussed in the next sections.

2.4.2. Strongly Centred Optimal Tests

As discussed for the linear case, optimal tests depend on the expected alternative scenario. In the nonlinear case, in principle it would be possible to find generic optimal tests, but there is no clear framework to obtain them. For this reason we limit our study to the case of optimal tests for a specific alternative scenario. We denote by μ ¯ i j k = E ( ξ i ξ j ξ k ) the moments of the alternative spectrum for this scenario.
Since we use the same normalisation for linear and nonlinear tests, the optimality condition corresponds to the maximisation of the expected value of the test under the alternative scenario:
E ( T Ω ) = I Ω I ( n I ) μ ¯ I Var I Ω I ( n I ) ( ξ ξ ) I
and can be justified as in the linear case.
We denote by I ˜ the ordered sequence of the indices contained in I = i j k and by σ I the number of distinct permutations of the sequence I , i.e., the total number of permutations divided by the number of permutations that leave I invariant. The main result for the optimal weights is presented in this theorem.
Theorem 4. 
The maxima of E ( T Ω ) correspond to the weights:
Ω I ( n I ) = 1 σ I L ˜ C I ˜ L ˜ 1 μ ¯ L ˜ k l L ˜ C I ˜ L ˜ 1 μ L ˜ ( k ) M k l J ˜ , K ˜ μ J ˜ ( l ) C J ˜ K ˜ 1 μ ¯ K ˜
where the matrices C I ˜ J ˜ 1 and M k l satisfy the identities:
K ˜ C I ˜ K ˜ 1 μ K ˜ J ˜ μ K ˜ μ J ˜ = δ I ˜ J ˜
r M k r I ˜ , L ˜ μ I ˜ ( r ) C I ˜ L ˜ 1 μ L ˜ ( l ) = δ k l
Moreover, the variance of the corresponding unnormalised test under the null model is equal to its expected value under the alternative model:
Var I Ω I ( n I ) ( ξ ξ ) I = I Ω I ( n I ) μ ¯ I
Note that in general all the weights of the above optimal solution (50) are nonzero, therefore the maximum average value of the test for optimal tests built on polynomials of degree d increases with the degree d. This suggests that optimal tests of higher degree should be more powerful than linear optimal tests.
We provide explicit formulae for the above weights for the optimal quadratic test in the independent sites approximation. Given E ( ξ i ) = μ i and E ( ξ i ) = μ ¯ i , the relevant weights Ω I ( n I ) are:
Ω i ( 1 ) = ( Σ μ + 2 Σ μ ¯ ) μ ¯ i μ i Σ μ ¯ Σ μ 1 2 μ ¯ i 2 μ i 2 Σ μ ¯ 2 Σ μ 2
Ω i i ( 2 ) = μ ¯ i μ i Σ μ ¯ Σ μ + 1 2 μ ¯ i 2 μ i 2 Σ μ ¯ 2 Σ μ 2
Ω i j ( 2 ) = 1 2 μ ¯ i μ ¯ j μ i μ j Σ μ ¯ 2 Σ μ 2 μ ¯ i μ i Σ μ ¯ Σ μ μ ¯ j μ j Σ μ ¯ Σ μ
where Σ μ = i = 1 n 1 μ i and Σ μ ¯ = i = 1 n 1 μ ¯ i . All these formulae are also valid for the folded spectrum if the appropriate μ i and μ ¯ i are used. These results are discussed in Appendix A.7.
For optimal tests of higher degree, explicit expressions become cumbersome and the numerical implementation of the test (50) and the matrices (51) and (52) is more convenient.

2.4.3. Weakly Centred Optimal Tests

In this case the optimality condition corresponds to the maximisation of the expression:
E ( T Γ ) = γ + I Γ I ( n I ) μ ¯ I Var γ + I Γ I ( n I ) ( ξ ξ ) I
with the same condition:
0 = γ + I Γ I ( n I ) μ I
The simplest case corresponds to a first order polynomial:
T Γ = γ + i = 1 n 1 Γ i ( 1 ) ξ i γ 2 + 2 γ j = 1 n 1 Γ j ( 1 ) μ j + j = 1 n 1 k = 1 n 1 Γ j ( 1 ) Γ k ( 1 ) μ j k
whose maximum corresponds to the optimal weights:
Γ i ( 1 ) = j = 1 n 1 c i j 1 μ ¯ j μ j , γ = j = 1 n 1 k = 1 n 1 μ j c j k 1 μ ¯ k μ k
where c i j 1 is the inverse matrix of the covariance matrix c i j = μ i j μ i μ j . Since γ 0 for this optimal test, the value of this test for the specific scenario for which it is built is larger than the value of the corresponding linear optimal test. In fact the maximum of the test is:
E ( T Γ ) = j = 1 n 1 k = 1 n 1 μ ¯ j μ j c j k 1 μ ¯ k μ k
that should be compared to the maximum of the optimal test for the linear case, which can be rewritten as:
E ( T Ω ) l i n e a r = j = 1 n 1 k = 1 n 1 μ ¯ j μ j c j k 1 μ ¯ k μ k j = 1 n 1 k = 1 n 1 μ j c j k 1 μ ¯ k μ k 2 j = 1 n 1 k = 1 n 1 μ j c j k 1 μ k
The comparison shows clearly that nonlinear optimal tests are always more powerful than linear optimal tests for the same scenario.
The form of the results for the general case is similar to this simple case.
Theorem 5. 
The maxima of E ( T Γ ) correspond to the weights:
Γ I ( n I ) = 1 σ I J ˜ C I ˜ J ˜ 1 μ ¯ J ˜ μ J ˜ , γ = J ˜ μ J ˜ K ˜ C J ˜ K ˜ 1 μ ¯ K ˜ μ K ˜
where C I ˜ J ˜ 1 satisfied the identity:
K ˜ C I ˜ K ˜ 1 μ K ˜ J ˜ μ K ˜ μ J ˜ = δ I ˜ J ˜
Moreover, the variance of the corresponding unnormalised test under the null model is equal to its expected value under the alternative model:
Var γ + I Γ I ( n I ) ( ξ ξ ) I = I Γ I ( n I ) μ ¯ I + γ
Also in this case, the power of optimal tests based on polynomials of higher degree increases with the degree of the polynomial.
It is possible to give explicit expressions of the above matrix and moments for the optimal quadratic test. The formulae for the weights Γ I ( n I ) for the unfolded spectrum are:
Γ i ( 1 ) = ( Σ μ + 2 Σ μ ¯ ) μ ¯ i μ i 1 1 2 μ ¯ i 2 μ i 2 1
Γ i i ( 2 ) = 1 2 μ ¯ i μ i 1 2
Γ i j ( 2 ) = 1 2 μ ¯ i μ i 1 μ ¯ j μ j 1
γ = 1 2 ( Σ μ Σ μ ¯ ) ( Σ μ + 2 Σ μ ¯ )
These results are valid in the independent sites approximation. They are also valid for the folded spectrum if the appropriate μ i and μ ¯ i are used. An expression for the denominator of the test in the independent sites approximation can be found in Appendix A.7.

2.5. Empirical Simulations and Code Used for Studying the Statistical Power of Neutrality Tests

We obtained the frequency spectrum of samples for different subdivision and expansion models using one million iterations. Simulation parameters, as well as all the data frequencies from the simulations are included in Zenodo (DOI: 10.5281/zenodo.8279694). Linear and nonlinear tests were calculated using our own code, also available in the same link. Additionally, linear and nonlinear optimal tests are also included in the program mstatspop (https://github.com/cragenomica/mstatspop, accessed on 15 August 2023), to facilitate the calculation of these tests by the users.

3. Results

3.1. General Optimisation of Linear Tests

The condition for optimal tests is the maximisation of E ( T Ω ) under the alternative scenario. However, a better approach would by the maximisation of the power of the test to reject the neutral model in the alternative scenario, given a choice of significance level α . This approach requires the knowledge of the form of the probability distributions p ( T Ω = t | H 0 ) , p ( T Ω = t | H 1 ) where H 0 and H 1 are the null and alternative model, or equivalently of all the moments of the spectrum E ( ξ i ξ j ξ k ) and E ( ξ i ξ j ξ k ) .
Since this information is usually not available in analytic form and hard to obtain computationally, we limit to the case where the distribution can be well approximated by a Gaussian both for the null and for the expected model. Then, the only information needed are the spectra μ i = E ( ξ i ) , μ ¯ i = E ( ξ i ) and their covariance matrices c i j = E ( ξ i ξ j ) E ( ξ i ) E ( ξ j ) , c ¯ i j = E ( ξ i ξ j ) E ( ξ i ) E ( ξ j ) .
We expect that both in this approximation and in the general case, the tests with maximum power will depend on the significance level chosen, therefore limiting the interest of these test and the possibilities of comparison between results of the test on samples from different experiments.
We call τ = erf 1 ( 1 2 α ) the z-value corresponding to the critical p-value α . In the Gaussian approximation, the power is given by the following expression:
Power = 1 2 1 + erf j μ ¯ j Ω j τ j , k c j k Ω j Ω k j , k c ¯ j k Ω j Ω k
then its maximisation is equivalent to the maximisation of:
j μ ¯ j Ω j τ j , k c j k Ω j Ω k j , k c ¯ j k Ω j Ω k
In the general case, the weights corresponding to the maximum depend explicitly on τ and therefore on α . This dependence is expected but unwanted, since the interpretation of the test depends explicitly on the critical p-value chosen.
There is only one case with weights independent on τ , that is the case of c ¯ i j (approximately) proportional to c i j . In this case the maximisation of the power of the test is (approximately) equivalent to the maximisation of the average result of the test, which is precisely the condition for optimal tests in the sense of [10]. In fact, in this case, optimal tests correspond precisely to an approximation of the likelihood-ratio tests under the assumption of Gaussian likelihood functions, and are therefore approximately the most powerful tests because of the Neyman–Pearson lemma.
As a side note, there is also a regime of values of α such that the weights corresponding to maximum power are independent of α , that is, the regime τ ( α ) 1 . In this case the power is an increasing function of j , k c ¯ j k Ω j Ω k / l , m c l m Ω l Ω m and the weights are simply given by the null eigenvector (or linear combination of null eigenvectors) of the matrix c ¯ i j χ c i j , where χ is uniquely defined by the requirement that c ¯ i j χ c i j be a negative semidefinite matrix with at least a null eigenvalue. However, this regime is uninteresting because such small significance levels are practically useless (if τ 10 , the corresponding critical p-value is α 10 20 ). However, it could be possible to build interesting tests with higher power by selecting linear combinations of the weights of the two α -independent tests discussed above, that is, optimal tests and tests that maximise the alternative/null variance ratio j , k c ¯ j k Ω j Ω k / l , m c l m Ω l Ω m .

3.1.1. Generalised Optimality Conditions

In a more general linear framework, the (normalised) test has the form T = i = 1 n 1 Ω i ξ i / ξ i 0 . We denote its moments under the standard neutral model (SNM) and the alternative model by:
E 0 = E ( T ) S N M = θ L i = 1 n 1 Ω i , V 0 = Var ( T ) S N M = i , j = 1 n 1 Ω i Ω j c i j / ξ i 0 ξ j 0
E = E ( T ) a l t = θ L i = 1 n 1 Ω i ξ ¯ i / ξ i 0 , V = Var ( T ) a l t = i , j = 1 n 1 Ω i Ω j c ¯ i j / ξ i 0 ξ j 0
where E ( ξ i ) S N M = θ L ξ i 0 , E ( ξ i ) a l t = θ L ξ ¯ i , Cov ( ξ i , ξ j ) S N M = c i j and Cov ( ξ i , ξ j ) a l t = c ¯ i j . For the standard neutral model ξ i 0 = 1 / i .
The optimality condition can be the maximisation of a general function M ( E 0 , V 0 , E , V ) of these quantities with respect to the weights Ω i . Since we are dealing with linear combination of the frequency spectrum with mean E 0 = 0 and variance V 0 = 1 , the function effectively depends on E , V only. Maximisation of power (in the Gaussian approximation), given a significance level α , is equivalent to the maximisation of:
M ( E , V ) = E Φ 1 ( 1 α ) V
If there is some knowledge of the variance of the alternative spectrum, or at least of the contribution for unlinked sites, maximisation of power is not the only possible optimisation. In other words, it is possible to optimise with respect to other functions M ( E , V ) of the alternative mean E and variance V of the test, in order to obtain, e.g., more robust or conservative tests.
For example:
  • “Optimal tests”: if V is assumed to be completely unknown, the best we can do is minimise the p-value of the expected alternative spectrum, that is, in the Gaussian approximation p = 1 Φ ( ( E E 0 ) / V 0 ) where Φ ( z ) is the cumulative distribution function for the standard normal distribution. This is equivalent to the maximisation of:
    M ( E 0 , V 0 , E , V ) = E E 0 V 0
  • Most powerful one-tail tests: in the Gaussian approximation, the power of the right tail of test to reject the neutral Wright–Fisher model given a significance level α is Power = 1 Φ ( ( E 0 + τ V 0 E ) / V ) , where τ = Φ 1 ( 1 α ) . Maximising this power is equivalent to the maximisation of:
    M ( E 0 , V 0 , E , V ) = E E 0 τ V 0 V
    If V V 0 , this is equivalent to the previous case and we retrieve the optimal tests of [10] that are therefore the most powerful tests in this approximation.
  • Most powerful two-tails tests: in the Gaussian approximation, the power of both tails of the test to reject the neutral Wright–Fisher model is:
    M ( E 0 , V 0 , E , V ) = 1 Φ E 0 + τ V 0 E V + Φ E 0 τ V 0 E V
    where τ = Φ 1 ( 1 α / 2 ) and α is the significance level. If E 0 = 0 , this maximisation is equivalent to the maximisation of ( E E 0 τ V 0 ) / V similar to the previous case.
  • Penalisations for high or low variance, depending on an extra parameter ν , such as:
    M ( E 0 , V 0 , E , V ) = E E 0 ( V 0 + V ) ν

3.1.2. Tunable Optimal Tests

Interestingly, it turns out that the choice of an optimisation criterion—i.e., of a function M ( E , V ) to be maximised—can be performed simply by tuning a parameter λ in a simple class of tests that we call “tunable optimal tests”.
The family of optimised tests with tunable parameter λ has the simple form:
T = i = 1 n 1 i Ω i ( λ ) ξ i Var ( i = 1 n 1 i Ω i ( λ ) ξ i )
with weights:
Ω i ( λ ) = 1 i 1 a n 1 + λ i ξ ¯ i j = 1 n 1 1 j ( 1 + λ j ξ ¯ j ) 1
where a n = j = 1 n 1 1 / j .
The interest of this family of tests lies in the following property: for every possible choice of the optimisation function M ( E , V ) , the test corresponding to the maximum value of this function belongs to this family (see Appendix B).
Usual optimal tests [10] are obtained from the maximisation of M ( E , V ) = E and correspond to λ = 0 + , that is, to the usual weights Ω i = ξ ¯ i 1 i j = 1 n 1 ξ ¯ j a n .
More generally, λ can be obtained directly by evaluating E , V with the weights (80) and then looking for the maximisation of M ( E ( λ ) , V ( λ ) ) . Note that there could be several local maxima.
This class of tests is simple but far more flexible than usual optimal tests. However, note that the exact choice of weights depends explicitly on θ and α . Furthermore, the smoothness of the choice of weights with respect to the evolutionary parameters is not assured. In principle, a slight change of evolutionary scenario could change the optimal weights abruptly.

3.2. Simulations of the Power of Optimal Tests

Since a theoretical evaluation of the power of optimal tests of different degree is not possible, we evaluate numerically the power of some of these tests in different scenarios. We consider the best possible case, that is, we assume that the precise value of θ is known. Moreover we assume unlinked sites and θ 1 . In this approximation, as shown in Appendix A.7, the moments E ( ξ i ξ j ξ k ) depend only on the first moments μ i = θ L ξ i 0 and similarly E ( ξ i ξ j ξ k ) depend only on μ ¯ i = θ L ξ ¯ i , therefore optimal tests depend only on the alternative and null average spectra.
Note that for numerical simulations of optimal tests of higher degree, the numerical implementation can be made easier if all the occurrences of inverse covariance matrices C I ˜ J ˜ 1 in the the above formulae are replaced with the corresponding second moments μ I ˜ J ˜ 1 , both in the expressions (50), (63), and in the definition (52). The test is the same because of the centredness condition, as it can be verified explicitly.
We compare four optimal tests. The first two are the linear and quadratic strongly centred optimal tests, which are denoted by T O ( 1 ) s c and T O ( 2 ) s c respectively. The third test is the weakly centred optimal test T O ( 1 ) w c based on a first order polynomial and presented in (59). The last optimal test T O ( 2 ) w c is also weakly centred and based on on a quadratic polynomial. The explicit formulae for the computation of the weights of T O ( 2 ) s c and T O ( 2 ) w c were given in Equations (54)–(56) and (66)–(69).
We simulated two demographic processes: (A) subdivision, where two populations having identical size exchange individuals given a symmetric migration rate M, then individuals are sampled from one population only; (B) expansion, where the population size changes by a factor N 0 / N = 10 at a time T before present (in units of 4 N generations). For each value of the parameters M and T, 10 6 simulations were performed with mlcoalsim v1.98b [20] for a region of 1000 bases with variability θ = 0.05 and recombination ρ = and a sample size of n = 20 (haploid) individuals. Confidence intervals at 95% level were estimated from 10 6 simulations of the standard neutral coalescent with the same parameters.
In Figure 3 we compare the power of the tests in the best possible situation, namely when θ is known with good precision. In this condition all optimal tests should give the best results. In fact, the power of weakly centred tests ( T O ( 1 ) w c and T O ( 2 ) w c ) is impressive, being around 100 % for a large part of the parameter space and decreasing for large migration rates (Figure 3A) and long times (Figure 3B) as every other test, because the frequency spectrum for these cases becomes very similar to the standard spectrum. So, weakly centred tests show a very good theoretical performance, counterbalanced by their lack of robustness. The power of T O ( 1 ) w c and T O ( 2 ) w c are almost identical, therefore the contribution of the quadratic part to T O ( 2 ) w c is probably not relevant.
On the other hand, strongly centred optimal tests are more powerful than Tajima’s D but less powerful than weakly centred tests, as expected. However, there is a sensible difference in power between T O ( 1 ) s c and T O ( 2 ) s c : in the range of parameters where the power of weakly centred tests is around 100 % , both strongly centred tests show a good performance not so far from the weakly centred ones, while in the less favourable range the quadratic test T O ( 2 ) s c , while performing worse than the weakly centred tests, has a power that is 20 % higher than the linear test T O ( 1 ) s c . Taking into account the robustness of the tests, these simulations show that optimal tests like T O ( 2 ) s c could be an interesting alternative to the usual linear tests.

4. Discussion

In this paper we have presented a systematic analysis of neutrality tests based on the site frequency spectrum. This study is intended to extend and complete the recent works in [8,10] by extending the study of the linear neutrality tests presented by Achaz. The properties of linear neutrality tests and optimal tests have been studied using this framework. A new class of “tunable” optimal tests that include usual optimal tests as a special case have been proposed, using a generalisation of the optimisation approach for linear tests.
The aim of the paper is to give mathematical guidelines to build new and more effective tests to detect deviations from neutrality. The proposed guidelines are the scaling relation (8) and the optimality condition based on the maximisation of E ( T Ω ) . Both these guidelines are thoroughly explained and discussed.
One of the strengths of optimal neutrality tests (initially presented in [10]) is the fact that their weights scale automatically with the aim to avoid a dependence with the sample size, enabling interpretation of the results of the test in a sample-size-independent way. For other tests, different scaling strategies were analysed and evaluated, discussing the suitability of weighting methods and the scaling of existing neutrality tests.
The different neutral tests studied and developed in this paper have different features, which make them suitable for different purposes. For example, a general neutrality test where the weights are scaled to obtain interpretable results may be sufficient, with minimum effort, to reject the null model and to interpret results, but the statistical power when faced with a specific alternative hypothesis can be low. Instead, optimal tests become a better approach if the alternative hypothesis is clearly formulated and the data is not clearly from the null hypothesis. In respect to the differences between linear and nonlinear optimal test, while nonlinear optimal tests have been shown to be more powerful than linear ones (and weakly centred tests more powerful than strongly centred ones), power is not the only important issue: robustness must also be taken into consideration.
In fact, there are three important remarks on the relative robustness of these tests. The first one is that, as already discussed, centredness of weakly centred tests is not robust with respect to a biased estimate of θ , therefore these tests should be preferred to strongly centred tests only in situations where the value of θ is well known or a good estimate is available.
The second remark is that neither the weights nor the results of linear optimal tests do depend on the value of θ and on the number of segregating sites S, while the weights of nonlinear optimal tests have an explicit dependence on θ and their results depend not only on the spectrum but also on S; therefore, the interpretation of the results of these tests is more complicated. However, this is not necessarily true for homogeneous tests of any degree, like the quadratic G ξ test by Fu. An interesting development of this work could be a study of homogeneous tests of a given degree k satisfying the optimality condition, which can be easily obtained from Equation (50) by restricting all ordered sequences of indices I ˜ , J ˜ , K ˜ , L ˜ to contain precisely k indices (along with some “traceless” condition, in case). These homogeneous optimal tests (or at least some subclass of them) should depend weakly on S.
The third remark is that linear optimal tests have two interesting properties that are not shared by other tests: they depend only on the deviations from the null spectrum and they have an easy interpretation in terms of these deviations, that is, they are positive if the observed deviations are similar to the expected ones and negative if the observed deviations are opposite to the expected ones. These features give an important advantage to linear optimal tests.
A fourth remark is that “tunable” optimal tests can be built to achieve weights that correspond to maximum power to reject the null hypothesis for a given alternative scenario but uncertain power calculations (e.g., when the variance of the alternative scenario is not known). This new class of neutrality tests is highly flexible and only depends on a single parameter and the mean alternative spectrum. Nevertheless, since the test can be used even when the alternative scenario is not fully defined, there may be situations where optimising its power can result in the interpretability or robustness of the test being compromised.
Tests based on the frequency spectrum of polymorphic sites are fast, being based on simple matrix multiplications, and can therefore be applied to genome-wide data. Moreover, they can be used as summary statistics for Approximate Bayesian Computation or other statistical approaches to the analysis of sequence data. While linear tests are often used in this way, the nonlinear tests presented in this paper contain more information (related to the covariances and higher moments of the frequency spectrum) that could increase the power of these analyses.

Author Contributions

Conceptualization, S.E.R.-O., G.A. and L.F.; Methodology, S.E.R.-O. and L.F.; Software, S.E.R.-O.; Formal analysis, G.M. and L.F.; Writing—original draft, S.E.R.-O., G.M. and L.F.; Writing—review & editing, S.E.R.-O., G.M., G.A. and L.F.; Funding acquisition, S.E.R.-O. All authors have read and agreed to the published version of the manuscript.

Funding

This work was funded by grant CGL2009-0934 and PID2020-119255GB-I00 (MICINN, Spain) to S.R.O.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

No data was used in this paper.

Acknowledgments

We thank M. Perez-Enciso and J. Rozas for useful comments.

Conflicts of Interest

The authors declare no conflict of interest.

Appendix A. Technical Results

Appendix A.1. Transformations of Weights and Invariance of Tests

We report some theorems on the invariance of the tests under affine transformations. These results can be easily proved and are implicitly used throughout this paper.
Theorem A1. 
A test of the form (3) does not change its value if all the weights Ω i are rescaled by a common factor λ > 0 , that is:
Ω i λ Ω i T Ω sign ( λ ) T Ω
Note that the invariance of the tests mean that these transformations define equivalence classes of weights, i.e., sets of different weights that actually correspond to the same test. In particular, this theorem implies that the space of possible tests, in terms of the weights Ω i , is not homeomorphic to R n 2 (which would be the subspace of weights in R n 1 that satisfy the linear condition (4)) but to its quotient with respect to the invariance (multiplicative) group R + , that is, the ( n 3 ) -dimensional sphere S n 3 = R n 2 / R + .
Theorem A2. 
A test of the form (7) does not change its value under an affine transformation of parameters ( λ , ρ i ) on the weights ω i , ω i with a common rescaling factor λ > 0 , that is:
ω i λ ω i + ρ i , ω i λ ω i + ρ i T Ω sign ( λ ) T Ω
However, the estimators (5) are unbiased only if the rescaling factor satisfies the condition λ = 1 i = 1 n 1 ρ i .

Appendix A.2. Generalised D′ Tests for Multilocus Analysis

The statistic D [21], which is defined as the ratio of Tajima’s D versus its minimum value (given a fixed number of segregating sites), has been used in the literature for multilocus analyses [21,22,23], arguing that the value of Tajima’s D is affected by the length, the sample size, and the number of segregating sites of each studied locus and therefore the values of each locus are not directly comparable.
The contribution of each locus to the heterogeneity is hardly known. Tajima’s D is robust to differences in the level of variability (the variance is approximately equal to one) and also quite robust against differences in sample size (as will be shown in the next part), although the quantitative values of Tajima’s D for each condition are someway different and therefore the comparison between values is not simple. The proposal of Schaeffer is to use the test:
D = D min ( D ) S = S o b s
as a (re)normalised version of Tajima’s D. S o b s is the observed number of segregating sites in the sample. This proposal can be generalised for all the tests of the form (3) as follows:
T Ω = T Ω min ( T Ω ) S = S o b s = i = 1 n 1 i Ω i ξ i min ( j Ω j ) S o b s
This appears to be the natural generalisation of D to general linear tests. For the optimal tests, there are other possibilities.

Appendix A.3. Tests Based on the Folded SFS

If an outgroup is not available, then the test should be based on the folded spectrum and has the general form:
T Ω * = θ ^ ω * θ ^ ω * Var ( θ ^ ω * θ ^ ω * ) = i = 1 n / 2 i ( n i ) ( 1 + δ n , 2 i ) ( ω i * ω i * ) η i Var j = 1 n / 2 j ( n j ) ( 1 + δ n , 2 j ) ( ω j * ω j * ) η j = = i = 1 n / 2 i ( n i ) ( 1 + δ n , 2 i ) Ω i * η i Var j = 1 n / 2 j ( n j ) ( 1 + δ n , 2 j ) Ω j * η j
where the weights Ω i * = ω i * ω i * satisfy the conditions:
i = 1 n / 2 ω i * = 1 , i = 1 n / 2 ω i * = 1 i = 1 n / 2 Ω i * = 0
and:
θ ^ ω * = 1 L i = 1 n / 2 i ( n i ) ( 1 + δ n , 2 i ) n ω i * η i , θ ^ ω * = 1 L i = 1 n / 2 i ( n i ) ( 1 + δ n , 2 i ) n ω i * η i
are unbiased estimators of θ .

Appendix A.4. Scaling of Weights in Tests without an Outgroup

The above arguments can be repeated in a straightforward way for the tests T Ω * based on the folded spectrum η i . The only relevant difference is that the frequency f of the minor allele in the population is always less than 50%, that is, f ( 0 , 1 / 2 ] . For consistency with the unfolded case, the weight η n / 2 is reduced by a factor 2. Moreover, the additional parameters related to the weights of singletons cannot distinguish between ancestral and derived alleles and therefore reduce to Ω s * , ω s * , ω s * . These parameters, together with the functions Ω * ( f ) , ω * ( f ) , and ω * ( f ) , should satisfy the conditions:
Ω s * + 0 1 / 2 d f Ω * ( f ) = 0 , ω s * + 0 1 / 2 d f ω * ( f ) = ω s * + 0 1 / 2 d f ω * ( f ) = 1
The formulae that determine the scaling of the weights are:
Ω i * ( n ) = 1 1 + δ n , 2 i Ω * i n + Ω s * δ i , 1 1 n / 2 Ω s * + j = 1 n / 2 1 1 + δ n , 2 j Ω * j n
Ω i * ( n ) = ω s * δ i , 1 + ω * i n / ( 1 + δ n , 2 i ) ω s * + j = 1 n / 2 ω * j n / ( 1 + δ n , 2 j ) ω s * δ i , 1 + ω * i n / ( 1 + δ n , 2 i ) ω s * + j = 1 n / 2 ω * j n / ( 1 + δ n , 2 j )
The weights of the folded versions of Tajima’s D and Fu and Li’s F * test follow this scaling. The nonzero weight functions are ω * ( f ) = 1 , ω * ( f ) = 1 / ( log ( N ) f ( 1 f ) ) for Tajima’s D and ω s * = 1 , ω * ( f ) = 1 / ( log ( N ) f ( 1 f ) ) for the test of Fu and Li.

Appendix A.5. Scaling of Optimal Tests

Optimal tests have weights proportional to the expected allele distribution ω i = ξ ¯ i / j = 1 n 1 ξ ¯ j and to the null allele distribution ω i = ξ i 0 / j = 1 n 1 ξ j 0 . Therefore, the weights of an optimal test follow the same scaling with sample size as the allele distributions. Denoting by ξ ¯ ( f ) and ξ 0 ( f ) the spectra of expected and null allele frequencies in the whole population, the spectra for the sample are obtained by binomial sampling:
ξ i = 1 / N e 1 d f P b i n ( i ; n , f ) ξ ( f ) P b i n ( i ; n , f ) = n i f i ( 1 f ) n i
from the spectra ξ ( f ) = ξ ¯ ( f ) and ξ ( f ) = ξ 0 ( f ) , respectively. Therefore the scaling of the allele distributions is:
ξ ¯ i j = 1 n 1 ξ ¯ j = 1 / N e 1 d f n i f i ( 1 f ) n i ξ ¯ ( f ) 1 / N e 1 d f ( 1 f n ( 1 f ) n ) ξ ¯ ( f )
ξ i 0 j = 1 n 1 ξ j 0 = 1 / N e 1 d f n i f i ( 1 f ) n i ξ 0 ( f ) 1 / N e 1 d f ( 1 f n ( 1 f ) n ) ξ 0 ( f )
which is precisely the scaling (26) and (27) with weight functions ω ( f ) ξ ¯ ( f ) and ω ( f ) ξ 0 ( f ) . This scaling does not correspond to the scaling (8) suggested in this paper, but it takes into account the sampling process in a straightforward way, being based on the expected and null allele distributions for the sample and therefore immediately related to the binomial sampling of alleles from the population.
Note that these weights actually follow the scaling (8) for large n, with the same weight functions ω ( f ) ξ ¯ ( f ) and ω ( f ) ξ 0 ( f ) . This agrees with the fact that when the sample size is large enough, the variance of the sampling process can be safely ignored and all reasonable choices of scaling are equivalent to our proposal (8).

Appendix A.6. Generalising D′ for Optimal Test

The D statistics of [21] can be generalised for optimal tests as it was done for general linear tests. In particular, for a fixed number of segregating sites S o b s , the generalisation for optimal tests in the approximation of unlinked sites and θ 1 is:
T O = i = 1 n 1 Ω i ξ i / ξ i 0 min j ( Ω j / ξ j 0 ) S o b s = i = 1 n 1 ( ξ i / S o b s ) ( ξ ¯ i / j = 1 n 1 ξ ¯ j ) / ( ξ i 0 / j = 1 n 1 ξ j 0 ) 1 min k ( ξ ¯ k / l = 1 n 1 ξ ¯ l ) / ( ξ k 0 / l = 1 n 1 ξ l 0 ) 1
which has the interesting property of depending only on the allele frequency distributions.
However, in the case of optimal tests there is another possibility, namely to define a D ¯ test as the ratio of the optimal test and of its average minimum, assuming that the spectrum corresponds to the average spectrum of the actual scenario. This would correspond to the form:
T ¯ O = ξ , ξ ¯ ξ , ξ 0 ξ 0 , ξ ¯ / ξ 0 , ξ 0 S o b s / a n ξ ¯ , ξ ¯ ξ 0 , ξ ¯ 2 / ξ 0 , ξ 0 ξ , ξ ξ 0 , ξ 2 / ξ 0 , ξ 0
which has the interesting property of being symmetric with respect to the actual spectrum ξ and the expected spectrum ξ ¯ .

Appendix A.7. Moments of the Frequency Spectrum in the Independent Sites Approximation

We consider the limit θ 1 , L with constant θ L . The spectrum ξ i can be written as a sum of spectra for all sites:
ξ i = s = 1 L ξ i ( s )
where each variable ξ i ( s ) has a Bernoulli distribution ξ i ( s ) { 0 , 1 } with probabilities p ( 1 ) = θ ξ i 0 and p ( 0 ) = 1 θ ξ i 0 where ξ i 0 = 1 / i under the standard neutral model. The expectation value of ξ i is therefore:
E ( ξ i ) = μ i = s = 1 L E ( ξ i ( s ) ) = θ L ξ i 0 = θ L i
and similarly E ( ξ i ) = μ ¯ i = θ L ξ ¯ i for a general model with average spectrum ξ ¯ i .
In the independent sites approximation, which is equivalent to the infinite recombination limit, the variables ξ i ( s ) and ξ i ( s ) are i.i.d. random variables for s s , and more generally the random variables ξ i ( s ) and ξ j ( s ) are independent for s s . The moments for a single site s can be calculated as:
E ( ξ i ( s ) ξ j ( s ) ξ k ( s ) ) = a , b , c { 0 , 1 } a b c P ( ξ i ( s ) = a , ξ j ( s ) = b , ξ k ( s ) = c , ) = = P ( ξ i ( s ) = 1 , ξ j ( s ) = 1 , ξ k ( s ) = 1 , ) = P ( ξ i ( s ) = 1 ) δ i j δ j k
because the sum i = 1 n 1 ξ i ( s ) { 0 , 1 } , that is, different allele frequencies for the same site are mutually exclusive. Therefore all these moments are always linear in θ and are nonzero only when all indices are equal:
E ( ξ i ( s ) ξ j ( s ) ξ k ( s ) ) = θ ξ i 0 δ i j δ j k = θ i δ i j δ j k .
Then the second moment can be evaluated as:
E ( ξ i ξ j ) = s , s E ( ξ i ( s ) ξ j ( s ) ) = s E ( ξ i ( s ) ξ j ( s ) ) + s s E ( ξ i ( s ) ) E ( ξ j ( s ) ) = = L δ i j θ i + L ( L 1 ) θ 2 i j = δ i j μ i + μ i μ j μ i μ j L
and neglecting subleading orders in θ or L 1 like the last term above, we can calculate the third and forth moments that are needed for the calculation of C 1 .
The final result for the moments of the spectrum ξ i is:
E ( ξ i ξ j ) = μ i j = δ i j μ i + μ i μ j
E ( ξ i ξ j ξ k ) = μ i j k = δ i j δ j k μ i + ( δ i k μ i μ j + δ j k μ i μ j + δ i j μ i μ k ) + μ i μ j μ k
E ( ξ i ξ j ξ k ξ l ) = μ i j k l = δ i j δ j k δ k l μ i + ( δ i k δ j l μ i μ j + δ i l δ j k μ i μ j + δ i j δ k l μ i μ k ) + + ( δ i j δ j k μ i μ l + δ i j δ j l μ i μ k + δ i k δ k l μ i μ j + δ j k δ k l μ i μ j ) + + ( δ i l μ i μ j μ k + δ j l μ i μ j μ k + δ i k μ i μ j μ l + δ j k μ i μ j μ l + + δ i j μ i μ k μ l + δ k l μ i μ j μ k ) + μ i μ j μ k μ l
All the results above can be applied to a general model simply by substituting μ i with μ ¯ i . Moreover, they can be applied to the folded spectrum by taking μ i = θ L n / i ( n i ) ( 1 + δ n , 2 i ) for the standard neutral model or μ ¯ i = θ L ( ξ ¯ i + ξ ¯ n i ) / ( 1 + δ n , 2 i ) for general models.
We define some quantities in order to simplify the expressions for the weights:
Σ μ = i = 1 n 1 μ i , Σ μ ¯ = i = 1 n 1 μ ¯ i , Σ q = i = 1 n 1 μ ¯ i 2 μ i
If the spectrum is folded, all the sums in the above expressions run from 1 to n / 2 .
The covariance matrix C I ˜ , J ˜ is:
C i , j = μ i j μ i μ j = δ i j μ i
C i j , k = μ i j k μ i j μ k = δ i j δ j k μ i + ( δ i k μ i μ j + δ j k μ i μ j )
C i j , k l = μ i j k l μ i j μ k l = δ i j δ j k δ k l μ i + ( δ i k δ j l μ i μ j + δ i l δ j k μ i μ j ) + + ( δ i j δ j k μ i μ l + δ i j δ j l μ i μ k + δ i k δ k l μ i μ j + δ j k δ k l μ i μ j ) + + ( δ i l μ i μ j μ k + δ j l μ i μ j μ k + δ i k μ i μ j μ l + δ j k μ i μ j μ l )
with the elements C i j , k and C i j , k l that should be considered only for i j , k l . It can be verified that the inverse matrix C I ˜ , J ˜ 1 has the form:
C i , j 1 = 1 + δ i j 2 μ i Σ μ + 3 + 1 2 μ i 2
C i j , k 1 = δ i j δ j k 2 μ i 1 2 μ i 2 ( δ i k + δ j k ) 1 μ k
C i j , k l 1 = ( δ i k δ j l + δ i l δ j k ) 1 μ i μ j 3 2 δ i j δ i k δ j l 1 μ i 2
The formulae for the weakly centred quadratic test (66)–(69) can be obtained from these formulae and the definition (63). The corresponding variance in the denominator (45) is:
Var I Γ I ( n I ) ( ξ ξ ) I = 2 ( Σ μ ¯ Σ q / 2 ) 2 + Σ μ ( Σ μ / 2 + 1 2 Σ μ ¯ + Σ q ) + Σ q 2 Σ μ ¯
The matrix M is the inverse of the matrix M r l 1 = I ˜ , L ˜ μ I ˜ ( r ) C I ˜ L ˜ 1 μ L ˜ ( l ) , which can be easily calculated from the above equations as:
M 11 1 = 2 Σ μ 2 + Σ μ
M 12 1 = Σ μ 2
M 22 1 = Σ μ 2 / 2
and the matrix M is
M = 1 / Σ μ 2 / Σ μ 2 / Σ μ 4 / Σ μ + 2 / Σ μ 2
The formulae (54)–(56) can be obtained from the formula (A35) and from the following results:
I ˜ C i , I ˜ 1 μ ¯ I ˜ = Σ μ ¯ + ( Σ μ + 2 Σ μ ¯ ) μ ¯ i μ i 1 2 μ ¯ i μ i 2
I ˜ C i i , I ˜ 1 μ ¯ I ˜ = μ ¯ i μ i + 1 2 μ ¯ i μ i 2
I ˜ C i j , I ˜ 1 μ ¯ I ˜ = μ ¯ i μ i μ ¯ j μ j + μ ¯ i μ ¯ j μ i μ j
I ˜ , J ˜ μ I ˜ ( 1 ) C I ˜ J ˜ 1 μ ¯ J ˜ = Σ μ ¯ ( 2 Σ μ Σ μ ¯ + 1 ) I ˜ , J ˜ μ I ˜ ( 2 ) C I ˜ J ˜ 1 μ ¯ J ˜ = Σ μ ¯ 2 / 2 Σ μ Σ μ ¯
I ˜ C i , I ˜ 1 μ I ˜ ( 1 ) = 2 Σ μ + 2 I ˜ C i , I ˜ 1 μ I ˜ ( 2 ) = Σ μ 1 / 2
I ˜ C i i , I ˜ 1 μ I ˜ ( 1 ) = 1 I ˜ C i i , I ˜ 1 μ I ˜ ( 2 ) = 1 / 2
I ˜ C i j , I ˜ 1 μ I ˜ ( 1 ) = 2 I ˜ C i j , I ˜ 1 μ I ˜ ( 2 ) = 1

Appendix B. Proofs

Derivation of General Optimisation for Tunable Linear Tests

We consider the maximisation of M ( E , V ) with the conditions E 0 = 0 , V 0 = 1 . We assume that the function M ( E , V ) is monotonic in both variables.
The existence of an absolute maximum (and minimum) is ensured by Weierstrass theorem applied to the closed manifold determined by the conditions E 0 = 0 , V 0 = 1 [10].
Local maxima can be found by the Lagrange multipliers method, i.e., by the extremum conditions for M ( E , V ) λ 1 E 0 λ 2 ( V 0 1 ) with respect to Ω i , λ 1 and λ 2 . We obtain the extremum equation:
Ω i = θ L 2 M ( E , V ) / E M ( E , V ) / V · ξ i 0 j = 1 n 1 c ¯ + λ ˜ 2 c i j 1 ξ ¯ j λ ˜ 1 ξ j 0
with λ ˜ 1 , λ ˜ 2 determined by the constraint equations. Solving for λ ˜ 1 , we obtain:
Ω i = θ L 2 M ( E , V ) / E M ( E , V ) / V · ξ i 0 j = 1 n 1 c ¯ + λ ˜ 2 c i j 1 ξ ¯ j ξ j 0 l , m = 1 n 1 ξ l 0 ( c ¯ + λ ˜ 2 c ) l m 1 ξ ¯ m l , m = 1 n 1 ξ l 0 ( c ¯ + λ ˜ 2 c ) l m 1 ξ m 0
with λ ˜ 2 determined by the condition i , j = 1 n 1 Ω i Ω j c i j / ξ i 0 ξ j 0 = 1 .
We approximate the variances with their values for unlinked sites:
c i j δ i j θ L ξ i 0 , c ¯ i j δ i j θ L ξ ¯ i
and we obtain the weights:
Ω i = ξ i 0 1 j = 1 n 1 ξ j 0 ( λ ξ ¯ i / ξ i 0 + 1 ) j = 1 n 1 ξ j 0 λ ξ ¯ j / ξ j 0 + 1
where the remaining parameter λ is fixed by the condition:
θ 3 L 3 4 i = 1 n 1 Ω i 2 / ξ i 0 = M ( E , V ) / V M ( E , V ) / E 2
This equation fixes all values of λ corresponding to the local maxima. To obtain the absolute maximum, one has to choose the solution λ that actually maximises M ( E , V ) .
In practice, for the standard neutral model, it is sufficient to use the usual form of the test:
T = i = 1 n 1 i Ω i ξ i Var ( i = 1 n 1 i Ω i ξ i )
with the (unnormalised) weights:
Ω i = 1 i 1 a n ( λ i ξ ¯ i + 1 ) j = 1 n 1 1 j ( λ j ξ ¯ j + 1 )
with λ determined numerically either by the condition:
θ 3 L 3 4 i = 1 n 1 i Ω i 2 = M ( E , V ) / V M ( E , V ) / E 2
or more easily, looking directly for the value of λ that maximises numerically M ( E , V ) .
We discuss explicitly two important limit cases:
  • M / V = 0 : this case reduces to the usual optimal tests. It corresponds to the limit λ 0 + in the above equation, which gives a unique solution:
    Ω i = λ ξ ¯ i 1 i j = 1 n 1 ξ ¯ j a n
    where the λ factor is irrelevant.
  • M / E = 0 : maximisation or minimisation of variance. In this case the values of λ are determined by the condition j = 1 n 1 1 j ( λ j ξ ¯ j + 1 ) = 0 , which is equivalent to a n = j = 1 n 1 1 j + 1 / λ ξ ¯ j . The r.h.s. is monotonically increasing and diverges for the n 1 values λ = 1 / i ξ ¯ i , i = 1 n 1 . Monotonicity and the Weierstrass theorem ensure that there are precisely n 2 solutions for this equation. If we order the values of i ξ ¯ i from the lowest i 1 ξ ¯ i 1 to the highest i n 1 ξ ¯ i n 1 , the value of λ that maximises V is the only solution that lies in the interval 1 / i 1 ξ ¯ i 1 < λ < 1 / i 2 ξ ¯ i 2 and the value that minimises V is the only solution in 1 / i n 2 ξ ¯ i n 2 < λ < 1 / i n 1 ξ ¯ i n 1 .
Proof of Theorem 1. 
Choose a vector Δ i in R n 1 that is orthogonal both to i Ω i and to i, that is, such that i i Δ i Ω i = 0 and i i Ω i = 0 . Since α / i a n + ( 1 α ) Δ i is a set of continuous functions of α , its minimum is also continuous in α . Moreover, the minimum is clearly positive if α = 1 , while it is negative by construction if α = 0 . The theorem follows from the intermediate value theorem. □
Proof of Theorem 2. 
The proof is similar to the previous one. Choose a function Δ ( f ) in C ( 0 , 1 ) to satisfy both 1 / N 1 d f f Ω ( f ) Δ ( f ) = 0 and 1 / N 1 d f f Δ ( f ) = 0 . (Since these conditions correspond just to two independent functionals of Δ ( f ) and C ( 0 , 1 ) is an infinite-dimensional linear space, the existence of such a function is guaranteed). Since α / f log ( N ) + ( 1 α ) Δ ( f ) is a continuous functions of α and its infimum is not ± , its infimum is also continuous in α . Moreover, the infimum is clearly positive if α = 1 , while it is negative by construction if α = 0 . The theorem follows from the intermediate value theorem. □
Proof of Theorem 3. 
The vectors Ω i are a basis of the subspace R n 2 R n 1 defined by the condition i Ω i = 0 , that is, the space of vectors orthogonal to the vector whose components are v i = 1 . Therefore the only vectors i Δ i that are orthogonal to all the vectors in this basis are precisely of the form i Δ i v i , that is, Δ i = c o n s t / i . □
The theorems on the form of optimal tests can be easily proved from a general lemma.
Lemma A1. 
Consider a function f : R M { 0 } R of the form:
f ( v ) = v · w v · Q v
where w R M and Q is a M × M symmetric positive matrix, and a K × M matrix R with K < M and maximum rank. The extrema of the function f restricted to the subspace R v = 0 are given by:
v α = α Q 1 w Q 1 R t R Q 1 R t 1 R Q 1 w
The extrema with α > 0 are maxima and the extrema with α < 0 are minima of the function f. These extrema satisfy the identity:
v α · Q v α = α v α · w
Proof. 
The existence of maxima and minima can be proved by the Weierstrass extreme value theorem. In fact f is continuous and invariant under a homothety with centre in the origin of R M and positive scale factor, therefore the codomain of the function on the linear subspace defined by R v = 0 is the same as the codomain of its restriction to the submanifold of unit vectors | v | = 1 , which is a compact space. The restriction of f is also continuous and the conclusion follows. To determine the extrema, the method of Lagrange multipliers states that it is sufficient to extremise the function:
F ( v , λ ) = v · w v · Q v + λ · R v
and since there are no boundaries, this is equivalent to the solution of the equations:
0 = v f = w v · Q v v · w v · Q v 3 / 2 Q v + R t λ
0 = λ f = R v
The solution satisfies:
v · w v · Q v v = Q 1 w + Q 1 R t λ
and multiplying it by R and using (A57) we obtain:
λ = R Q 1 R t 1 R Q 1 w + l , R t l = 0
that can be inserted again in Equation (A58) to eliminate λ . The resulting equation in v admits only solutions of the form (A53) and by substituting (A53) into it, it can be checked that all values of α 0 correspond to solutions of (A56) and (A57). The invariance of f under a central homothety with positive scale factor implies that the value of the function does not depend on | α | . The function is positive for α > 0 and negative for α < 0 , therefore solutions with α > 0 correspond to maxima and solutions with α < 0 correspond to minima. The identity (A54) can be proved by substituting the solution (A53).
Proof of Theorem 4. 
The expected values of the tests (41) have the same functional form as the function f of Lemma A1. The correspondence is the following:
v v I ˜ = σ ( I ˜ ) Ω I ˜ ( n I ˜ )
w w I ˜ = μ ¯ I ˜
Q Q I ˜ J ˜ = μ I ˜ J ˜ μ I ˜ μ J ˜
R R k , I ˜ = μ I ˜ ( k )
and the positivity of the matrix Q is guaranteed by the positivity of the variance for all possible choices of the weights. Application of Lemma A1 with a  α = 1 gives the result (50). □
Proof of Theorem 5. 
We can immediately solve Equation (58) for γ and substitute it in Equation (57). Then γ is a function of the other weights and the maximisation is unconstrained. It can be seen that also in this case, the expected values of the tests have the same functional form as the function f of Lemma A1. The correspondence is the following:
v v I ˜ = σ ( I ˜ ) Γ I ˜ ( n I ˜ )
w w I ˜ = μ ¯ I ˜ μ I ˜
Q Q I ˜ J ˜ = μ I ˜ J ˜ μ I ˜ μ J ˜
R empty 0 × M matrix
and the positivity of the matrix Q is implied by by the positivity of the variance. Then the result (63) follows from Lemma A1 with α = 1 . □

References

  1. Kreitman, M. Nucleotide polymorphism at the alcohol dehydrogenase locus of Drosophila melanogaster. Nature 1983, 304, 412–417. [Google Scholar] [CrossRef] [PubMed]
  2. Hudson, R.; Kreitman, M.; Aguadé, M. A test of neutral molecular evolution based on nucleotide data. Genetics 1987, 116, 153. [Google Scholar] [CrossRef] [PubMed]
  3. Lewontin, R.; Krakauer, J. Distribution of gene frequency as a test of the theory of the selective neutrality of polymorphisms. Genetics 1973, 74, 175. [Google Scholar] [CrossRef] [PubMed]
  4. Sabeti, P.; Reich, D.; Higgins, J.; Levine, H.; Richter, D.; Schaffner, S.; Gabriel, S.; Platko, J.; Patterson, N.; McDonald, G.; et al. Detecting recent positive selection in the human genome from haplotype structure. Nature 2002, 419, 832–837. [Google Scholar] [CrossRef]
  5. Tajima, F. Statistical method for testing the neutral mutation hypothesis by DNA polymorphism. Genetics 1989, 123, 585. [Google Scholar] [CrossRef] [PubMed]
  6. Fu, Y.; Li, W. Statistical tests of neutrality of mutations. Genetics 1993, 133, 693. [Google Scholar] [CrossRef]
  7. Fay, J.; Wu, C. Hitchhiking under positive Darwinian selection. Genetics 2000, 155, 1405. [Google Scholar] [CrossRef]
  8. Achaz, G. Frequency Spectrum Neutrality Tests: One for All and All for One. Genetics 2009, 183, 249. [Google Scholar] [CrossRef]
  9. Fu, Y. Statistical properties of segregating sites. Theor. Popul. Biol. 1995, 48, 172–197. [Google Scholar] [CrossRef]
  10. Ferretti, L.; Perez-Enciso, M.; Ramos-Onsins, S. Optimal Neutrality Tests Based on Frequency Spectrum. Genetics 2010, 186, 353–365. [Google Scholar] [CrossRef]
  11. Fu, Y. New statistical tests of neutrality for DNA samples from a population. Genetics 1996, 143, 557. [Google Scholar] [CrossRef] [PubMed]
  12. Ferretti, L.; Klassmann, A.; Raineri, E.; Ramos-Onsins, S.E.; Wiehe, T.; Achaz, G. The neutral frequency spectrum of linked sites. Theor. Popul. Biol. 2018, 123, 70–79. [Google Scholar] [CrossRef] [PubMed]
  13. Klassmann, A.; Ferretti, L. The third moments of the site frequency spectrum. Theor. Popul. Biol. 2018, 120, 16–28. [Google Scholar] [CrossRef] [PubMed]
  14. Giner-Delgado, C.; Villatoro, S.; Lerga-Jaso, J.; Gayà-Vidal, M.; Oliva, M.; Castellano, D.; Pantano, L.; Bitarello, B.D.; Izquierdo, D.; Noguera, I.; et al. Evolutionary and functional impact of common polymorphic inversions in the human genome. Nat. Commun. 2019, 10, 4222. [Google Scholar] [CrossRef] [PubMed]
  15. Fu, Y. Statistical tests of neutrality of mutations against population growth, hitchhiking and background selection. Genetics 1997, 147, 915. [Google Scholar] [CrossRef]
  16. Zeng, K.; Fu, Y.; Shi, S.; Wu, C. Statistical tests for detecting positive selection by utilizing high-frequency variants. Genetics 2006, 174, 1431. [Google Scholar] [CrossRef]
  17. Tajima, F. Evolutionary relationship of DNA sequences in finite populations. Genetics 1983, 105, 437. [Google Scholar] [CrossRef]
  18. Watterson, G. On the number of segregating sites in genetical models without recombination. Theor. Popul. Biol. 1975, 7, 256. [Google Scholar] [CrossRef]
  19. Achaz, G. Testing for neutrality in samples with sequencing errors. Genetics 2008, 179, 1409. [Google Scholar] [CrossRef]
  20. Ramos-Onsins, S.E.; Mitchell-Olds, T. Mlcoalsim: Multilocus coalescent simulations. Evol. Bioinform. 2007, 3, 41–44. [Google Scholar] [CrossRef]
  21. Schaeffer, S. Molecular population genetics of sequence length diversity in the Adh region of Drosophila pseudoobscura. Genet. Res. 2003, 80, 163–175. [Google Scholar] [CrossRef] [PubMed]
  22. Schmid, K.; Ramos-Onsins, S.; Ringys-Beckstein, H.; Weisshaar, B.; Mitchell-Olds, T. A multilocus sequence survey in Arabidopsis thaliana reveals a genome-wide departure from a neutral model of DNA sequence polymorphism. Genetics 2005, 169, 1601. [Google Scholar] [CrossRef] [PubMed]
  23. Hutter, S.; Li, H.; Beisswanger, S.; De Lorenzo, D.; Stephan, W. Distinctly different sex ratios in African and European populations of Drosophila melanogaster inferred from chromosomewide single nucleotide polymorphism data. Genetics 2007, 177, 469. [Google Scholar] [CrossRef] [PubMed]
Figure 1. Illustrative example of the dependence of the weight on sample size: weight Ω as a function of i / n for the test for admixture by Achaz, plotted for different sample size n = 10 (blue), 100 (red), 1000 (green).
Figure 1. Illustrative example of the dependence of the weight on sample size: weight Ω as a function of i / n for the test for admixture by Achaz, plotted for different sample size n = 10 (blue), 100 (red), 1000 (green).
Genes 14 01714 g001
Figure 2. Geometrical representation of the numerator of the optimal test T O in (34). The length of the red line segment corresponds to the value of the numerator.
Figure 2. Geometrical representation of the numerator of the optimal test T O in (34). The length of the red line segment corresponds to the value of the numerator.
Genes 14 01714 g002
Figure 3. Statistical power of nonlinear optimal tests from coalescent simulations for the 5% tail, compared with Tajima’s D test (for the left and the right tail). The parameters for the simulations are: n = 20 , θ = 0.05 , L = 1000 bp, ρ = ; two populations considered but only one sampled (for panel A); expansion factor N 0 / N = 10 (for panel B).
Figure 3. Statistical power of nonlinear optimal tests from coalescent simulations for the 5% tail, compared with Tajima’s D test (for the left and the right tail). The parameters for the simulations are: n = 20 , θ = 0.05 , L = 1000 bp, ρ = ; two populations considered but only one sampled (for panel A); expansion factor N 0 / N = 10 (for panel B).
Genes 14 01714 g003
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Ramos-Onsins, S.E.; Marmorini, G.; Achaz, G.; Ferretti, L. A General Framework for Neutrality Tests Based on the Site Frequency Spectrum. Genes 2023, 14, 1714. https://doi.org/10.3390/genes14091714

AMA Style

Ramos-Onsins SE, Marmorini G, Achaz G, Ferretti L. A General Framework for Neutrality Tests Based on the Site Frequency Spectrum. Genes. 2023; 14(9):1714. https://doi.org/10.3390/genes14091714

Chicago/Turabian Style

Ramos-Onsins, Sebastián E., Giacomo Marmorini, Guillaume Achaz, and Luca Ferretti. 2023. "A General Framework for Neutrality Tests Based on the Site Frequency Spectrum" Genes 14, no. 9: 1714. https://doi.org/10.3390/genes14091714

APA Style

Ramos-Onsins, S. E., Marmorini, G., Achaz, G., & Ferretti, L. (2023). A General Framework for Neutrality Tests Based on the Site Frequency Spectrum. Genes, 14(9), 1714. https://doi.org/10.3390/genes14091714

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop