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 chi-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 chi-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, chi-square = N F^2 = 0.221490 (textbook 0.222), df 1 (closed form, rel 1e-9)passed
p0.5425 ± 5.4e-130.5425lockedunder 0.01 % of the tolerance usedq0.4575 ± 4.6e-130.4575lockedunder 0.01 % of the tolerance usedgenotype_table.M/N.expected{"value": 496.3875, "rel_tol": 1e-12}chi_square0.22149 ± 2.2e-100.22149lockedunder 0.01 % of the tolerance usedinbreeding_F0.0148825 ± 1.5e-110.0148825lockedunder 0.01 % of the tolerance useddf11lockedr0002counts exactly p^2 : 2pq : q^2 (36/48/16, p = 0.6): chi-square 0, F 0, chi-square p 1 (exact identity, abs 1e-12)passed
p0.6 ± 6e-130.6lockedunder 0.01 % of the tolerance usedchi_square0 ± 1e-120lockedunder 0.01 % of the tolerance usedinbreeding_F0 ± 1e-120lockedunder 0.01 % of the tolerance usedchi_square_p1 ± 1e-121lockedunder 0.01 % of the tolerance usedhwe_ok= truetruelockedexact matchr0003only heterozygotes 0/4/0: F = -1, chi-square = N F^2 = 4, its p = erfc(sqrt 2) = 0.0455003, Levene-Haldane exact p = (3 + 8)/35 and excess p = 8/35 by hand enumeration of 3 tables (rel 1e-9)passed
inbreeding_F-1 ± 1e-12-1lockedunder 0.01 % of the tolerance usedchi_square4 ± 4e-124lockedunder 0.01 % of the tolerance usedchi_square_p0.0455003 ± 4.6e-110.0455003lockedunder 0.01 % of the tolerance usedexact_p0.314286 ± 3.1e-100.314286lockedunder 0.01 % of the tolerance usedexact_p_het_excess0.228571 ± 2.3e-100.228571lockedunder 0.01 % of the tolerance usedexact_tables33lockedr0004three alleles in exact proportions (p = .5/.3/.2, N = 100: 25/30/9/20/12/4): chi-square 0, F 0, df 3, p1 = 0.5 (exact identity)passed
allele_freq.A1{"value": 0.5, "rel_tol": 1e-12}allele_freq.A3{"value": 0.2, "rel_tol": 1e-12}chi_square0 ± 1e-120lockedunder 0.01 % of the tolerance usedinbreeding_F0 ± 1e-120lockedunder 0.01 % of the tolerance useddf33lockedr0005three alleles, N = 2 (A1/A2 + A3/A3): chi-square 4 and exact p = 1/3 by hand (two possible tables, probabilities 1/3 and 2/3), df 3 (rel 1e-9)passed
chi_square4 ± 4e-124lockedunder 0.01 % of the tolerance usedexact_p0.333333 ± 3.3e-100.333333lockedunder 0.01 % of the tolerance usedexact_tables22lockeddf33lockedr0006recessive incidence 1/2500: q = sqrt(0.0004) = 0.02, carriers 2pq = 0.0392 (textbook), 1 in 25.51 (closed form, rel 1e-12)passed
q0.02 ± 2e-140.02lockedunder 0.01 % of the tolerance usedcarrier_frequency0.0392 ± 3.9e-140.0392lockedunder 0.01 % of the tolerance usedcarriers_one_in25.5102 ± 2.6e-1125.5102lockedunder 0.01 % of the tolerance usedr0007first-cousin F = 1/16, incidence (1-F)q^2 + Fq = 13/8000 built from q = 0.02: q recovered = 0.02, carriers 2pq(1-F) = 0.03675 (closed form, rel 1e-12)passed
q0.02 ± 2e-140.02lockedunder 0.01 % of the tolerance usedcarrier_frequency0.03675 ± 3.7e-140.03675lockedunder 0.01 % of the tolerance usedr0008chi-square 1 df at its 0.95 quantile 3.841458820694124: p = erfc(sqrt(x/2)) = 0.05 (closed form, rel 1e-9)passed
chi_square_p0.05 ± 5e-110.05lockedunder 0.01 % of the tolerance usedr0009chi-square 2 df at 5.991464547107979: p = exp(-x/2) = 0.05 (closed form, rel 1e-9)passed
chi_square_p0.05 ± 5e-110.05lockedunder 0.01 % of the tolerance usedr0010chi-square 4 df at 10: p = exp(-5)(1 + 5) = 0.0404277 (closed form, rel 1e-9)passed
chi_square_p0.0404277 ± 4e-110.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 chi-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: chi-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 chi-square. |
hwe_ok | true when hwe_p is at or above alpha (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.