Skip to main content

Allele Frequency Calculator

Hardy–Weinberg equilibrium: from genotype counts (AA, Aa, aa) get allele frequencies p & q, expected genotype frequencies p², 2pq, q², and a chi-square goodness-of-fit test (df = 1) with p-value and interpretation. Runs 100% in your browser.

Enter the observed number of individuals of each genotype. Counts must be non-negative whole numbers.

Worked example

A sample of 800 individuals has genotypes AA=250, Aa=400, aa=150.

  1. Allele counts: A = 2×250 + 400 = 900; a = 2×150 + 400 = 700; total = 1600.
  2. p = 900/1600 = 9/16 = 0.5625; q = 1 − p = 0.4375.
  3. Expected counts: p²N = 253.125, 2pqN = 393.75, q²N = 153.125.
  4. χ² = Σ(O−E)²/E = 0.2016 with df = 1; p-value = 0.6535. Since 0.6535 > 0.05, the sample is consistent with Hardy–Weinberg equilibrium.

Perfect-equilibrium anchor: AA=36, Aa=48, aa=16 gives p = 0.6 (3/5), q = 0.4 (2/5), expected exactly 36/48/16, χ² = 0, p-value = 1.0000.

How to read the result

  • p-value ≥ 0.05 — fail to reject H₀: the sample is consistent with Hardy–Weinberg equilibrium.
  • p-value < 0.05 (χ² > 3.841) — reject H₀: the population departs from equilibrium. Candidate causes: natural selection, genetic drift, migration, mutation, non-random mating (inbreeding), or genotyping error.
  • The test has 1 degree of freedom because p is estimated from the same data (3 classes − 1 fixed total − 1 estimated parameter).
  • The χ² approximation is shaky when any expected count is below ~5 — treat tiny samples as exploratory.
Boundary note: this tool tests Hardy–Weinberg equilibrium specifically. For contingency tables, tests of independence, or other goodness-of-fit problems, use our general chi-square calculator.

Frequently asked questions

What is allele frequency?

Allele frequency is the proportion of one gene variant (allele) among all copies of that gene in a population. For a gene with alleles A and a, the frequencies are written p (for A) and q (for a), with p + q = 1. Example: in a sample of 100 people with genotypes AA=36, Aa=48, aa=16, there are 120 A alleles out of 200 total, so p = 0.6 and q = 0.4.

How do you calculate allele frequency from genotype counts?

Count the alleles directly: p = (2 x AA + Aa) / (2N) and q = 1 - p, where N is the number of individuals. Each AA individual contributes 2 copies of A, each Aa contributes 1. Example: AA=36, Aa=48, aa=16 gives N=100, so p = (72 + 48) / 200 = 120/200 = 0.6, and q = 0.4. This calculator does the counting for you and shows the exact fractions.

What is the Hardy-Weinberg equation?

The Hardy-Weinberg equation states that under equilibrium, genotype frequencies follow p^2 + 2pq + q^2 = 1, where p^2 is the expected frequency of AA, 2pq of Aa, and q^2 of aa. With p = 0.6 and q = 0.4, the expected frequencies are 0.36 (AA), 0.48 (Aa), and 0.16 (aa). Multiply by sample size N to get expected counts.

What does Hardy-Weinberg equilibrium mean?

Hardy-Weinberg equilibrium means allele and genotype frequencies stay constant from generation to generation. It holds only when five conditions are met: no mutation, no migration, no natural selection, random mating, and a very large population (no genetic drift). Real populations rarely meet all five, which is why the equilibrium is used as a null model to detect evolution.

How do you test whether a population is in Hardy-Weinberg equilibrium?

Use a chi-square goodness-of-fit test comparing observed genotype counts to the expected counts (p^2 x N, 2pq x N, q^2 x N). This calculator computes the chi-square statistic with 1 degree of freedom and its p-value. Example: observed 250/400/150 gives expected 253.125/393.75/153.125, chi-square = 0.2016, p-value = 0.6535, which is well above 0.05, so the sample is consistent with Hardy-Weinberg equilibrium.

Why does the Hardy-Weinberg chi-square test use 1 degree of freedom?

Degrees of freedom equal (number of genotype classes) minus 1 (the fixed total) minus (number of parameters estimated from the data). With 3 genotype classes and p estimated from the sample, df = 3 - 1 - 1 = 1. The critical value at alpha = 0.05 is 3.841: reject equilibrium if chi-square exceeds it.

What does a significant chi-square result mean in a Hardy-Weinberg test?

A significant result (p-value below 0.05, or chi-square above 3.841) means the population departs from Hardy-Weinberg equilibrium. Possible causes are natural selection, genetic drift, migration, new mutations, non-random mating (such as inbreeding), or genotyping errors in the data. An extreme example: 0 AA, 100 Aa, 0 aa gives chi-square = 100 and p-value about 1.5e-23, a massive departure.

Can I enter allele frequencies instead of genotype counts?

Yes. Switch to the Allele frequency tab and enter p (0 to 1); q is computed as 1 - p, or enter both and the tool checks that p + q = 1. The calculator returns the expected genotype frequencies p^2, 2pq, q^2, and if you also give a sample size N it converts them to expected counts. Note that the chi-square test requires observed counts, so it is only available in the genotype-counts mode.

Why does the calculator reject negative or fractional genotype counts?

Genotype counts are numbers of individuals, so they must be non-negative whole numbers. A negative count or a fractional count like 48.5 is impossible data, and silently rounding it would corrupt the exact fraction math (p = 120/200 = 3/5). The calculator rejects such input with an explicit error instead of guessing.

How reliable is the chi-square test for small samples?

The chi-square approximation is unreliable when any expected genotype count is below about 5. Small samples also give wide uncertainty around p and q. Treat results from tiny samples as exploratory; for publication-grade analysis with rare alleles, use an exact test (for example Fisher's exact test for HWE) rather than chi-square.

Is this the same as a general chi-square calculator?

No. This tool is specific to population genetics: it estimates p from your data, derives the Hardy-Weinberg expected counts, and runs the chi-square test with exactly 1 degree of freedom. For contingency tables, independence tests, or other goodness-of-fit problems, use our general chi-square calculator at nrtechstudio.com/tools/chi-square/.

Is my data sent to a server?

No. This calculator runs 100 percent in your browser using JavaScript. Your genotype counts never leave your device, there are no accounts, no cookies for the calculation, and no external requests.

Free tool by NRTechStudio