Skip to content

feat(differential): MN/DM through MGLM as a second backend (upstream #22) - #327

Merged
hyperpolymath merged 6 commits into
mainfrom
marina/eloquent-ritchie-p8kko8
Nov 12, 2026
Merged

hyperpolymath merged 6 commits into
mainfrom
marina/eloquent-ritchie-p8kko8

Conversation

@hyperpolymath

@hyperpolymath hyperpolymath commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Change and reason

Upstream ruled on JoshuaJewell/MetaManifold-WebUI#22 that multinomial (MN) and Dirichlet-multinomial (DM) regression come in as "MGLM through RCall, in line with CONTRIBUTING". This PR brings that route into the fork as a second backend, beside the fork's own Julia models.

  • New setting analysis.differential.mn_backend: julia (the default, CompositionalModels, unchanged) or mglm (MGLM::MGLMreg.fit through RCall).
  • The MGLM code (fit_mglm, its R script, MGLMUnavailable, the constants) is the same text as on the upstream branch, so a later sync finds identical code.
  • The shared steps are unchanged: prevalence filter, separation refusal, reference choice, and the rule that the reference must have reads in at least half the samples.
  • mglm refuses a non-zero mn_penalty and dm_overdispersion_method: mom, which it cannot honour. It does not use max_iter, tolerance or max_seconds. The config route and the cross-key check refuse the same combinations.
  • The multinomial is the same model in both backends. The Dirichlet-multinomials differ: MGLM's has a concentration per group, the Julia model has one. The docs say which one runs, and diagnostics.mglm.overdispersion reports each group.
  • When a DM group shows no overdispersion, its rows are boundary and keep their statistics. The note calls them the multinomial's estimates only when both groups are flat (fix in 4a39525, after an independent review).
  • docs/proposals/upstream-issue-22/ holds the upstream pull-request body and the comment for Add AnalysisConfig + validators + Nickel/DEED schemas + provenance + issues - Milestone 3  #22, for a person to post.

The upstream branch itself (one signed commit, 37c9ffa, on upstream main at 89be534) is not in this PR. Merging it here would also bring in the upstream commits this fork does not have yet, which is the separate sync in notes/upstream-sync.md.

Validation

Ubuntu 24.04, Julia 1.12.5, R 4.5.0 (apt 4.5.0-3.2404.0), the R library restored from renv.lock with renv::restore(), MGLM 0.2.3, bun 1.4.4.

  • After 4a39525: CI=true ... julia --project=. test/runtests.jl test_differential.jl gave 1864 of 1864 passed.
  • Before that fix, the full CI=true RENV_CONFIG_AUTOLOADER_ENABLED=FALSE julia --project=. -t 2 test/runtests.jl --server gave 8863 passed, 6 failed, 12 broken. The 6 failures are the test_provenance.jl live probes for cutadapt, fastqc, multiqc, vsearch, swarm and cd-hit, which that machine did not have; they are unrelated to this change. The fix touches only differential.jl and its tests.
  • The new tests check:
    • MGLM's multinomial equals the Julia fit (estimates to 1e-6, standard errors to a relative 1e-6, p and padj to a relative 1e-4) and the closed form (to 1e-8).
    • With mn_backend: mglm the route reproduces the Julia route test's numbers.
    • The per-group DM concentrations.
    • A table with one flat group is not called multinomial.
    • The config refusals, and that R's warn option is unchanged after a fit.
  • cd frontend && bun run test: 82 pass, 0 fail; tsc --noEmit clean.
  • Not run: --integration, and the frontend with the CI bun pin.

Scope

  • No change to the Julia backend or to the default.
  • renv.lock gains one entry, MGLM 0.2.3 (34 lines, nothing else changes). The mglm backend loads it. MGLM is pure R with base-R imports only, licensed GPL (>= 2) like zCompositions.
  • The upstream sync is not part of this PR.

Contribution checks

  • I followed CONTRIBUTING.md.
  • This branch starts at current upstream main and contains no merges from fork main. (Not applicable as written: this is a fork-main PR based on fork main 644cd9c, with no merge commits.)
  • CI has run and passes.
  • Existing licensing, citation and acknowledgement text is unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok

HoTT-stuff and others added 2 commits November 12, 2026 17:37
…LM as a second backend

analysis.differential.mn_backend selects who fits the two joint
compositional models: "julia" (the default, this fork's CompositionalModels)
or "mglm", MGLM::MGLMreg.fit through RCall, the route upstream ruled on
JoshuaJewell#22. The MGLM code (fit_mglm, its R script,
MGLMUnavailable and the constants) is the same as on the upstream branch, so
a later sync finds identical text.

- The shared steps stay as they are: prevalence filter, separation refusal,
  reference choice and the half-the-samples reference rule.
- mglm refuses a non-zero mn_penalty and dm_overdispersion_method mom, which
  it cannot honour, and does not use max_iter, tolerance or max_seconds. The
  config route and the cross-key check refuse the same combinations.
- The multinomial is one model in both backends; the tests check that MGLM
  reproduces the Julia fit (estimates to 1e-6, standard errors to a relative
  1e-6), the closed form, and the Julia route test's numbers. The
  Dirichlet-multinomials differ (MGLM has a concentration per group), so they
  are not compared; diagnostics.mglm.overdispersion reports each group.
- MGLM 0.2.3 is pinned in renv.lock and checked in CI; MGLMUnavailable is a
  503; the config editor, results panel, CSV line, README and ROADMAP name
  the backend.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
The pull-request body, in upstream's template, and the comment for issue #22,
for a person to post: the upstream repository is read-only from the session
that built the branch. The README says where the upstream branch is, what it
contains, and the order of sending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

HoTT-stuff and others added 4 commits November 12, 2026 17:54
…ps are flat

Review found that the mglm backend's boundary note and refusal said the
Dirichlet-multinomial estimates equal the multinomial ones whenever either
group showed no overdispersion. That holds only when both groups are flat:
with one group overdispersed the contrasts differ and the multinomial would
understate that group's variance. The note and the refusal now say which
group is flat, and point to multinomial only when both are. theta is now
computed in R, so an infinite concentration (theta = 0) is still flagged.
The shared MGLM code is re-copied from the upstream branch, which has the
same fix; a test covers the one-flat-group table.

The upstream package in docs/proposals/upstream-issue-22/ is updated to the
amended upstream commit and the new counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
The upstream branch exists only in the session that built it, and that
session may push to this fork's working branch alone. The patch applies with
git am onto upstream 89be534 and gives the same tree as the signed commit
37c9ffa; applied elsewhere it must be signed again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
…template

SonarCloud typescript:S4624 on the line this PR added to DifferentialPanel.
The output text is unchanged; tsc and the frontend tests pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
…T-stuff

Owner's order (2026-11-12): the comment on upstream #22 goes first and asks
whether Joshua still wants the change; the pull request follows only on a
yes. The comment now points at upstream/issue-22-mglm (37c9ffa, Verified,
0 commits behind upstream main) instead of a PR number. The commit is
submitted from the HoTT-stuff account, so the comment and the PR body each
carry a line for the owner to name who answers for the code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZoFbrtmpRbKPqk25ok
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 12, 2026 18:49
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-12T18:50:01.354922Z
We couldn’t complete this review. Comment @codex review to try again.
796406e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@hyperpolymath
hyperpolymath merged commit 48d7b43 into main Nov 12, 2026
21 checks passed
@hyperpolymath
hyperpolymath deleted the marina/eloquent-ritchie-p8kko8 branch November 12, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants