EProportions · Guide test 297
Hardy–Weinberg likelihood ratio test
Uses a likelihood comparison to test equilibrium genotype probabilities.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Hardy–Weinberg proportions (exact, χ², likelihood ratio) — Do the genotype counts at one marker match what random mating predicts?
In Hardy–Weinberg proportions (exact, χ², likelihood ratio), choose Test = Likelihood ratio (G²).
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Hardy–Weinberg likelihood ratio test
0 is Hardy–Weinberg equilibrium.
Your data
Edit the countsDashed lines: the counts H₀ expects (equal shares).
If H₀ were true
- The reference: how G varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .004).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- observed and Hardy–Weinberg expected genotype counts
The verdict
G(1) = 8.37, p = .004, F = 0.20
p ≤ α = .050: reject H₀
Effect size: inbreeding coefficient F = 0.205
Asymptotically the same as the χ² version; both fail with rare genotypes.
- Statistic
- 8.372
- p-value
- 0.0038
Hardy–Weinberg likelihood ratio test on 41, 76, 83 across 3 categories: G(1) = 8.37, p = .004, F = 0.20. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: genotype probabilities satisfy Hardy–Weinberg proportions.
Assumptions
Independent diploid individuals from a suitably defined population, reliable biallelic genotypes, and random-union-of-gametes Hardy–Weinberg proportions under H0. Relatedness, stratification and genotype error affect inference. Standard likelihood-ratio calibration requires regular, sufficiently populated cells.
Formula
Parameters and notation
Eg uses the fitted allele frequency as in entry 295; zero observed counts contribute zero. Saturated genotype model has two free probabilities versus one under H0.
Structure of the method
Fit the equilibrium one-parameter genotype model and compare its multinomial likelihood with the saturated two-parameter genotype model. Twice the log likelihood difference gives the likelihood-ratio statistic; observed zero cells contribute zero by a limit, while impossible fitted expectations require careful boundary handling.
Estimated and nuisance parameters
The null estimates allele frequency; the saturated alternative estimates genotype proportions. For a regular autosomal biallelic model the parameter-dimension difference is one. The likelihood ratio itself is computed, not an effect estimate or a learned model coefficient.
Settings and design choices
Choose marker type, genotype coding, population definition and asymptotic versus conditional/bootstrap calibration in advance. Do not label an X-linked or multi-allelic analysis as the same three-count model. Report the distinction between Lambda, −2 log Lambda and the returned p value.
Fitting and adaptation
Fit both likelihoods consistently for each dataset. For a parametric bootstrap under equilibrium, estimate the null frequency, simulate the specified design and refit both models for every replicate. Fine-tuning language is inapplicable: the relevant operation is constrained versus unconstrained likelihood fitting.
Sensitivity and robustness
Rare genotypes and allele frequencies near zero or one weaken standard chi-square asymptotics. Agreement with Pearson’s test in large samples does not make sparse-cell behavior identical. Inspect fitted counts and genotype quality; a likelihood departure still has nonunique biological explanations and may reflect stratification or measurement error.
How to use and calibrate
Use χ²1 asymptotically or an exact/parametric-bootstrap calibration.
Example application
Assess equilibrium with a likelihood-ratio criterion.
Interpretation and pitfalls
Watch out
This is the general G/likelihood-ratio framework applied to genetic proportions; sparse-cell limitations remain.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Genotype counts from unrelated diploid individuals at one biallelic locus; allele frequency is estimated from these counts. Stratification, relatedness and genotyping error affect interpretation.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: HardyWeinberg
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
counts<-c(AA=36,AB=48,BB=16);print(HardyWeinberg::HWLratio(counts))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Not run — Syntax checked; runtime not verified in the final environment · needs HardyWeinberg
counts<-c(AA=36,AB=48,BB=16);print(HardyWeinberg::HWLratio(counts))
Sources
- HardyWeinberg — HardyWeinberg · HWLratioAuthor documentation/source reviewed: HardyWeinberg 1.7.9.search.r-project.org
- HWLratiosearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 297, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT297.