hardy_weinberg
Hardy-Weinberg analysis of genotype counts at one autosomal locus with two or more alleles: allele frequencies with standard errors, expected counts, Pearson χ-square, the Levene-Haldane exact test (full enumeration, or seeded Monte Carlo when too large), observed and expected heterozygosity and the inbreeding coefficient F. Also: allele and carrier frequency from the incidence of a recessive condition (with optional Wright's F), and the χ-square upper tail.
- Field
- Genomics
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.05 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001MN blood group textbook counts 298/489/213: p = 1085/2000 = 0.5425 exactly, expected M/N = 2Npq = 496.3875, χ-square = N F² = 0.221490 (textbook 0.222), df 1 (closed form, rel 10⁻⁹)passed
p0.5425 ± 5.4 × 10⁻¹³0.5425lockedunder 0.01 % of the tolerance usedq0.4575 ± 4.6 × 10⁻¹³0.4575lockedunder 0.01 % of the tolerance usedgenotype_table.M/N.expected= 496.3875, within 1.000000 × 10⁻¹² relativereading not recorded on this pagechi_square0.22149 ± 2.2 × 10⁻¹⁰0.22149lockedunder 0.01 % of the tolerance usedinbreeding_F0.0148825 ± 1.5 × 10⁻¹¹0.0148825lockedunder 0.01 % of the tolerance useddf11lockedr0002counts exactly p² : 2pq : q² (36/48/16, p = 0.6): χ-square 0, F 0, χ-square p 1 (exact identity, abs 10⁻¹²)passed
p0.6 ± 6 × 10⁻¹³0.6lockedunder 0.01 % of the tolerance usedchi_square0 ± 10⁻¹²0lockedunder 0.01 % of the tolerance usedinbreeding_F0 ± 10⁻¹²0lockedunder 0.01 % of the tolerance usedchi_square_p1 ± 10⁻¹²1lockedunder 0.01 % of the tolerance usedhwe_ok= truetruelockedexact matchr0003only heterozygotes 0/4/0: F = -1, χ-square = N F² = 4, its p = erfc(√2) = 0.0455003, Levene-Haldane exact p = (3 + 8)/35 and excess p = 8/35 by hand enumeration of 3 tables (rel 10⁻⁹)passed
inbreeding_F-1 ± 10⁻¹²-1lockedunder 0.01 % of the tolerance usedchi_square4 ± 4 × 10⁻¹²4lockedunder 0.01 % of the tolerance usedchi_square_p0.0455003 ± 4.6 × 10⁻¹¹0.0455003lockedunder 0.01 % of the tolerance usedexact_p0.314286 ± 3.1 × 10⁻¹⁰0.314286lockedunder 0.01 % of the tolerance usedexact_p_het_excess0.228571 ± 2.3 × 10⁻¹⁰0.228571lockedunder 0.01 % of the tolerance usedexact_tables33lockedr0004three alleles in exact proportions (p = .5/.3/.2, N = 100: 25/30/9/20/12/4): χ-square 0, F 0, df 3, p₁ = 0.5 (exact identity)passed
allele_freq.A1= 0.5, within 1.000000 × 10⁻¹² relativereading not recorded on this pageallele_freq.A3= 0.2, within 1.000000 × 10⁻¹² relativereading not recorded on this pagechi_square0 ± 10⁻¹²0lockedunder 0.01 % of the tolerance usedinbreeding_F0 ± 10⁻¹²0lockedunder 0.01 % of the tolerance useddf33lockedr0005three alleles, N = 2 (A₁/A₂ + A₃/A₃): χ-square 4 and exact p = 1/3 by hand (two possible tables, probabilities 1/3 and 2/3), df 3 (rel 10⁻⁹)passed
chi_square4 ± 4 × 10⁻¹²4lockedunder 0.01 % of the tolerance usedexact_p0.333333 ± 3.3 × 10⁻¹⁰0.333333lockedunder 0.01 % of the tolerance usedexact_tables22lockeddf33lockedr0006recessive incidence 1/2500: q = √(0.0004) = 0.02, carriers 2pq = 0.0392 (textbook), 1 in 25.51 (closed form, rel 10⁻¹²)passed
q0.02 ± 2 × 10⁻¹⁴0.02lockedunder 0.01 % of the tolerance usedcarrier_frequency0.0392 ± 3.9 × 10⁻¹⁴0.0392lockedunder 0.01 % of the tolerance usedcarriers_one_in25.5102 ± 2.6 × 10⁻¹¹25.5102lockedunder 0.01 % of the tolerance usedr0007first-cousin F = 1/16, incidence (1-F)q² + Fq = 13/8000 built from q = 0.02: q recovered = 0.02, carriers 2pq(1-F) = 0.03675 (closed form, rel 10⁻¹²)passed
q0.02 ± 2 × 10⁻¹⁴0.02lockedunder 0.01 % of the tolerance usedcarrier_frequency0.03675 ± 3.7 × 10⁻¹⁴0.03675lockedunder 0.01 % of the tolerance usedr0008χ-square 1 df at its 0.95 quantile 3.841458820694124: p = erfc(√(x/2)) = 0.05 (closed form, rel 10⁻⁹)passed
chi_square_p0.05 ± 5 × 10⁻¹¹0.05lockedunder 0.01 % of the tolerance usedr0009χ-square 2 df at 5.991464547107979: p = exp(-x/2) = 0.05 (closed form, rel 10⁻⁹)passed
chi_square_p0.05 ± 5 × 10⁻¹¹0.05lockedunder 0.01 % of the tolerance usedr0010χ-square 4 df at 10: p = exp(-5)(1 + 5) = 0.0404277 (closed form, rel 10⁻⁹)passed
chi_square_p0.0404277 ± 4 × 10⁻¹¹0.0404277lockedunder 0.01 % of the tolerance used
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
mode | genotypes | genotypes: test counts for Hardy-Weinberg proportions; carrier: allele and carrier frequency from the incidence of a recessive condition; chi_square_p: upper tail of the χ-square distribution. | |
counts | 1 | Genotype counts in the order A1A1, A1A2, A2A2, A1A3, A2A3, A3A3, ...: k(k+1)/2 numbers for k alleles (2 to 12). Two alleles: [AA, AB, BB]. Give this or 'genotypes'. | |
genotypes | Genotype counts by name, e.g. {"M/M": 298, "M/N": 489, "N/N": 213}. Give this or 'counts'. | ||
alleles | Allele names (optional): fixes their order and lets absent alleles be listed. | ||
alpha | 1 | 0.05 | Significance level for the verdict. |
exact_method | auto | auto: enumerate every table if it fits the budget, else Monte Carlo; none: χ-square only. | |
mc_draws | 1 | 20000 | Random matings of the allele pool for the Monte Carlo exact test. |
seed | 1 | 1 | |
incidence | 1 | carrier mode: fraction of people affected by the recessive condition (1 in 2500 is 0.0004). | |
incidence_one_in | 1 | carrier mode: the same as 1 / incidence, e.g. 2500. | |
inbreeding_F | 1 | 0 | carrier mode: Wright's inbreeding coefficient of the population (0 random mating, 1/16 first-cousin children). |
chi_square | 1 | chi_square_p mode: the statistic. | |
df | 1 | 1 | chi_square_p mode: degrees of freedom. |
Readings
| Name | Unit | Meaning |
|---|---|---|
mode | genotypes, carrier or chi_square_p | |
n_individuals | 1 | |
n_alleles | 1 | |
allele_freq | ||
p | 1 | Frequency of the first allele (two alleles only). |
q | 1 | Frequency of the second allele (two alleles), or of the recessive allele (carrier mode). |
chi_square | 1 | |
df | 1 | |
chi_square_p | 1 | |
exact_p | 1 | Levene-Haldane exact test: sum of the probabilities of every genotype table no more probable than the observed one. |
exact_p_het_deficit | 1 | |
exact_p_het_excess | 1 | |
exact_p_se | 1 | |
exact_tables | 1 | |
exact_prob_sum | 1 | |
exact_mean_het_count | 1 | |
observed_het | 1 | |
expected_het | 1 | |
expected_het_unbiased | 1 | |
inbreeding_F | 1 | 1 - H_obs / H_exp (genotypes mode); the input F (carrier mode). |
min_expected_count | 1 | |
hwe_p | 1 | The p-value the verdict uses: exact when available, else χ-square. |
hwe_ok | true when hwe_p is at or above α (genotypes mode) | |
genotype_table | ||
allele_table | ||
incidence | 1 | |
carrier_frequency | 1 | 2pq(1-F): heterozygote carriers in the whole population. |
carriers_one_in | 1 | |
carrier_frequency_among_unaffected | 1 | |
carriers_per_affected | 1 |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.