Statistics & probability

Two locus haplotype frequency and linkage disequilibrium calculator from unphased genotypes

Rows of the input are AA, Aa, and aa at the first locus; columns are BB, Bb, and bb at the second.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Rows of the input are AA, Aa, and aa at the first locus; columns are BB, Bb, and bb at the second. Each cell counts unrelated subjects having that pair of unphased genotypes. The nine counts must be nonnegative integers totaling at least ten and at most one hundred thousand complete diploid observations. Do not enter haplotype counts into this genotype table.

THE FORMULAP(genotype)=Σ_compatible (2−1[a=b]) f_a f_b; D=f_AB−p_A p_B; r²=D²/[p_A(1−p_A)p_B(1−p_B)]. EM allocates compatible diplotypes.

A worked example

The default110-subject table gives f_AB≈0.403791252,D≈0.121146624,D′≈0.514341807,r²≈0.237094453.

Good to know

Two biallelic autosomal loci, 3x3 complete genotype count table, 10–100000 unrelated diploid subjects. Multi-start EM over four haplotype frequencies under random haplotype pairing, compute D,D prime,r squared and ambiguous-double-heterozygote phase probabilities. Retain tied distinct likelihood maxima and label ambiguity. No pedigree linkage, recombination distance, multi-locus phasing or significance test.

Use a three-by-three unphased genotype table

Rows of the input are AA, Aa, and aa at the first locus; columns are BB, Bb, and bb at the second. Each cell counts unrelated subjects having that pair of unphased genotypes. The nine counts must be nonnegative integers totaling at least ten and at most one hundred thousand complete diploid observations. Do not enter haplotype counts into this genotype table.

Four haplotypes are possible: AB, Ab, aB, and ab. Most genotype cells identify one compatible unordered haplotype pair, but the double heterozygote AaBb can arise from AB with ab or Ab with aB. That unresolved phase is the reason an iterative model is required. The row and column labels fix allele orientation, so relabeling an allele can change the sign of D.

Two phase routes produce the same double heterozygoteAaBb has two compatible haplotype pairsDouble heterozygoteAB + ab: couplingAb + aB: repulsionFitted probability 0.894469Fitted probability 0.105531Probabilities condition on the default fitted frequencies.
Scroll across to see the full diagram.
EM allocates ambiguous counts probabilistically; the fitted phase probability does not reveal an individual’s true phase.

Compare this with the Latent class analysis calculator for binary item responses. Fits constrained unordered haplotype-pair likelihood for a 3 by 3 unphased genotype table; double heterozygotes have phase ambiguity. This is not arbitrary binary latent-class fitting or simple observed allele correlation.

Estimate haplotypes under random pairing

Let the four haplotype frequencies be nonnegative and sum to one. An unordered pair of distinct haplotypes has probability twice their frequency product; a repeated haplotype has its frequency squared. Summing these pair probabilities over pairs compatible with a genotype gives that genotype's modeled probability. The likelihood multiplies those probabilities raised to the corresponding observed genotype counts.

The random haplotype-pairing assumption is part of the model, rather than a consequence of having unphased data. It can be inappropriate for related individuals, selected samples, or structured mixtures. This page estimates frequencies and linkage disequilibrium under that assumption. It does not provide a significance test, estimate recombination distance, or reconstruct individual phase with certainty.

Why EM needs multiple starting points

At each expectation step, allocate each genotype's count among its compatible haplotype pairs in proportion to their current modeled probabilities. Count the resulting expected haplotypes and divide by twice the number of subjects for the maximization step. The procedure increases the likelihood when implemented correctly, but that property alone does not establish a unique global maximum.

Run several distinct interior starting frequency vectors, compare achieved likelihoods, and retain genuinely distinct tied solutions rather than merging their phases arbitrarily. Boundary frequencies and a table composed mostly of double heterozygotes can produce weak identification or multiple explanations. A convergence flag describes numerical progress for a start; it should not be presented as a general biological certificate that the inferred phase is known.

The default table gives positive disequilibrium

The default nine counts total one hundred ten subjects, including thirty double heterozygotes. Independent enumeration of compatible pairs with multi-start EM gives frequencies AB approximately 0.403791252, Ab 0.114390566, aB 0.141663293, and ab 0.340154889. They sum to one; the implied marginal allele frequencies also agree with those obtained directly from the genotype table.

For this orientation D is approximately 0.121146624, D prime approximately 0.514341807, and r squared approximately 0.237094453. Conditional on being a double heterozygote under the fitted model, the AB/ab coupling probability is approximately 0.894469183. That is a model-based probability shared by that ambiguous genotype category, not a confirmed phase assignment for each of the thirty individuals.

Read the two phase routes

The figure separates the coupling route AB plus ab from the repulsion route Ab plus aB for an AaBb subject. Both produce the same unordered alleles at each locus. Arrow weights explain how the EM expectation step shares ambiguous counts between those routes. Homozygous or singly heterozygous genotype cells provide additional information that can favor one route through the overall fitted frequencies.

A linkage disequilibrium summary compares the fitted AB frequency with the product of its marginal allele frequencies. Positive D indicates more AB and ab coupling than that product model expects under the chosen labels. Squared correlation removes the sign but remains sensitive to allele frequencies. High D prime with modest r squared is possible, so the two normalized measures should not be described as equivalent scales.

Normalize D with the correct feasible bound

D equals fAB minus pA times pB. Its feasible positive upper bound is the smaller of pA times one minus pB and one minus pA times pB. For negative D the magnitude bound is the smaller of pA pB and (1-pA)(1-pB). Dividing by the bound of the corresponding sign gives the signed D prime convention used here.

The r-squared denominator is pA(1-pA)pB(1-pB). If a locus is monomorphic that denominator vanishes, and normalized disequilibrium measures are undefined rather than evidence of perfect association. Iteration limits, near-boundary frequencies, and tied maxima should be visible in the output. No pseudo-count or smoothing prior is inserted without disclosure, because that would change both the likelihood and the reported estimates.

Keep phasing distinct from association inference

A single-locus equilibrium test evaluates a different target and cannot recover two-locus haplotypes. A phased haplotype-count calculator also answers a different question because its input already resolves the ambiguous diplotypes. This page specifically models two biallelic loci from unphased genotype counts. Pedigree transmission, multi-locus phasing, and physical recombination maps require additional data and algorithms.

Record both locus orientations, the complete count table, pairing assumption, initialization strategy, convergence status, competing likelihoods, and all retained frequency solutions. Present D and r squared as estimated association summaries under that model. If alternative solutions have the same likelihood, retain the ambiguity in any downstream explanation rather than selecting a phase because it yields the most appealing association magnitude.

A few questions, answered

What order must the table use?

Rows AA,Aa,aa at the first locus and columns BB,Bb,bb at the second; the four reported haplotypes are AB,Ab,aB,ab.

Are double heterozygotes assigned a certain phase?

No. Their compatible diplotypes receive fitted posterior probabilities under the random-pairing model.

Can EM have multiple solutions?

Yes. Distinct starts can reach different maxima, and tied distinct solutions should be retained as phase ambiguity.

Does r squared estimate recombination distance?

No. It summarizes allelic association and is not a recombination map estimate or a significance test.

Find your calculator

Start typing to explore the library.