Skip to content

Hardy-Weinberg Equilibrium Calculator

Updated: 11 comments

Enter observed counts of homozygous dominant, heterozygous, and homozygous recessive individuals to calculate allele frequencies (p and q), expected genotype frequencies, and a chi-square statistic that tests whether the population is in Hardy-Weinberg equilibrium.

Hardy-Weinberg Frequency and Chi-Square Test

Input Fields
CH
Number of individuals with dominant homozygous genotype (AA)
H
Number of heterozygous individuals (Aa)
RH
Number of individuals with recessive homozygous genotype (aa)
If enabled, the result will update automatically when you change any value.

Hardy-Weinberg Equilibrium Formula

Formula
\[ p = \frac{CH + 0.5 \cdot H}{CH + H + RH}, \qquad q = \frac{RH + 0.5 \cdot H}{CH + H + RH} \\ E_{CH} = p^2 N, \qquad E_H = 2pqN, \qquad E_{RH} = q^2 N \\ \chi^2 = \frac{(CH - E_{CH})^2}{E_{CH}} + \frac{(H - E_H)^2}{E_H} + \frac{(RH - E_{RH})^2}{E_{RH}} \]

Where:

  • \(CH\) — number of homozygous dominant individuals (AA)
  • \(H\) — number of heterozygous individuals (Aa)
  • \(RH\) — number of homozygous recessive individuals (aa)
  • \(N\) — total population size, \(N = CH + H + RH\)
  • \(p\), \(q\) — frequencies of alleles A and a (\(p + q = 1\))
  • \(E_{CH}\), \(E_H\), \(E_{RH}\) — expected genotype counts under equilibrium
  • \(\chi^2\) — chi-square statistic measuring deviation from equilibrium

The first two equations estimate allele frequencies from genotype counts (heterozygotes contribute one copy of each allele), the middle three give the genotype counts expected under Hardy-Weinberg equilibrium, and the last quantifies how far the observed counts deviate from those expectations.

Hardy-Weinberg Equilibrium – Calculation Example

Example: a sample of 100 individuals contains 50 homozygous dominant (AA), 30 heterozygous (Aa), and 20 homozygous recessive (aa) individuals.

\[ p = \frac{50 + 0.5 \cdot 30}{100} = 0.65, \qquad q = \frac{20 + 0.5 \cdot 30}{100} = 0.35 \]

\[ E_{CH} = 0.65^2 \cdot 100 = 42.25, \quad E_H = 2(0.65)(0.35) \cdot 100 = 45.5, \quad E_{RH} = 0.35^2 \cdot 100 = 12.25 \]

\[ \chi^2 = \frac{(50 - 42.25)^2}{42.25} + \frac{(30 - 45.5)^2}{45.5} + \frac{(20 - 12.25)^2}{12.25} \approx 11.61 \]

Result: \(p = 0.65\), \(q = 0.35\); expected counts 42.25 AA, 45.5 Aa, 12.25 aa; \(\chi^2 \approx 11.61\). Since 11.61 exceeds the critical value of 3.84 (1 degree of freedom, \(\alpha = 0.05\)), the population deviates significantly from Hardy-Weinberg equilibrium — there is a deficit of heterozygotes.

How to Use the Calculator

  1. Enter the number of Homozygous dominant individuals (genotype AA) in the first field.
  2. Enter the number of Heterozygous individuals (genotype Aa) in the second field.
  3. Enter the number of Homozygous recessive individuals (genotype aa) in the third field.
  4. Read the results: allele frequencies p and q, the expected counts of each genotype, and the Chi-squared (χ²) statistic.
  5. Compare the chi-squared value with the critical value below to judge whether the population is in equilibrium.

What Is Hardy-Weinberg Equilibrium?

The Hardy-Weinberg principle states that allele and genotype frequencies in a population remain constant from generation to generation in the absence of evolutionary forces. For a gene with two alleles, A and a, with frequencies \(p\) and \(q\) (where \(p + q = 1\)), the genotype frequencies after one generation of random mating are \(p^2\) (AA), \(2pq\) (Aa), and \(q^2\) (aa). This relationship holds only under ideal conditions: no mutation, no migration, no natural selection, infinitely large population size (no genetic drift), and random mating.

Because real populations rarely satisfy all these conditions perfectly, Hardy-Weinberg equilibrium serves as a null model. If observed genotype counts match the expected \(p^2 : 2pq : q^2\) proportions, there is no evidence that evolutionary forces are acting on that locus. If they do not match, the deviation points to one or more violated assumptions — selection, non-random mating (inbreeding), genetic drift, mutation, migration, or genotyping error.

The chi-square goodness-of-fit test quantifies the disagreement between observed and expected counts. Because allele frequencies are estimated from the same data, the test has \(3 - 1 - 1 = 1\) degree of freedom. At the conventional significance level of 0.05, the critical value is 3.84: a χ² below 3.84 is consistent with equilibrium, while a larger value suggests a significant deviation. The allele frequencies p and q themselves remain useful summary statistics even when the equilibrium test is rejected.

This tool is widely used in population genetics, evolutionary biology, and classroom exercises. In genetics counseling contexts, allele frequencies also underpin carrier-risk estimation — see the Blood Type Inheritance Calculator for how genotype combinations pass from parents to offspring.

Interpreting the Chi-Square Result

Degrees of freedom χ² critical value (α = 0.05)
1 3.841
2 5.991

For this test, use 1 degree of freedom, since one allele frequency is estimated from the data. If your χ² value is below 3.841, accept the null hypothesis of equilibrium; if it is above, the deviation is statistically significant at the 5% level.

Assumptions and Limitations

  • The calculator assumes a single autosomal locus with exactly two alleles and complete dominance (AA and Aa are phenotypically distinguishable from aa, and genotypes can be counted directly, e.g. by genetic testing).
  • Equilibrium requires random mating, no selection, no mutation, no migration, and a large population. A significant χ² indicates at least one of these assumptions fails — it does not tell you which.
  • The chi-square approximation is unreliable when expected counts are small (as a rule of thumb, any \(E < 5\)). Combine genotype classes or collect a larger sample in that case.
  • Genotyping errors, sampling bias, and pooled subpopulations (the Wahlund effect) can all produce apparent heterozygote deficits that mimic disequilibrium.
  • The test detects deviation at one locus only; conclusions about a whole population require examining multiple loci.

Frequently Asked Questions

How do I calculate allele frequencies by hand without a calculator?

Count the total copies of the allele and divide by all gene copies in the sample. Each homozygote carries two copies of one allele, each heterozygote carries one of each. So p = (2·AA + Aa) / (2N) and q = (2·aa + Aa) / (2N), where N is the number of individuals. Since there are 2N alleles total, p + q must equal 1 — a quick check that your arithmetic is correct.

Why does this test use 1 degree of freedom instead of 2?

With three genotype classes you would normally lose one degree of freedom for the fixed total (3 − 1 = 2). But here the allele frequency p is estimated from the same sample, and q is then determined by q = 1 − p, so you lose one more degree of freedom: 3 − 1 − 1 = 1. That is why the 5% critical value is 3.84 rather than 5.99. Using the wrong degrees of freedom is one of the most common mistakes in Hardy-Weinberg exercises.

What is a good or normal chi-square value for Hardy-Weinberg equilibrium?

There is no "ideal" value — the statistic depends on sample size and the allele frequencies themselves. A population consistent with equilibrium simply produces a small χ² relative to the critical value of 3.84 (at α = 0.05, 1 df). Very small χ² values are common and expected in idealized textbook data. Very large values signal deviation, but beware: with large samples even tiny biological differences become statistically significant, so also compare observed and expected counts directly.

Can allele frequencies be negative or greater than 1?

No. Because allele frequencies are counts of allele copies divided by the total number of gene copies (2N), both p and q always fall between 0 and 1, and p + q = 1 exactly. If you get a value outside this range, you have made an arithmetic or data-entry error — for example, mistaking phenotype counts (where AA and Aa are indistinguishable) for genotype counts. Note that genotype frequencies can be 0, but allele frequencies only reach 0 or 1 when an allele is entirely absent.

What happens if one genotype is completely missing from my sample?

A missing genotype class is fine for estimating p and q — for example, 0 AA, 40 Aa, 20 aa still gives valid frequencies (p = 0.33, q = 0.67). The concern is the chi-square test: if any expected count is below about 5, the approximation becomes unreliable. With rare alleles, expected homozygote counts are often tiny. In that case collect a larger sample, or use an exact test (such as the exact Hardy-Weinberg test used in genetics software), which handles small samples correctly.

How can I use allele frequencies to estimate carrier frequency for a recessive disease?

If the disease is recessive and the locus is in equilibrium, affected individuals (aa) occur at frequency q², so you can estimate q = √(frequency of affected). The carrier frequency among unaffected people is approximately 2pq. For example, if 1 in 2,500 newborns is affected, q = 1/50 = 0.02, and about 3.9% of the population carries one copy. This assumes equilibrium holds; in practice, consult a genetic counselor for actual risk assessment, since real populations may deviate.

My chi-square is significant but the population seems fine — what could cause a false deviation?

Several technical causes mimic true disequilibrium: genotyping errors that miscall heterozygotes, pooling data from genetically distinct subpopulations (the Wahlund effect, which inflates apparent homozygosity), non-random sampling, or simply small expected counts making the χ² approximation inaccurate. Also check that genotypes were truly distinguished — if AA and Aa were inferred from phenotypes under incomplete dominance assumptions, the input data itself may be wrong. Testing multiple independent loci helps distinguish a data problem from a real biological signal.

Leave a Reply

Your email address will not be published. Required fields are marked *

11 thoughts on “Hardy-Weinberg Equilibrium Calculator”

  1. Asmaa says:

    how can I know if there is deviation from HWE or not ?

    1. Rim says:

      Hello
      If X squared is less than 3,841 than there is no deviation from HWE

  2. Yurany Granada says:

    Buenas tardes, quiero saber como debo citarlos. Gracias

  3. Adriana Mena says:

    How are the df calculated?

    1. Monica says:

      df = number of classes compared – no. of parameters estimated – 1.

  4. Oladejo Aliu Abiola says:

    How do you calculate the expected value for the alleles

  5. Daniel says:

    Si una enfermedad es recesiva y la frecuencia del alelo que la genera es de
    0,08, ¿cómo serán las frecuencias genotípicas?

  6. Nada says:

    I have one question please, the equation was as follows;
    ECH = pfreq * pfreq * (CH + H + RH)
    yet you have used the frequency of the rare allele in the following example ,
    Step 3 : Expected CH

    Expected CH =

    = 0.78 * 0.2121 * (21 + 10 + 2)

    can you explain why, please?
    Plus,
    what do you mean exactly by the following;
    chi2 = chi1 + chi2 + chi3

  7. Aaron Castle says:

    I love you, thank you for saving my grade in bio and letting me keep an A. Thank you!

  8. hamzah H kzar says:

    thank you so much to helping me by your this website

  9. kamna srivastava srivastava says:

    very useful. with you examples anybody can learn easily and population genetics.