Home › Biology, 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
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
count_homozygous_dominant | integer | yes | Number of individuals with genotype AA. Range: ≥ 0, ≤ 1000000000 | |
count_heterozygous | integer | yes | Number of individuals with genotype Aa. Range: ≥ 0, ≤ 1000000000 | |
count_homozygous_recessive | integer | yes | Number of individuals with genotype aa. Range: ≥ 0, ≤ 1000000000 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
total_individuals | integer | Sum of the three genotype counts. | |
p | number | Dominant allele frequency (2·AA + Aa) / 2N. | |
q | number | Recessive allele frequency 1 − p. | |
observed_frequencies | object | Observed fractions of AA, Aa and aa. | |
expected_frequencies | object | p_squared (AA), two_pq (Aa) and q_squared (aa) expected under equilibrium. | |
expected_homozygous_dominant | number | p² × N. | |
expected_heterozygous | number | 2pq × N. | |
expected_homozygous_recessive | number | q² × N. | |
chi_square | number | Σ (observed − expected)² / expected over the three genotypes. | |
degrees_of_freedom | integer | 3 genotype classes − 1 − 1 estimated parameter (p) = 1. | |
p_value | number | P(χ²₁ ≥ chi_square) = 2 × (1 − Φ(√χ²)). | |
in_equilibrium | boolean | true when p_value ≥ 0.05 (no significant deviation at α = 0.05). | |
interpretation | string | Plain-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
- API:
GET https://tttkmbb.com/api/v1/calculate/hardy-weinberg(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/hardy-weinberg · Markdown: https://tttkmbb.com/science/hardy-weinberg.md · JSON definition: https://tttkmbb.com/science/hardy-weinberg.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="hardy-weinberg" - OpenAPI operationId:
calculate_hardy_weinberg - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- Wikipedia – Hardy–Weinberg principle (reference)
- OpenStax Biology 2e – 19.1 Population Evolution (textbook)
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
- Punnett Square Calculator — Offspring ratios of a single cross instead of population frequencies.
- Chi-Square Test Calculator — General chi-square tests for contingency tables and other goodness-of-fit problems.
- P-Value Calculator — Convert a chi-square statistic with other degrees of freedom to a p-value.