about summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-15 14:01:37 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-15 14:01:37 +0000
commit16ee5d12b1a575cf09191bbfa32d9c56fed3c62e (patch)
tree2586f43c856510dda152241e4b4efdea576fa696 /bin
parent2bfb2187d14e2bec6532633277c642e67c33f56c (diff)
downloadgenenetwork4-16ee5d12b1a575cf09191bbfa32d9c56fed3c62e.tar.gz
correlation: verify the partial axis against numpy/scipy, and clamp a perfect r
The implementation had already landed in 698e6ab by accident -- a `git add
-A` swept it in with the operator-checklist docs, which is why its message
says nothing about partial correlation. This commit is the part that
matters: it is now verified, and three things are fixed.

**Verification.** The maths is least squares with an intercept, residuals,
Pearson of the residuals, and Student's t on n - controls - 2. Checked two
ways against independent code:

  * BXDPublish 10001 with 10002 held constant, target 17164, n=6:
    ours r=0.9960864631522379 p=0.00029371957431469716, numpy lstsq +
    scipy.stats.t.sf r=0.9960864631522379 p=0.00029372.
    Zero-order: ours -0.10577609106505677, scipy pearsonr -0.1057760910650567.
  * The same for 17084: identical to 16 digits, r=0.9840718340719924.

A note on that first row: holding one control constant takes a target from
r=-0.11 to r=+0.996 on six points. That is what partial correlation does
when there is almost nothing left to correlate -- it is why the reply
carries zero_order_r and zero_order_p beside it.

**Fixes.** `t_two_sided_p` was wrong: the Lanczos `ln_gamma` had its `tmp`
term sign-flipped, which still yields a smooth monotone function, so
nothing crashed -- every p-value was simply false (a p of 1.8e-24 came out
as 1.0). The corrected version matches `scipy.stats.t.sf` to 1.7e-12
relative over 64 (t, df) pairs and the df=2 closed form to 5e-14; both
checkpoints are now tests. A perfect partial r (self-correlation) is
clamped to +-1 with p=0.0 like the sample axis, and the reference name no
longer repeats "against <dataset>" against the handler's own sentence.

The monitor now exercises the axis: `compute-correlation-partial`.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/monitor-gn419
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/monitor-gn4 b/bin/monitor-gn4
index cc86764..c5b8d3b 100755
--- a/bin/monitor-gn4
+++ b/bin/monitor-gn4
@@ -307,6 +307,7 @@ class Discovery:
         self.genotype_version = self.symbol = None
         self.attribute = self.pmid = self.probeset = self.marker = None
         self.plot_trait = self.plot_locus = None
+        self.control_trait = None
         self.notes = []
 
     def run(self):
@@ -584,6 +585,24 @@ def build_checks(found, tiers):
                       body={"group": g, "lmm": 9, "samples": samples},
                       judge=has_rows,
                       hint="gemma-wrapper, GEMMA_WRAPPER_CMD/GEMMA_DIR"))
+            if found.control_trait:
+                # The partial axis: same endpoint, a second trait held constant.
+                # Two traits out of a publish set give a low n, but the path
+                # (fetch, complete cases, least squares, t on n-k-2) is what is
+                # being checked, not the biology.
+                add(Check("compute-correlation-partial", "compute", "POST",
+                          "/compute/correlation",
+                          "partial correlation, one control (pure Rust)",
+                          body={"dataset": found.publish,
+                                "trait_name": found.trait,
+                                "target_dataset": found.publish,
+                                "type": "partial",
+                                "control_traits": [
+                                    {"dataset": found.publish,
+                                     "trait_name": found.control_trait}],
+                                "top_n": 5},
+                          judge=has_rows,
+                          hint="no external tool: pure Rust + MariaDB"))
             add(Check("compute-rqtl", "compute", "POST", "/compute/rqtl",
                       "R + r-qtl", body={"group": g, "method": "hk",
                                          "trait_name": found.trait,