Hardy-Weinberg Equilibrium Calculator: Allele Frequency, Genotype Frequency, and HWE Departure Test
What is the Hardy-Weinberg Law
The Hardy-Weinberg Law (HWE) describes the quantitative relationship between allele frequency and genotype frequency in an ideal diploid sexually reproducing population free from evolutionary pressures. For a biallelic locus, let p be the frequency of the major allele A and q the frequency of the minor allele a:
p + q = 1
The expected genotype frequencies under HWE are:
f(AA) = p²
f(Aa) = 2pq
f(aa) = q²
These sum to p² + 2pq + q² = (p+q)² = 1, which is mathematically self-consistent. In a large, randomly mating population, HWE is reached in a single generation.
Two use cases
Use case 1: Derive genotype frequencies from allele frequency (carrier frequency estimation)
Given the minor allele frequency q, the expected proportions of all three genotypes follow immediately. The most common application is carrier frequency estimation for autosomal recessive diseases.
Worked example: Cystic fibrosis has a prevalence of approximately 1/2500 in northern Europeans:
q² = 1/2500 → q = √(1/2500) ≈ 0.02,p ≈ 0.98
Carrier frequency = 2pq = 2 × 0.02 × 0.98 ≈ 0.039 (≈ 1/26)
About 1 in 26 individuals is a carrier — far more than the 1 in 2500 who are affected.
Use case 2: Test for HWE departure from observed genotype counts
In GWAS (genome-wide association study) quality control, every SNP must pass an HWE test: in healthy controls, loci that depart significantly from HWE usually indicate genotyping errors or batch effects rather than true genetic association signals.
Calculation steps: Given observed counts n_AA, n_Aa, n_aa with total sample size n = n_AA + n_Aa + n_aa:
Step 1: Estimate allele frequencies from the observed data:
q̂ = (n_Aa + 2 × n_aa) / (2 × n)
p̂ = 1 − q̂
Step 2: Compute expected counts under HWE:
E_AA = n × p̂²
E_Aa = n × 2p̂q̂
E_aa = n × q̂²
Step 3: Compute the χ² statistic (df = 1):
χ² = (n_AA − E_AA)² / E_AA
+ (n_Aa − E_Aa)² / E_Aa
+ (n_aa − E_aa)² / E_aa
Worked example (verifiable): n = 1000, observed AA = 820, Aa = 160, aa = 20:
q̂ = (160 + 2×20) / 2000 = 0.10,p̂ = 0.90
E_AA = 810,E_Aa = 180,E_aa = 10
χ² = (820−810)²/810 + (160−180)²/180 + (20−10)²/10
= 0.123 + 2.222 + 10.000 = 12.35
df = 1,p ≈ 0.0004 (significant departure from HWE)
This pattern of departure (heterozygote deficit 160 < 180, homozygote excess) is the most typical signature of genotyping error.
Scope and limitations
- Biallelic loci only. Multi-allelic loci (e.g., microsatellites, multi-nucleotide polymorphisms) require extended formulas; this tool does not support them.
- The χ² approximation requires expected counts ≥ 5 in every cell. With small sample sizes or very low minor allele frequencies (E_aa < 5), the χ² approximation is unreliable; an exact test is preferred. In the worked example above, E_aa = 10 ≥ 5, so the condition is satisfied.
- In GWAS QC, apply HWE filtering only to controls. Disease-associated loci may depart from HWE in cases due to selection; strict filtering of cases discards true signals. The standard threshold for controls is p < 1×10⁻⁶.
Common mistakes
Equating HWE departure with genotyping error: In an admixed population, each ancestral sub-group may individually satisfy HWE, but pooling them produces a systematic allele-frequency imbalance (Wahlund effect) that can give very small p-values — this reflects population structure, not a technical artifact. Stratify by principal components (PC) before QC.
Using disease prevalence directly as q: Prevalence is q² (the frequency of recessive homozygotes), not q. Treating prevalence as q overestimates the carrier frequency by nearly two orders of magnitude.
FAQ
Why does the HWE test have 1 degree of freedom instead of 2?
There are three genotype classes; if all parameters were known in advance, df = 2. Here, the allele frequency is estimated from the observed data (consuming one degree of freedom), giving df = 3 − 1 (classes) − 1 (estimated parameter) = 1.
What p-value threshold is commonly used for HWE filtering in GWAS QC?
In controls (healthy individuals) the standard cutoff is p < 1×10⁻⁶. In cases, disease-associated loci can depart from HWE for biological reasons, so the threshold is relaxed or omitted to avoid discarding true association signals.
Why is a deficit of heterozygotes the classic signature of a genotyping error?
On genotyping arrays or in sequencing, heterozygous calls require resolving two alleles whose signals are more similar than in either homozygote, making heterozygotes systematically undercalled. The result is a deficit of Aa and excess of both homozygotes — a pattern that shows up as significant HWE departure.
What is the pitfall of running an HWE test on an admixed population?
Each ancestral sub-population may individually be at HWE, but pooling them together produces a systematic allele-frequency imbalance (Wahlund effect) that can give very small p-values — this reflects population structure, not genotyping error. Principal-component stratification should precede GWAS QC.
Given the prevalence of a recessive disease, how do I estimate the carrier frequency?
Assuming HWE: prevalence = q², so q = √(prevalence), p = 1 − q, carrier frequency = 2pq. For example, cystic fibrosis in northern Europeans has a prevalence of about 1/2500, giving q ≈ 0.02, p ≈ 0.98, and a carrier frequency of ≈ 2×0.02×0.98 ≈ 1/26.
Related tools
Multiple Testing Correction Calculator: BH (FDR), BY, and Bonferroni
Paste a column of p-values and get BH q-values, BY, and Bonferroni corrections side by side in one step.
qPCR 2^−ΔΔCt Relative Quantification Online Calculator
Paste your Ct table and get ΔCt, ΔΔCt, fold-change, and within-group dispersion calculated automatically.
Gene List Intersection, Union & Difference — Online Venn Set Calculator
Paste 2–3 gene/ID lists and instantly get intersections, unions, and unique elements, with deduplication and case normalization.
Buy me a coffee