about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/bulklmm.md55
1 files changed, 55 insertions, 0 deletions
diff --git a/docs/bulklmm.md b/docs/bulklmm.md
index fbb3b37..21e7f48 100644
--- a/docs/bulklmm.md
+++ b/docs/bulklmm.md
@@ -58,6 +58,61 @@ the engine agrees with the record — and the peak clears the α = 0.01 threshol
   lod, L_perms)`; `SE` is not among them, so the reply's `se` column does not
   exist and the rows are `marker, chr, pos, lod, beta, h2`.
 
+## When the two engines' h2 disagree, and what settles it
+
+Reported from a real analysis (BXD.8, 35 phenotyped animals):
+
+| trait | BulkLMM h2 | GEMMA `l_mle` | reading |
+|---|---|---|---|
+| 16769 | 1.000, σ²_e = 0 | at the upper clamp on every marker except the chr2 peak | both say kinship dominates; the peak's drop is the marker absorbing the effect |
+| 16627 | 0.000, σ²_e = 0.402 | at the upper clamp everywhere, peak included | a genuine disagreement |
+
+Both estimates sit on a boundary, which is expected at n = 35 — the likelihood
+is flat there — so neither number is a precise proportion. But *opposite*
+boundaries on the same phenotype and the same genotypes means the two engines
+are estimating different things, and it is worth knowing which:
+
+1. **Different kinship matrices.** GEMMA computes its own relatedness from the
+   BIMBAM dosages (and, in LOCO mode, one per chromosome); BulkLMM's
+   `calcKinship` is `2·(X−0.5)(X−0.5)ᵀ/p + 0.5` with a unit diagonal. Two
+   matrices, two variance components — not comparable until their correlation is
+   known.
+2. **Different encodings.** GEMMA gets `0 / 0.5 / 1` dosages with `NA` for
+   missing; BulkLMM gets the same dosages with missing values mean-imputed per
+   marker, and R/qtl's `convert2riself` (two of three codes) is a third.
+   Trait 16627 is nearly determined by the chr2 genotype (B above 1.0, D below
+   0.6), so the residual variance differs a lot between those encodings.
+3. **Different variance-component step.** BulkLMM estimates once under the null
+   with `assumption = "null"` (and REML or ML); GEMMA optimises per chromosome
+   under LOCO. On a boundary both optimisers clamp, and they clamp to different
+   conventions.
+
+**What would settle it, in order of cost:**
+
+* **GEMMA's own variance components.** GEMMA prints `pve estimate` and
+  `se(pve)` in its `.log.txt` when it is run with `-pve`, and gemma-wrapper keeps
+  the per-chromosome logs under its cache directory (223 `.log.txt` files here,
+  **none** containing `pve` — the flag is not passed). The change is one
+  argument on the GWA step and a parser over those logs; then `/compute/gemma`
+  can report pve per chromosome, as `/compute/bulklmm` reports h2.
+* **BulkLMM's likelihood over an h2 grid.** The package has
+  `BulkLMM.profile_LL(y::Matrix, G, covar, K, h2_grid, markerID; reml)` (internal,
+  not exported), returning `(ll_list_null, ll_list_alt)` over the grid. It wants
+  the phenotype as a one-column matrix and a covariate matrix (an all-zero column
+  is what `scan` uses with no covariates). Printing that profile at the peak
+  marker says whether an h2 of 0.000 is the maximum or the flat edge of one — the
+  difference between "no heritability" and "the estimator cannot tell".
+* **The kinship matrices, or a summary.** BulkLMM's `calcKinship(g)` is one line
+  and can be written out per panel; GEMMA's is already cached as a `-gk`
+  `*.k.json`. Correlating their off-diagonals (or reporting min/median/max) is
+  enough to say whether the two engines disagree about *relatedness* before
+  arguing about what the variance components mean.
+
+Until then, the honest reading is the one the analysis reached: BulkLMM's `h2`
+and the thresholds that depend on it are approximate where `h2` is on a
+boundary, and GEMMA's p-values for 16627 come from a kinship-dominated model —
+its peak should not be compared with a fixed-effects LOD.
+
 ## Cores: `scan()` is serial by design
 
 This was measured, not assumed. `Threads.@threads` appears in `bulkscan.jl` and