Hardy-Weinberg calculator
This Hardy-Weinberg calculator finds the allele frequencies p and q and the expected genotype frequencies p², 2pq and q² for a gene with two alleles. Start from genotype counts to test whether a sample is in Hardy-Weinberg equilibrium with a chi-square test, or from one known frequency, such as the share of people with a recessive condition, to get the carrier frequency.
Hardy-Weinberg calculator from genotype counts
Hardy-Weinberg calculator from one known frequency
How to use the Hardy-Weinberg calculator
Use the first panel when you have genotyped a sample and know how many individuals are AA, Aa and aa. The Hardy-Weinberg calculator counts the alleles to get p and q, works out how many of each genotype you would expect if the population were in equilibrium, and then compares observed with expected counts in a chi-square test with one degree of freedom. It also reports the observed and expected heterozygosity and the inbreeding coefficient F, which shows whether heterozygotes are missing or in excess. The chart marks your χ² value on the chi-square distribution, with the rejection region in red.
Use the second panel when you know only one number and are willing to assume equilibrium. The classic case is a recessive condition: if 1 in 2,500 newborns is affected, the Hardy-Weinberg calculator gives the allele frequency q and the carrier frequency 2pq. In this mode the Hardy-Weinberg calculator can also start from p, q, p², the dominant phenotype frequency or the heterozygote frequency, and add a population size to get expected numbers of people, plants or animals.
The Hardy-Weinberg equations behind the calculator
For one gene with two alleles, A with frequency p and a with frequency q, the allele frequencies add up to one. With random mating and no evolutionary forces, one generation of mating produces genotypes in the proportions of the binomial expansion (p + q)²:
p² is the frequency of AA, 2pq of Aa and q² of aa. From genotype counts, each AA individual carries two A alleles and each Aa one, out of 2N alleles in all:
The goodness-of-fit test compares observed (O) and expected (E) counts. There are three genotype classes, one degree of freedom is lost because the counts must add up to N and one more because p is estimated from the same data, so df = 1:
At α = 0.05 the critical value is 3.841: a χ² above it means the sample deviates significantly from equilibrium. The inbreeding coefficient F = 1 − Hobs/Hexp is positive when heterozygotes are fewer than expected. The OpenStax Biology 2e chapter on population evolution explains the principle and its assumptions with a pea plant example.
Worked example with the Hardy-Weinberg calculator
A sample of 200 plants contains 104 AA, 72 Aa and 24 aa. There are 400 allele copies, so p = (2 × 104 + 72)/400 = 280/400 = 0.70 and q = (2 × 24 + 72)/400 = 0.30. In equilibrium you would expect 0.49 × 200 = 98 AA, 0.42 × 200 = 84 Aa and 0.09 × 200 = 18 aa. The chi-square statistic is (104 − 98)²/98 + (72 − 84)²/84 + (24 − 18)²/18 = 0.367 + 1.714 + 2.000 = 4.08. With df = 1 this gives a p-value of 0.0433, below 0.05, so the Hardy-Weinberg calculator rejects equilibrium. The observed heterozygosity is 72/200 = 0.36 against 0.42 expected, F = 1 − 0.36/0.42 = 0.143: there are too few heterozygotes, as in a partly self-pollinating or inbred population.
The second panel’s default is a recessive disorder affecting 1 in 2,500 births. Then q² = 0.0004, q = 0.02 and p = 0.98, so 2pq = 2 × 0.98 × 0.02 = 0.0392: about 1 person in 25.5 is a carrier, nearly 100 times as many as are affected. In 10,000 people that is 9,604 AA, 392 Aa and 4 aa, and 3.92 % of the unaffected people are carriers.
Hardy-Weinberg calculator reference tables
| α (significance level) | Critical χ² for df = 1 | Meaning |
|---|---|---|
| 0.10 | 2.706 | Weak evidence threshold |
| 0.05 | 3.841 | Usual threshold in biology classes and papers |
| 0.01 | 6.635 | Strong evidence |
| 0.001 | 10.828 | Very strong evidence; common for large genetic studies |
Critical values from the NIST/SEMATECH table of chi-square critical values. The Hardy-Weinberg calculator uses the exact chi-square distribution, so it also gives the p-value itself. The table below shows how the genotype frequencies change with the allele frequency; note how most copies of a rare recessive allele hide in carriers.
| q (allele a) | p² (AA) | 2pq (Aa) | q² (aa) | Carriers per affected |
|---|---|---|---|---|
| 0.5 | 0.25 | 0.50 | 0.25 | 2 |
| 0.3 | 0.49 | 0.42 | 0.09 | 4.7 |
| 0.1 | 0.81 | 0.18 | 0.01 | 18 |
| 0.02 | 0.9604 | 0.0392 | 0.0004 | 98 |
| 0.01 | 0.9801 | 0.0198 | 0.0001 | 198 |
Assumptions and practical uses
Hardy-Weinberg equilibrium assumes a large population with random mating and no selection, mutation, migration or genetic drift. Real populations never meet all of these, which is what makes the test useful: a significant deviation points to one of them. Population geneticists use a Hardy-Weinberg calculator to look for inbreeding, population structure (the Wahlund effect, a deficit of heterozygotes when separate subpopulations are pooled) and selection. In genome-wide studies, a Hardy-Weinberg test on control samples is a standard quality check, because genotyping errors often show up as an excess or deficit of heterozygotes. In medical genetics, the Hardy-Weinberg calculator estimates carrier frequencies from disease incidence for counseling and screening programs. For the general goodness-of-fit test with other ratios, use the Chi-Square Calculator; to see how genotypes arise in a single family, use the Punnett Square Calculator.
Common mistakes with a Hardy-Weinberg calculator
Taking the square root of the dominant phenotype. With complete dominance you cannot tell AA from Aa, so start from the recessive phenotype: q = √q², never p = √(p² + 2pq). Entering percentages instead of counts in the test: 52 %, 36 % and 12 % give the right p but a meaningless χ², because the statistic grows with sample size. Using df = 2. The Hardy-Weinberg calculator uses df = 1 because p is estimated from the sample, a two-allele Hardy-Weinberg test has 1 degree of freedom, not 2. Treating “not significant” as proof of equilibrium. A small sample rarely rejects anything. Ignoring small expected counts. When an expected count is below 5, typically for a rare allele, use an exact test instead of the chi-square approximation. Applying the formulas to X-linked genes without separating males, who carry one copy, from females, who carry two.
Related calculators
More tools for genetics and lab statistics are in the Biology Calculators; the Statistics Calculator summarizes a data set.
- Chi-Square Calculator
- Punnett Square Calculator
- Statistics Calculator
- Probability Calculator
- All biology calculators
Frequently asked questions
How do you calculate p and q from genotype counts?
Count alleles: p = (2 × AA + Aa) / (2N) and q = (2 × aa + Aa) / (2N), where N is the number of individuals. For 104 AA, 72 Aa and 24 aa, p = 280/400 = 0.70 and q = 0.30, as the first panel of the Hardy-Weinberg calculator shows.
How do you find the carrier frequency of a recessive disease?
Take the incidence as q², so q = √(incidence), p = 1 − q and the carrier frequency is 2pq. For 1 in 2,500, q = 0.02 and 2pq = 0.0392, about 1 in 25. The Hardy-Weinberg calculator does this in the second panel.
Why does the Hardy-Weinberg chi-square test have 1 degree of freedom?
There are three genotype classes. One degree of freedom is lost because the expected counts must add up to the sample size, and one more because the allele frequency p is estimated from the same data, leaving 3 − 1 − 1 = 1.
What does it mean if a population is not in Hardy-Weinberg equilibrium?
Something other than random mating of a large, closed population is acting on that gene: inbreeding, population structure, selection, migration, drift in a small population, or genotyping errors. A heterozygote deficit (positive F, which the Hardy-Weinberg calculator reports) is the most common pattern.
Can I use percentages in the Hardy-Weinberg calculator?
In the second panel, yes, as fractions (0.16 for 16 %). For the chi-square test in the first panel you need counts of individuals, because the test depends on the sample size.
Is this Hardy-Weinberg calculator free?
Yes. It runs in your browser, needs no sign-up and does not store or send the counts you enter.