Tajima's D Calculator

Calculate Tajima's D to test for departures from neutral evolution in population genetics.

Mean pairwise nucleotide differences
Please check your inputs and try again.

Two Estimates of the Same Quantity

Tajima's D compares two ways of estimating genetic diversity that should agree under neutrality but diverge under selection or demographic change.

EstimatorBased onSensitive to
π (pairwise)Average differences between sequence pairsIntermediate-frequency variants
θW (Watterson)Number of segregating sitesAll variants equally, including rare ones
D ∝ π − θW

The difference in sensitivity is the whole mechanism. Because θW counts every polymorphic site regardless of frequency, an excess of rare variants inflates it relative to π, driving D negative. An excess of intermediate-frequency variants does the opposite.

D valuePatternSelection causeDemographic cause
D < 0Excess rare variantsPurifying selection, selective sweepPopulation expansion
D ≈ 0Neutral expectation—Constant size
D > 0Excess intermediate variantsBalancing selectionBottleneck, structure

The Confounding Problem

Notice that each D value has both a selective and a demographic explanation, and the statistic cannot distinguish them from a single locus. A sweep and a population expansion both produce negative D.

The standard resolution is to compare many loci. Demographic history affects the entire genome equally, so a genome-wide negative D suggests expansion. Selection acts locally, so a single locus with strongly negative D against a neutral genomic background suggests a sweep. This is why modern scans report D relative to an empirical genome-wide distribution rather than against zero.

Values beyond roughly ±2 are conventionally treated as significant, though the actual null distribution depends on sample size and recombination rate.

Worked Examples

Example 1: Neutral population: S=17, pi=3.2, n=20
Expect D near 0
Result: D=0.12 — neutral evolution
Most loci show D near 0 under neutrality
Example 2: After selective sweep: low D
S high (many rare variants), pi low
Result: D < -2 — excess rare mutations
Star-like phylogeny after selective sweep
Example 3: Distinguishing sweep from expansion
One locus D = −2.4, genome-wide mean D = −0.1
Result: Likely a selective sweep
The locus stands out sharply against a near-neutral background. If the whole genome were negative, expansion would be the better explanation.
Example 4: Balancing selection signature
D = +2.3 at an immune locus, genome-wide mean near 0
Result: Balancing selection
Excess intermediate-frequency variants is characteristic of maintained polymorphism, as seen at MHC loci where heterozygote advantage preserves diversity.

Common Mistakes

⚠️
Interpreting D from a single locus

Selection and demography produce identical signatures. Distinguishing them requires comparing many loci across the genome.

⚠️
Assuming negative D always means selection

Population expansion produces genome-wide negative D. Only a locus that stands out against the genomic background suggests a sweep.

⚠️
Comparing D across different sample sizes without care

The null distribution depends on sample size and recombination. Empirical genome-wide distributions are more reliable than the nominal ±2 threshold.

⚠️
Ignoring recombination

Low-recombination regions show wider variance in D, so apparent outliers there may be statistical artefacts rather than selection.

Frequently Asked Questions

Tajima's D interpretation?
D≈0: neutral (drift only). D>2: balancing selection (excess intermediate frequency variants, like MHC). D<-2: positive selective sweep (excess rare variants). Also affected by population size changes: expansion → D<0, bottleneck → D>0.
Limitations?
Tajima's D assumes constant population size and random mating. Demographic history (expansion, bottleneck) can mimic selection signatures. Need multiple loci or whole-genome data to distinguish selection from demography.
What does Tajima's D measure?
The difference between two diversity estimators — pairwise differences and segregating site count — which agree under neutrality and diverge under selection or demographic change.
What does a negative D indicate?
An excess of rare variants, consistent with a recent selective sweep, purifying selection, or population expansion. The causes cannot be separated from one locus.
What does a positive D indicate?
An excess of intermediate-frequency variants, consistent with balancing selection, a population bottleneck, or population structure.
How do I distinguish selection from demography?
Compare across loci. Demographic effects are genome-wide while selection is local, so an outlier locus against a neutral background suggests selection.