Genetics / Population genetics

Hardy-Weinberg Calculator

Explore expected genotype proportions from p or q, or compare observed genotype counts with Hardy-Weinberg expectations and a carefully qualified chi-square test.

Switching modes loads its worked example. Reset restores the example values in the current mode.

01 / Set your frequency

Start with one allele

Enter a proportion from 0 to 1, inclusive. For 70%, enter 0.7.

Expected frequencies under equilibrium. These inputs do not test whether a population is in equilibrium.

02 / Expected proportions

Population snapshot

Allele frequencies

p = 0.7 (70.0%)

q = 0.3 (30.0%)

Genotype frequencies

p² · AA49.0%0.49
2pq · Aa42.0%0.42
q² · aa9.0%0.09

AA (light green) · Aa (teal) · aa (peach). Percentages are rounded to one decimal place.

Step by step

  1. q = 1 − 0.7 = 0.3
  2. p² = 0.7² = 0.49
  3. 2pq = 2 × 0.7 × 0.3 = 0.42
  4. q² = 0.3² = 0.09

p + q = 1; p² + 2pq + q² = 1 before display rounding.

How it works

Choose Allele Frequency for the original p/q calculator, or Observed Genotype Counts for population analysis. Results update as you type. Switching modes loads its example; Reset restores the current mode’s example.

Allele-frequency mode

  1. Choose whether you know p or q.
  2. Enter that allele’s frequency as a proportion between 0 and 1.
  3. The other allele frequency is calculated by subtracting from 1.
  4. Read the expected genotype frequencies and percentages below.

Estimate allele frequencies from observed genotypes

Enter counts of individuals with known AA, Aa and aa genotypes. Each homozygote contributes two copies of its allele, while each heterozygote contributes one of each. Phenotype counts alone are not enough to identify all genotypes.

N = AA + Aa + aa
p = (2AA + Aa) / (2N)
q = (2aa + Aa) / (2N)

Observed genotype frequencies are the counts divided by N. Expected frequencies are p², 2pq and q²; multiplying them by N gives expected genotype counts. Expected counts can be fractional. Both frequency sets sum to one and expected counts sum to N, allowing for floating-point precision.

Chi-square Hardy-Weinberg test

χ² = Σ (Observed − Expected)² / Expected
df = 3 − 1 − 1 = 1

Three genotype categories lose one degree of freedom because their counts sum to N, and another because p is estimated from the same sample. q is determined by p, so only one allele-frequency parameter is estimated. The p/q-only mode does not perform a goodness-of-fit test.

The p-value is the upper-tail probability P(χ² ≥ the observed statistic) under the approximate null distribution. The calculator evaluates that tail numerically with one degree of freedom, using the incomplete-gamma function rather than a normal approximation.

At α = 0.05, a p-value below 0.05 is evidence of deviation. Otherwise there is insufficient evidence to reject the expectations. A p-value is not the probability that the population is in equilibrium, and a nonsignificant result does not prove equilibrium. A significant result does not explain the cause of deviation.

Worked population examples

Exact match: 36 AA, 48 Aa, 16 aa

For 100 sampled diploid individuals, p = (72 + 48)/200 = 0.6 and q = (32 + 48)/200 = 0.4. The expected frequencies are 0.36, 0.48 and 0.16, giving expected counts 36, 48 and 16. All contributions are zero, so χ² = 0 and the p-value is 1. This agreement does not prove that all equilibrium assumptions hold.

Small deviation: 38 AA, 44 Aa, 18 aa

The same p = 0.6 and q = 0.4 give expected counts 36, 48 and 16. Contributions are 4/36, 16/48 and 4/16, so χ² = 25/36 ≈ 0.694444. With df = 1, the p-value is approximately 0.404656762. There is insufficient evidence to reject at α = 0.05.

Clear deviation: 50 AA, 0 Aa, 50 aa

Here p = q = 0.5 and expected counts are 25, 50 and 25. The contributions 25, 50 and 25 sum to χ² = 100. The p-value is about 1.52397 × 10⁻²³, providing strong evidence of deviation under the stated sampling assumptions.

Small expected counts and statistical validity

If any expected count is below 5, this calculator conservatively withholds the p-value and rejection decision; a descriptive statistic may still be shown. If an expected count is zero, that contribution and the overall statistic are undefined. No categories are dropped or pooled. A suitable exact Hardy-Weinberg or alternative analysis may be needed; it is not implemented here.

For example, 0 AA, 40 Aa and 60 aa give p = 0.2 and expected counts 4, 32 and 64. Although the descriptive χ² is 6.25, the expected AA count is below 5, so no inferential conclusion is provided.

Use a representative sample of independent diploid individuals with reliable genotype calls at a biallelic autosomal locus. Related individuals, mixed subpopulations and genotyping errors can affect results. Meeting the expected-count threshold alone is not sufficient to establish the test’s assumptions.

The Hardy-Weinberg equilibrium equation

p + q = 1
p² + 2pq + q² = 1

For a gene with two alleles, p is the frequency of allele A and q is the frequency of allele a. Here we label A dominant and a recessive for consistency with the Punnett calculator; dominance is not required for the equilibrium equation.

p² gives the expected frequency of homozygous AA, 2pq of heterozygous Aa, and q² of homozygous aa. Random pairing produces two routes to Aa, accounting for the factor of 2.

Allele frequency vs genotype frequency

Allele frequency is the proportion of gene copies carrying an allele in the population. Genotype frequency is the proportion of individuals with a particular pair of alleles. A frequency of 0.42 means 42%.

Worked example: p = 0.7

q = 1 − 0.7 = 0.3. The expected AA frequency is 0.7² = 0.49 (49.0%). Aa is 2 × 0.7 × 0.3 = 0.42 (42.0%), and aa is 0.3² = 0.09 (9.0%). The three genotype frequencies sum to 1.

Scientific assumptions and limitations

  • A sufficiently large population, so genetic drift is negligible.
  • Random mating with respect to the gene.
  • No mutation, migration, or natural selection affecting the alleles.

This two-allele diploid model calculates expected frequencies under equilibrium. It does not prove that a real population is in equilibrium. Testing a population requires observed genotype data and an appropriate statistical analysis.

Frequently asked questions

Can I enter a percentage?

Convert it to a proportion first: divide by 100. For example, enter 0.7 for 70%.

Does a common allele have to be dominant?

No. Dominance describes expression in a heterozygote, not how common an allele is. Either p or q can be the larger frequency.

Does this calculator perform a chi-square test?

Yes, in Observed Genotype Counts mode. It estimates allele frequencies from your sample and uses one degree of freedom. Inference is withheld when expected counts are too small or zero. The original allele-frequency mode still calculates expected frequencies only.

Can an observed count be zero?

Yes. Zero observed counts are allowed when the total population is positive. Statistical suitability depends on expected counts, not on whether every observed category is populated.

Why are only whole-number inputs accepted?

Counts represent individual organisms. Enter digits only, using 0 for an absent genotype. Decimal or scientific-notation input is rejected. The total is limited so all allele-copy counts remain safe integers.

Why does a very small p-value use scientific notation?

This preserves small tail probabilities instead of displaying a misleading rounded zero. If a tail underflows JavaScript’s floating-point range, it is explicitly labeled as below numerical range rather than exactly zero.

Scientific and statistical references