Skip to content

Linkage disequilibrium between two loci from phased haplotype counts

popgen_linkage_disequilibrium

Works out D, Dmax, signed D′ and r² between two biallelic loci from the four phased haplotype counts.

Runs
On the server
Level
Checked against a reference: exact arithmetic: Python fractions on the definitions, written before the engine, with hand-worked cases, and a second implementation in Python by a separate agent of the same model family
Ask your assistant

What it is

Returns D, Dmax, signed D′ and r² between two biallelic loci from the four phased haplotype counts. Use when haplotypes AB, Ab, aB and ab have been counted in a sample, for a candidate pair or a teaching table. Not for linkage in a cross or family from recombinants: use `genetics_lod_score`; not for a test of association: use `stats_contingency_table`. Counts in unit 1; D′ and r² withheld at a monomorphic locus; unphased genotypes are not accepted.

Field: Genetics, evolution and ecology.

What it does

You give

  • countAB (required): Phased haplotypes AB counted, 0 or more. Must be at least 0 and at most 10000000.
  • countAb (required): Phased haplotypes Ab counted, 0 or more. Must be at least 0 and at most 10000000.
  • countaB (required): Phased haplotypes aB counted, 0 or more. Must be at least 0 and at most 10000000.
  • countab (required): Phased haplotypes ab counted, 0 or more. Must be at least 0 and at most 10000000.

No request is recorded for this tool.

Limits

  • Research and teaching arithmetic on the caller's data.
  • Not for diagnosis, genetic counselling, clinical, breeding, conservation-management or animal-welfare decisions.
  • The tool checks arithmetic, not the data.
  • D, D′ and r² from phased haplotype counts at two biallelic loci; no test of association and no inference about selection or demography.
  • Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

It will not answer when

  • all four haplotype counts are zero.
Every input, with its units4 inputs
  • countAB (required): Phased haplotypes AB counted, 0 or more. Must be at least 0 and at most 10000000.
  • countAb (required): Phased haplotypes Ab counted, 0 or more. Must be at least 0 and at most 10000000.
  • countaB (required): Phased haplotypes aB counted, 0 or more. Must be at least 0 and at most 10000000.
  • countab (required): Phased haplotypes ab counted, 0 or more. Must be at least 0 and at most 10000000.
Every refusal, with its code1 refusal
CodeWhen
NO_HAPLOTYPESall four haplotype counts are zero.

The calculation

The method's equations, constants and worked example.

Linkage disequilibrium between two biallelic loci from phased haplotype countspopgen-linkage-disequilibrium@1.0.2

Equation 1

n=nAB+nAb+naB+nab
pAB=nAB/n
pA=(nAB+nAb)/n
pB=(nAB+naB)/n
SymbolMeaning
nhaplotypes counted
nAB, nAb, naB, nabcounts of the four phased haplotypes
pABfrequency of haplotype AB
pAfrequency of allele A at the first locus
pBfrequency of allele B at the second locus

Equation 2

D=pAB−pA·pB=(nAB·nab−nAb·naB)/n2
SymbolMeaning
Dcoefficient of linkage disequilibrium
pAB, pA, pBhaplotype and allele frequencies

Source 1.

Equation 3

Dmax = min(pA(1 − pB), (1 − pA)pB) when D > 0

min(pA·pB, (1 − pA)(1 − pB)) when D ≤ 0

SymbolMeaning
Dmaxmaximum attainable magnitude of D given the allele frequencies
pA, pBallele frequencies

Source 1.

Equation 4

D′ = D/Dmax, signed as D

D′ = 0 when D = 0

SymbolMeaning
D′D over its maximum attainable magnitude given the allele frequencies, signed as D
D, DmaxD and its maximum magnitude

Source 1.

Equation 5

r2=D2/(pA(1−pA)·pB(1−pB))
SymbolMeaning
r²squared correlation of allele indicators on haplotypes
D, pA, pBD and the allele frequencies

Source 1.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of popgen-linkage-disequilibrium@1.0.2, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • countAB = 40
  • countAb = 10
  • countaB = 10
  • countab = 40

Steps

  1. pA = 0.5, from countAB, countAb, countaB, countab; by equation 1; gives alleleFrequencyA.
  2. pB = 0.5, from countAB, countAb, countaB, countab; by equation 1; gives alleleFrequencyB.
  3. d = 0.15, from countAB, countAb, countaB, countab, pA, pB; by equation 2; gives d.
  4. dMax = 0.25, from pA, pB, d; by equation 3; gives dMax.
  5. dPrime = 0.6, from d, dMax; by equation 4; gives dPrime.
  6. r2 = 0.36, from d, pA, pB; by equation 5; gives rSquared.

The working, as the case writes it:

n 100

pAB 0.40, pA 0.50, pB 0.50

D = 0.40 - 0.25 = 0.15

D > 0 so Dmax = min(0.5 x 0.5, 0.5 x 0.5) = 0.25

D' = 0.15/0.25 = 0.6

r2 = 0.0225/(0.25 x 0.25) = 0.36.

Answer

alleleFrequencyA = 0.5

alleleFrequencyB = 0.5

d = 0.15

dMax = 0.25

dPrime = 0.6

rSquared = 0.36

Where these values came from: our own exact-arithmetic script and a hand-worked case; stored reference values: exact rational arithmetic on the definitions.

At build the tool returned this answer within the tolerance the file states: D, Dmax, D', r2 and allele frequencies absolute 1e-14; statuses, codes, units and withheld rules exact.

Sources

  1. VanLiere JM, Rosenberg NA, Mathematical properties of the r² measure of linkage disequilibrium, Theoretical Population Biology 74:130–137 (2008)

    Used for: Linkage disequilibrium between two biallelic loci from phased haplotype counts. At: p. 135, section 2.5, the text after Eq. (13): D = p_ab − p_a p_b; p. 135, section 2.5, the text after Eq. (13), after Lewontin 1964, as stated in VanLiere and Rosenberg 2008: Dmax = min(p_a p_b, (1 − p_a)(1 − p_b)) if D < 0 and min(p_a(1 − p_b), (1 − p_a)p_b) if D > 0 (Lewontin, 1964); D = 0 taken in the D ≤ 0 branch, the record's, where D′ = 0 either way; equation 13, p. 135, section 2.5: D′ = D/Dmax; equation 1, p. 131, section 2, after Hill and Robertson 1968, as stated in VanLiere and Rosenberg 2008: r² = (p_ab − p_a p_b)²/(p_a(1 − p_a)p_b(1 − p_b)).

    Read in full, 24 November 2026

How it is checked

Level

Checked against a reference.

Checked against

Our own exact-arithmetic script and a hand-worked case.

Cases

No case set is linked to this version.

Not checked

Lewontin 1964 (PMC1210557: the scan is behind a bot check for every session) and Hill and Robertson 1968 (not in PMC) were not read; Dmax is taken as VanLiere and Rosenberg 2008 attribute it to Lewontin; no published worked table is compared. Each count is from zero to ten million and not all zero (the tool's schema; NO_HAPLOTYPES when all are zero); with n at most forty million, n² is below 2^53, so D's cross-product, n² and the Dmax products are exact integers, and the sign of D is decided on the integer cross-product.

What was not checked, in fullfrom the method records
  • Lewontin 1964 (PMC1210557: the scan is behind a bot check for every session) and Hill and Robertson 1968 (not in PMC) were not read; Dmax is taken as VanLiere and Rosenberg 2008 attribute it to Lewontin; no published worked table is compared.
  • Each count is from zero to ten million and not all zero (the tool's schema; NO_HAPLOTYPES when all are zero); with n at most forty million, n² is below 2^53, so D's cross-product, n² and the Dmax products are exact integers, and the sign of D is decided on the integer cross-product.
  • Genotype (unphased) data and their EM estimate, multi-allelic loci and any test of association are outside the method.
  • Whether the haplotypes were phased correctly is the caller's.
Changes to its methods0 changes

No change is logged for these method versions.