Hardy-Weinberg Calculator — Calculate Allele and Genotype Frequencies
The Hardy-Weinberg principle describes the expected allele and genotype frequencies in a population that is not evolving. It provides a mathematical baseline: if a population is in Hardy-Weinberg equilibrium, then no evolution is occurring at that locus. Deviations from equilibrium reveal the forces driving evolution — selection, mutation, genetic drift, non-random mating, or gene flow. The Hardy-Weinberg calculator on PublicSoftTools computes expected frequencies from allele frequencies, or works backward from genotype counts to test for equilibrium.
Hardy-Weinberg Equation and Genotype Frequencies
| Genotype | Expected frequency | Example (p=0.7, q=0.3) | Phenotype |
|---|---|---|---|
| AA (homozygous dominant) | p² | p=0.7: p² = 0.49 (49% of population) | Dominant phenotype expressed |
| Aa (heterozygous) | 2pq | p=0.7, q=0.3: 2pq = 0.42 (42% of population) | Dominant phenotype expressed (A masks a) |
| aa (homozygous recessive) | q² | q=0.3: q² = 0.09 (9% of population) | Recessive phenotype expressed (only in aa) |
| Total (all genotypes) | p² + 2pq + q² = 1 | 0.49 + 0.42 + 0.09 = 1.00 ✓ | All individuals in population |
How to Use the Hardy-Weinberg Calculator
- Open the Hardy-Weinberg calculator.
- Option 1 — From allele frequencies: Enter the frequency of the dominant allele (p) or recessive allele (q). Since p + q = 1, entering one calculates the other. The tool then computes p², 2pq, and q².
- Option 2 — From genotype counts: Enter the observed number of AA, Aa, and aa individuals in a sample population. The calculator determines allele frequencies and tests whether the observed genotype frequencies match Hardy-Weinberg expectations (chi-squared test).
- Option 3 — Find carrier frequency: Enter the frequency of a recessive condition (q²) to find q and then 2pq (carrier frequency).
The Hardy-Weinberg Equations
The principle is expressed in two equations:
Allele frequencies: p + q = 1
Genotype frequencies: p² + 2pq + q² = 1
Where p = frequency of the dominant allele (A) and q = frequency of the recessive allele (a).
The second equation is derived by squaring the first: (p + q)² = p² + 2pq + q² = 1. This is exactly what you would expect if individuals mate randomly — the probability of two alleles combining is the product of their individual frequencies.
The Five Assumptions of Hardy-Weinberg
| Assumption | Violated by | Effect on population |
|---|---|---|
| Large population | Small isolated populations (genetic drift) | Random allele frequency changes due to sampling — allele frequencies drift, not always toward equilibrium |
| Random mating (panmixia) | Sexual selection, assortative mating, geographic isolation | Non-random mating changes genotype frequencies but not necessarily allele frequencies |
| No mutation | Presence of mutations converting one allele to another | Mutation pressure changes allele frequencies slowly over generations |
| No gene flow (migration) | Immigration/emigration bringing new alleles | Gene flow can rapidly change allele frequencies and introduce new alleles |
| No natural selection | Differential survival or reproduction based on genotype | Selection changes allele frequencies directionally — favoured alleles increase over generations |
Worked Example: Cystic Fibrosis Carrier Frequency
Cystic fibrosis (CF) is an autosomal recessive condition. In the UK, approximately 1 in 2,500 children born is affected.
- Affected individuals are homozygous recessive: q² = 1/2500 = 0.0004
- Recessive allele frequency: q = √0.0004 = 0.02 (2%)
- Dominant allele frequency: p = 1 − q = 1 − 0.02 = 0.98
- Carrier frequency: 2pq = 2 × 0.98 × 0.02 = 0.0392 ≈ 1 in 25
So approximately 1 in 25 UK individuals are carriers of the CF allele — far more than the 1 in 2,500 who are affected. This illustrates why recessive alleles can be maintained at relatively high frequency in a population even when the homozygous recessive phenotype is harmful.
Testing for Hardy-Weinberg Equilibrium
To test whether a population is in Hardy-Weinberg equilibrium:
- Count observed genotypes (O): number of AA, Aa, aa individuals
- Calculate allele frequencies from observed data: p = (2×AA + Aa) / (2×total); q = 1 − p
- Calculate expected genotype numbers (E): total × p², total × 2pq, total × q²
- Perform chi-squared test: χ² = Σ(O − E)² / E
- With 1 degree of freedom (for 2 alleles), critical value at p=0.05 is χ² = 3.841
- If χ² > 3.841, reject null hypothesis — population is NOT in Hardy-Weinberg equilibrium
A significant deviation from equilibrium indicates that one or more of the five assumptions is violated — evolution is occurring at this locus.
Why Hardy-Weinberg Matters in Evolution
The Hardy-Weinberg principle is the null hypothesis of population genetics. It describes what would happen if evolution were NOT occurring. By comparing observed genotype frequencies to Hardy-Weinberg predictions:
- Identify which evolutionary forces are at work
- Estimate selection coefficients from deviations
- Detect inbreeding (excess homozygotes) or outbreeding (excess heterozygotes)
- Identify loci under selection in genome-wide association studies (GWAS)
Applications in Medicine and Conservation
Genetic disease screening
Hardy-Weinberg is used to estimate carrier frequencies of recessive genetic conditions from the known incidence of affected individuals (q² known → calculate 2pq). This informs genetic counselling and population screening programmes.
Forensic genetics
DNA profiling uses multiple loci. The probability of a random match is calculated using Hardy-Weinberg: frequency of a specific genotype = p² or 2pq at each locus. The product across loci gives the overall match probability (assuming independence — tested using Hardy-Weinberg).
Conservation genetics
Small isolated populations (endangered species) deviate from Hardy-Weinberg equilibrium due to genetic drift. Monitoring deviations guides conservation decisions — when to introduce genetic diversity from other populations to counteract inbreeding depression.
Common Questions
What does it mean if a population is in Hardy-Weinberg equilibrium?
A population in Hardy-Weinberg equilibrium at a given locus is not evolving at that locus — allele frequencies are stable across generations. This does not mean the population is not evolving at other loci. Real populations are rarely in perfect equilibrium for any locus, but many loci approximate equilibrium closely enough that deviations are meaningful signals of evolutionary forces.
Can q² be greater than q?
Yes — but only when q > 1, which is impossible since allele frequencies must be between 0 and 1. For valid allele frequencies (0 ≤ q ≤ 1), q² ≤ q always. This means homozygous recessives are always at lower frequency than the recessive allele itself — a recessive allele is often hidden in carriers (Aa) and not expressed, allowing it to persist even if harmful when homozygous.
How do you calculate allele frequency from a sample?
From a sample of N individuals: count the alleles (2N total). p = (2 × count of AA + count of Aa) / 2N. q = (2 × count of aa + count of Aa) / 2N. Alternatively, q = 1 − p. Enter these counts in the calculator and it performs this calculation automatically.
Calculate Hardy-Weinberg Frequencies
Enter allele frequencies or genotype counts to find p, q, p², 2pq, and q² — with chi-squared test for equilibrium.
Open Hardy-Weinberg Calculator