Invntr
Source

All instruments

ld_stats

Linkage disequilibrium between two biallelic loci (A/a, B/b) from phased haplotype counts, or from unphased 3x3 genotype counts by EM gene counting: haplotype frequencies, D, Lewontin's D', r, r^2, chi-square (1 df) with its tail probability, and the decay D_t = D_0 (1 - c)^t of D, D' and r^2 under random mating with recombination fraction c.

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

Admission replayld_stats 0.1.0 · files 23273ba25f05…0f45
  1. r0001closed form, independence: counts equal n pA pB (pA=0.6, pB=0.3, n=1000) give D = 0, D' = 0, r^2 = 0, chi-square = 0, p = 1 (exact up to rounding, abs 1e-12)passed

    D0 ± 1e-126.93889e-18lockedunder 0.01 % of the tolerance used
    D_prime0 ± 1e-125.78241e-17lockedunder 0.01 % of the tolerance used
    r20 ± 1e-129.55322e-34lockedunder 0.01 % of the tolerance used
    chi_square0 ± 1e-099.55322e-31lockedunder 0.01 % of the tolerance used
    p_value1 ± 1e-091lockedunder 0.01 % of the tolerance used
    p_A0.6 ± 6e-130.6lockedunder 0.01 % of the tolerance used
    p_B0.3 ± 3e-130.3lockedunder 0.01 % of the tolerance used
  2. r0002closed form, complete LD: only AB (40) and ab (60) give D' = 1, r^2 = 1, D = pAB - pA pB = 0.4 - 0.16 = 0.24, chi-square = n r^2 = 100 (rel 1e-9)passed

    D0.24 ± 2.4e-100.24lockedunder 0.01 % of the tolerance used
    D_prime1 ± 1e-091lockedunder 0.01 % of the tolerance used
    r21 ± 1e-091lockedunder 0.01 % of the tolerance used
    r1 ± 1e-091lockedunder 0.01 % of the tolerance used
    chi_square100 ± 1e-07100lockedunder 0.01 % of the tolerance used
  3. r0003closed form (30,20,10,40): D = 0.3 - 0.5*0.4 = 0.1, D' = 0.1/min(0.3,0.2) = 0.5, r^2 = 0.01/0.06 = 1/6, chi-square = 100/6, decay c=0.1 t=10: D_t = 0.1*0.9^10, half-life ln2/-ln0.9 = 6.5788134790 (rel 1e-9)passed

    D0.1 ± 1e-100.1lockedunder 0.01 % of the tolerance used
    D_prime0.5 ± 5e-100.5lockedunder 0.01 % of the tolerance used
    r20.166667 ± 1.7e-100.166667lockedunder 0.01 % of the tolerance used
    chi_square16.6667 ± 1.7e-0816.6667lockedunder 0.01 % of the tolerance used
    D_after0.0348678 ± 3.5e-110.0348678lockedunder 0.01 % of the tolerance used
    D_prime_after0.174339 ± 1.7e-100.174339lockedunder 0.01 % of the tolerance used
    r2_after0.0202628 ± 2e-110.0202628lockedunder 0.01 % of the tolerance used
    half_life_generations6.57881 ± 6.6e-096.57881lockedunder 0.01 % of the tolerance used
    generations_to_r2_threshold5.71359 ± 5.7e-095.71359lockedunder 0.01 % of the tolerance used
  4. r0004textbook chi-square(1) 95% point 3.841458820694 gives p = 0.05: counts 0.3n,0.2n,0.1n,0.4n with n = 6 x 3.841458820694 so chi2 = n/6 (rel 1e-6, erfc series)passed

    chi_square3.84146 ± 3.8e-093.84146lockedunder 0.01 % of the tolerance used
    p_value0.05 ± 5e-080.05lockedunder 0.01 % of the tolerance used
  5. r0005exact gene counting, EM on phase-unambiguous genotypes (no Aa Bb): returns the true haplotype counts AB 28, Ab 12, aB 7, ab 23 of 70 chromosomes, D = (28*23 - 12*7)/70^2 = 560/4900 (rel 1e-12)passed

    count_AB28 ± 2.8e-1128lockedunder 0.01 % of the tolerance used
    count_Ab12 ± 1.2e-1112lockedunder 0.01 % of the tolerance used
    count_aB7 ± 7e-127lockedunder 0.01 % of the tolerance used
    count_ab23 ± 2.3e-1123lockedunder 0.01 % of the tolerance used
    n_haplotypes70 ± 7e-1170lockedunder 0.01 % of the tolerance used
    D0.114286 ± 1.1e-100.114286lockedunder 0.01 % of the tolerance used
  6. r0006MLE at exact expectation: HWE genotype counts from haplotypes (0.4,0.1,0.1,0.4), N=10000, are a fixed point of EM, so EM returns them: D = 0.15, D' = 0.6, r^2 = 0.36, cis fraction 0.16/0.17 (rel 1e-8, EM tolerance 1e-13)passed

    p_AB0.4 ± 4e-090.4lockedunder 0.01 % of the tolerance used
    p_Ab0.1 ± 1e-090.1lockedunder 0.01 % of the tolerance used
    D0.15 ± 1.5e-090.15lockedunder 0.01 % of the tolerance used
    D_prime0.6 ± 6e-090.6lockedunder 0.01 % of the tolerance used
    r20.36 ± 3.6e-090.36lockedunder 0.01 % of the tolerance used
    double_het_cis_fraction0.941176 ± 9.4e-090.941176lockedunder 0.01 % of the tolerance used
    em_converged= truetruelockedexact match
6 of 6 cases passed · sandbox macos-seatbeltrecorded from the kernel in a fresh lab

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

NameUnitDefaultMeaning
n_AB1Phased data: chromosomes carrying haplotype AB. Give all four haplotype counts, or genotype_counts instead.
n_Ab1Phased data: chromosomes carrying haplotype Ab.
n_aB1Phased data: chromosomes carrying haplotype aB.
n_ab1Phased data: chromosomes carrying haplotype ab.
genotype_counts1Unphased data: 3x3 counts of individuals, rows AA, Aa, aa and columns BB, Bb, bb. Haplotype frequencies are the maximum-likelihood ones under random union of gametes (EM over the phase of the double heterozygotes Aa Bb).
recomb_rate10.01Recombination fraction c between the loci, per generation (0.5 = unlinked; about 0.01 per cM for short distances).
generations1100Generations of random mating for the decay of D (whole number).
r2_threshold10.2r^2 level for 'generations to decay to threshold'.
alpha10.05Significance level for the chi-square test of D = 0.
em_tol11e-13EM stops when a step changes the haplotype frequencies by less than this.
em_max_iter1100000EM iteration cap per start.

Readings

NameUnitMeaning
modehaplotypes (counts given) or genotypes_em (estimated from genotype counts)
n_haplotypes1number of chromosomes (2 x individuals in genotype mode)
count_AB1
count_Ab1
count_aB1
count_ab1
p_AB1
p_Ab1
p_aB1
p_ab1
p_A1
p_B1
D1p_AB p_ab - p_Ab p_aB = p_AB - p_A p_B
D_max1
D_prime1Lewontin's D / D_max, signed; null when a locus is monomorphic
D_prime_abs1
r1
r21D^2 / (p_A q_A p_B q_B)
chi_square1n r^2, one degree of freedom
p_value1erfc(sqrt(chi_square / 2))
alpha1
ld_significantp_value < alpha
min_expected_count1
recomb_rate1
generations1
decay_factor1(1 - c)^t
D_after1
D_prime_after1
r2_after1
half_life_generations1generations for D to halve: ln 2 / -ln(1 - c)
r2_threshold1
generations_to_r2_threshold1generations until r^2 falls to r2_threshold (fractional)
haplotypes
decay_table
n_individuals1
n_double_het1
double_het_cis_fraction1
em_iterations1
em_convergedEM met em_tol
em_optima1
log_likelihood1
warningslist of text

Try the call

Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.

Terminal
MCP call