HomeBiology, Earth & Space › Hardy-Weinberg Equilibrium Calculator

Hardy-Weinberg Equilibrium Calculator

Estimates the allele frequencies p and q of a two-allele locus from observed genotype counts, computes the genotype counts expected under Hardy–Weinberg equilibrium (p², 2pq, q²) and tests the deviation with a chi-square goodness-of-fit test with 1 degree of freedom.

When to use

You have counts of the three genotypes (AA, Aa, aa) of a population sample and need allele frequencies, expected genotype numbers or a test of whether the population is in Hardy–Weinberg equilibrium.

Do not use when: The locus has more than two alleles or is X-linked, you only know phenotype counts of a dominant trait (then q = √(recessive fraction) is the only estimate and no test is possible), or you need a general contingency-table test (use chi-square-test).

Formula

p = (2·AA + Aa) / (2N), q = 1 − p; expected AA = p²N, Aa = 2pqN, aa = q²N; χ² = Σ (O − E)² / E, df = 1; p-value = 2 × (1 − Φ(√χ²))

Hardy–Weinberg equilibrium assumes random mating and no selection, mutation, migration or drift. The test has 1 degree of freedom because p is estimated from the same data; the p-value uses the standard normal CDF exactly, since a χ² variable with 1 df is the square of a standard normal. Expected counts below 5 make the approximation unreliable (a note is added).

Inputs

ParameterTypeUnitRequiredDescription
count_homozygous_dominantintegeryesNumber of individuals with genotype AA. Range: ≥ 0, ≤ 1000000000
count_heterozygousintegeryesNumber of individuals with genotype Aa. Range: ≥ 0, ≤ 1000000000
count_homozygous_recessiveintegeryesNumber of individuals with genotype aa. Range: ≥ 0, ≤ 1000000000

Outputs

OutputTypeUnitDescription
total_individualsintegerSum of the three genotype counts.
pnumberDominant allele frequency (2·AA + Aa) / 2N.
qnumberRecessive allele frequency 1 − p.
observed_frequenciesobjectObserved fractions of AA, Aa and aa.
expected_frequenciesobjectp_squared (AA), two_pq (Aa) and q_squared (aa) expected under equilibrium.
expected_homozygous_dominantnumberp² × N.
expected_heterozygousnumber2pq × N.
expected_homozygous_recessivenumberq² × N.
chi_squarenumberΣ (observed − expected)² / expected over the three genotypes.
degrees_of_freedominteger3 genotype classes − 1 − 1 estimated parameter (p) = 1.
p_valuenumberP(χ²₁ ≥ chi_square) = 2 × (1 − Φ(√χ²)).
in_equilibriumbooleantrue when p_value ≥ 0.05 (no significant deviation at α = 0.05).
interpretationstringPlain-language conclusion of the test.

Example

50 AA, 40 Aa, 10 aa: {"count_homozygous_dominant":50,"count_heterozygous":40,"count_homozygous_recessive":10}{"total_individuals":100,"p":0.7,"q":0.3,"expected_homozygous_dominant":49,"expected_heterozygous":42,"expected_homozygous_recessive":9,"expected_frequencies":{"p_squared":0.49,"two_pq":0.42,"q_squared":0.09},"chi_square":0.2268,"p_value":0.6339,"in_equilibrium":true}

360 AA, 480 Aa, 160 aa (exact equilibrium): {"count_homozygous_dominant":360,"count_heterozygous":480,"count_homozygous_recessive":160}{"p":0.6,"q":0.4,"expected_homozygous_dominant":360,"expected_heterozygous":480,"expected_homozygous_recessive":160,"chi_square":0,"p_value":1,"in_equilibrium":true}

GET https://tttkmbb.com/api/v1/calculate/hardy-weinberg?count_homozygous_dominant=50&count_heterozygous=40&count_homozygous_recessive=10

Machine access

Sources

FAQ

Why only 1 degree of freedom with 3 classes?

One degree is lost because the counts must sum to N and another because the allele frequency p is estimated from the observed counts, leaving 3 − 2 = 1.

Can I use phenotype counts for a recessive trait?

Only to estimate q as the square root of the recessive phenotype fraction (assuming equilibrium); the chi-square test needs the three genotype counts, which this calculator requires.

What does a significant deviation mean?

The genotype proportions differ from p², 2pq, q² more than sampling error explains, pointing to non-random mating, selection, population structure or genotyping error; it does not say which.

Related calculators