# Linkage disequilibrium between two biallelic loci from phased haplotype counts, version 1.0.2

popgen-linkage-disequilibrium\@1.0.2: this version's equations with their symbols, each constant's value, their sources and whether each was read, a worked example where the record holds one, its level and what it was checked against, the number of cases, and what was not checked. This version's record is not rewritten; a correction is added under Changes.

## What this page can and cannot show

**Level: Checked against a reference; D, Dmax, D′ and r² as VanLiere and Rosenberg 2008 state them; Lewontin 1964 not read; no association test. Reference kind: our own exact-arithmetic script and a hand-worked case.**

Not fully recorded, and not independently reviewed. Items marked "Not recorded" are missing from this project's records for the version named. Apart from any worked example shown, the cases and their values are not printed, so a reader cannot re-run these checks. No independent scientist has yet reviewed these methods or checks.

[Every version of this method](https://www.drybench.com/methods/m/popgen-linkage-disequilibrium) · [Every method](https://www.drybench.com/methods/m) · [What the levels mean](https://www.drybench.com/methods/levels)

## Version 1.0.2

**Level: Checked against a reference; D, Dmax, D′ and r² as VanLiere and Rosenberg 2008 state them; Lewontin 1964 not read; no association test. Reference kind: our own exact-arithmetic script and a hand-worked case.** `popgen-linkage-disequilibrium@1.0.2`

Built, not hosted. Generated from a snapshot of the library's records taken on 2026-11-25, as committed on 2026-11-25. A later snapshot replaces this one, so these records and this page can change.

**Verification statement:** D, Dmax and signed D′ as VanLiere and Rosenberg 2008 state them (§2.5, Eq. (13), Dmax attributed there to Lewontin 1964), and r² as their Eq. (1), read at source 24 November 2026 in the journal's version of record (SHA-256 51439617…); Lewontin 1964 and Hill and Robertson 1968 not read. Counts up to 10^7 each keep the cross-products exact. Checked in exact arithmetic (Python fractions) and against a second implementation in Python by a separate agent of the same model family (31 cases, 18 at the edges). No test of association; phasing is the caller's.

The coefficient of linkage disequilibrium D, its maximum attainable magnitude Dmax given the allele frequencies, D′ = D/Dmax signed as D, and r², from the counts of the four phased haplotypes AB, Ab, aB and ab.

- **How results are reported:** none: full double precision
- **Uncertainty:** Sample quantities on the caller's haplotype counts; no sampling interval is given.
- **Every reply through it says:** D and D′ are signed by the caller's choice of which alleles are A and B; swapping the labels at one locus changes their sign, not r². No test of association is made.
- **Reference, as its record states it:** 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
- **Level confirmed by this project's ruling of** 24 November 2026

[What this page can and cannot show](#what-this-page-can-and-cannot-show)

### What was checked

44 cases in 2 files, linked by this exact version.

Run through the tool at build against our own exact-arithmetic script and a hand-worked case: 36 agree within the tolerance the file states, 8 refuse as the case expects, 0 differ, 0 were not run.

- **File 1, 13 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-11
  - **Reference:** Python standard library (fractions), 3.13.18; licence PSF-2.0
  - **Tolerance as the file states it:** D, Dmax, D', r2 and allele frequencies absolute 1e-14; statuses, codes, units and withheld rules exact

- **File 2, 31 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-14
  - **Reference:** second implementation by a fresh agent (Python 3.13), 2026-11-14; licence BSD-3-Clause
  - **Tolerance as the file states it:** every number relative 1e-15 (absolute 1e-30 below 1e-15, in each value's unit); counts, statuses, codes, labels and strings exact

Apart from the worked example, the cases and their values are not printed here. This shows agreement with this project's recorded cases. It does not show that a method suits your work, and it is not a qualification.

### What was 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. 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.

### Definition or model

A closed form: the result follows from the inputs by the equations alone.

### Equations

**Equation 1**

Definition: haplotype and allele frequencies from phased haplotype counts.

```equation
n = nAB + nAb + naB + nab
pAB = nAB/n
pA = (nAB + nAb)/n
pB = (nAB + naB)/n
```

| Symbol | Meaning and unit |
| --- | --- |
| n | haplotypes counted |
| nAB, nAb, naB, nab | counts of the four phased haplotypes |
| pAB | frequency of haplotype AB |
| pA | frequency of allele A at the first locus |
| pB | frequency of allele B at the second locus |

**Equation 2**

```equation
D = pAB − pA·pB = (nAB·nab − nAb·naB)/n²
```

| Symbol | Meaning and unit |
| --- | --- |
| D | coefficient of linkage disequilibrium |
| pAB, pA, pB | haplotype and allele frequencies |

Source: VanLiere JM, Rosenberg NA, Mathematical properties of the r² measure of linkage disequilibrium, Theoretical Population Biology 74:130–137 (2008), p. 135, section 2.5, the text after Eq. (13): D = p\_ab − p\_a p\_b, version of record (Elsevier's journal PDF, created 27 June 2008), as posted on the authors' lab site (a mirror); the NIH author manuscript, PMC2580747, read at 1.0.1, is not the copy hashed; read in full on 2026-11-24 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 5143961717bb. Free to read (To be checked (© Elsevier 2008; the authors' posted copy)), checked 2026-11-24. No erratum found (searched crossref (10.1016/j.tpb.2008.05.006): no update or erratum relation, publisher), 2026-11-24.

**Equation 3**

```equation
Dmax = min(pA(1 − pB), (1 − pA)pB) when D > 0
min(pA·pB, (1 − pA)(1 − pB)) when D ≤ 0
```

| Symbol | Meaning and unit |
| --- | --- |
| Dmax | maximum attainable magnitude of D given the allele frequencies |
| pA, pB | allele frequencies |

Source: VanLiere JM, Rosenberg NA, Mathematical properties of the r² measure of linkage disequilibrium, Theoretical Population Biology 74:130–137 (2008), 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, version of record (Elsevier's journal PDF, created 27 June 2008), as posted on the authors' lab site (a mirror); the NIH author manuscript, PMC2580747, read at 1.0.1, is not the copy hashed; read in full on 2026-11-24 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 5143961717bb. Free to read (To be checked (© Elsevier 2008; the authors' posted copy)), checked 2026-11-24. No erratum found (searched crossref (10.1016/j.tpb.2008.05.006): no update or erratum relation, publisher), 2026-11-24.

**Equation 4**

```equation
D′ = D/Dmax, signed as D
D′ = 0 when D = 0
```

| Symbol | Meaning and unit |
| --- | --- |
| D′ | D over its maximum attainable magnitude given the allele frequencies, signed as D |
| D, Dmax | D and its maximum magnitude |

Source: VanLiere JM, Rosenberg NA, Mathematical properties of the r² measure of linkage disequilibrium, Theoretical Population Biology 74:130–137 (2008), equation 13, p. 135, section 2.5: D′ = D/Dmax, version of record (Elsevier's journal PDF, created 27 June 2008), as posted on the authors' lab site (a mirror); the NIH author manuscript, PMC2580747, read at 1.0.1, is not the copy hashed; read in full on 2026-11-24 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 5143961717bb. Free to read (To be checked (© Elsevier 2008; the authors' posted copy)), checked 2026-11-24. No erratum found (searched crossref (10.1016/j.tpb.2008.05.006): no update or erratum relation, publisher), 2026-11-24.

**Equation 5**

```equation
r² = D²/(pA(1 − pA)·pB(1 − pB))
```

| Symbol | Meaning and unit |
| --- | --- |
| r² | squared correlation of allele indicators on haplotypes |
| D, pA, pB | D and the allele frequencies |

Source: VanLiere JM, Rosenberg NA, Mathematical properties of the r² measure of linkage disequilibrium, Theoretical Population Biology 74:130–137 (2008), 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)), version of record (Elsevier's journal PDF, created 27 June 2008), as posted on the authors' lab site (a mirror); the NIH author manuscript, PMC2580747, read at 1.0.1, is not the copy hashed; read in full on 2026-11-24 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 5143961717bb. Free to read (To be checked (© Elsevier 2008; the authors' posted copy)), checked 2026-11-24. No erratum found (searched crossref (10.1016/j.tpb.2008.05.006): no update or erratum relation, publisher), 2026-11-24.

### Constants

Constants: none used.

### 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:

```equation
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.

Who worked this case: not recorded.

### What it refuses, and its input ranges

- `NO_HAPLOTYPES` (invalid input): all four haplotype counts are zero

### Changes

No correction is logged for popgen-linkage-disequilibrium\@1.0.2.

## Tools that use it

- [`popgen_linkage_disequilibrium`](https://www.drybench.com/methods/tools/popgen-linkage-disequilibrium)

## Cite this version

Linkage disequilibrium between two biallelic loci from phased haplotype counts. Drybench; popgen-linkage-disequilibrium\@1.0.2; [https://www.drybench.com/methods/m/popgen-linkage-disequilibrium/1.0.2](https://www.drybench.com/methods/m/popgen-linkage-disequilibrium/1.0.2) (accessed \[date\]).
