Home / Science / Molecular and cell biology / Genetics / Hardy-Weinberg testerTool #206

Hardy-Weinberg equilibrium test: chi-square, exact test, inbreeding coefficient F and de Finetti diagram

Test whether one sample's genotype counts fit Hardy-Weinberg proportions. Gives allele frequencies, observed and expected heterozygosity, the inbreeding coefficient F, chi-square with optional continuity correction, and the exact test (two-sided and one-sided), with a de Finetti diagram. Also handles three or more alleles by chi-square.

Keep it one tap away for everyday use.

Bookmark Hardy-Weinberg tester?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Genotypes
  2. p and q
  3. HWE test
  4. Diagram
Nothing is uploadedWorks offline once open

Genotype counts

Hardy-Weinberg equilibrium predicts genotype shares p², 2pq and q² from the allele frequencies. The chi-square test is an approximation that needs expected counts of about 5 or more; Yates's correction makes it more cautious in small samples. The exact test (two alleles) is correct at any sample size and is the one to report. F = 1 − Ho/He: above 0 means too few heterozygotes, below 0 too many. The example counts are made up.

Result

Observed and expected

de Finetti diagram

Each corner is a genotype; a sample is a point whose distances from the three sides are its genotype shares. The curve is every population in Hardy-Weinberg equilibrium. Points below the curve have too few heterozygotes; above it, too many.

Exact test: every possible heterozygote count

With these allele counts fixed, the chance of each possible number of heterozygotes under Hardy-Weinberg. The exact p-value adds up every count no more likely than the one observed.

Download

What it does

In a large population with random mating and no selection, migration or mutation at a gene, genotype shares settle at p², 2pq and q², where p and q are the two allele frequencies. This is Hardy-Weinberg equilibrium (HWE). Testing it is a classic teaching exercise. It is also a routine quality check for genotyping: a SNP far out of HWE in healthy samples often means a genotyping error.

This page tests one sample at one gene (locus). It gives the allele frequencies, the expected counts, the chi-square test (with Yates’s continuity correction if you want it), the exact test of Wigginton and others (two-sided, plus one-sided for a heterozygote deficit or excess), the inbreeding coefficient F = 1 − Ho/He, and a de Finetti diagram.

How to use it

  1. Two alleles: type the counts of the three genotypes, such as AA, AB and BB. You can rename the alleles; the labels follow.
  2. Three or more: one row per genotype, written with a slash (A/B), then its count. Genotypes you leave out count as zero. Paste from a spreadsheet or open a CSV or Excel file. This mode uses chi-square with k(k − 1)/2 degrees of freedom; the exact test and the diagram are for two alleles.
  3. Continuity correction: subtracts ½ from each |O − E| before squaring. This makes the chi-square test more cautious in small samples. The exact test does not need it.

Reading the de Finetti diagram

The triangle’s corners are the three genotypes. Each sample is one point, placed so that its distances to the sides are its genotype shares. The curve is the Hardy-Weinberg parabola: every possible population in equilibrium. Points below the curve have too few heterozygotes, as from inbreeding or mixing populations; points above it have too many. The second chart shows the exact test itself: the probability of each possible heterozygote count, given the allele counts.

Worked example

The made-up sample has 12 AA, 70 AB and 18 BB, so p(A) = 0.47 and Hardy-Weinberg expects 22.09, 49.82 and 28.09. There are 70 heterozygotes where 49.82 are expected: Ho = 0.7 against He = 0.4982, so F = −0.4051, a heterozygote excess. Chi-square is 16.41 (p = 5.11 × 10⁻⁵), or 15.21 with the continuity correction. The exact test gives p = 0.000109 two-sided. The one-sided test for too many heterozygotes gives p = 5.67 × 10⁻⁵, and the one for too few gives p = 1.00. The point sits well above the curve in the diagram.

In Three or more, the made-up three-allele sample gives chi-square 4.254 with 3 degrees of freedom, p = 0.235, and F = 0.1179.

This tool or the allele frequency calculator?

Use this Hardy-Weinberg tester for one sample at one locus: learning HWE, checking a SNP’s genotype calls, one-sided tests, the continuity correction, more than two alleles, and the de Finetti picture. Use the allele frequency calculator when you have several populations and want to compare them with F-statistics (FIS, FST, FIT, by Weir and Cockerham or Nei).

FAQ

Why only 1 degree of freedom for 3 genotypes? One is lost to the fixed total and one to the allele frequency, which is estimated from the same data.

Which p-value should I report? The exact test: it is valid at every sample size. Use the one-sided versions only if you decided the direction before looking.

Is my data uploaded? No. Everything runs in your browser.

Where the numbers come from

  • Hardy-Weinberg principle (G. H. Hardy 1908; W. Weinberg 1908). Exact test: J. E. Wigginton, D. J. Cutler and G. R. Abecasis (2005), Am. J. Hum. Genet. 76: 887-893. Continuity correction: F. Yates (1934). de Finetti diagram: B. de Finetti (1926). Formulas only; no tables are copied.
  • Checked in the tests: two-sided and one-sided exact p-values against a full enumeration with exact fractions in Python; Yates-corrected chi-square against NumPy and scipy.stats.chi2; three-allele chi-square, He and F against an independent NumPy calculation.
  • The example counts are made up.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

VCF viewer and filter #173 Open a VCF or .vcf.gz file of any size and see variant types, Ti/Tv ratio, multi-allelic sites, FILTER and QUAL, allele frequencies, genotypes per sample and counts by chromosome. Filter by chromosome, region, QUAL, depth, PASS and type, then download the filtered VCF. Nothing is uploaded. Sample size and power calculator #32 How many subjects, samples or survey responses do you need? Sample size for comparing two means, paired data, two proportions, or a survey's margin of error, with power curves. Matches R and G*Power. DNA sequence tools #163 Paste a DNA or RNA sequence or open a FASTA file. Get the length and GC content, the reverse complement, the protein in any of the six reading frames, every open reading frame above a length you choose drawn on a map, and a codon usage table. Runs in your browser; your sequence never leaves the device. Punnett square and pedigree probability #202 Draw a Punnett square for 1 to 4 genes (complete, incomplete and codominant dominance, ABO blood groups, X-linked traits) and get the genotype and phenotype ratios as exact fractions. Use the branch method for up to 6 genes, the binomial rule for several children, and a Bayes table for carrier risk in a family. For learning, not genetic counselling. Mendelian chi-square test #203 Check whether the offspring of a cross fit a Mendelian ratio such as 3:1, 1:2:1, 9:3:3:1, 9:3:4, 12:3:1, 15:1, 1:1, 1:1:1:1 or your own. Get expected counts, chi-square, degrees of freedom, the p-value, which classes drive the result, a warning for small expected counts, and an exact binomial or multinomial test. Linkage map calculator #204 Convert recombination frequencies to map distances with the Haldane and Kosambi mapping functions (and back), order loci and draw a linkage map from a table of pairwise recombination frequencies, and solve a three-point testcross: gene order, recombination frequencies, coefficient of coincidence and interference. Runs in your browser.