Skip to content

A prior of its own for the ZINB zero-part random effects - #14

Merged
dwachsmuth merged 4 commits into
cma-rfxfrom
claude/zinb-zero-rfx-prior-3da03e
Nov 9, 2026
Merged

dwachsmuth merged 4 commits into
cma-rfxfrom
claude/zinb-zero-rfx-prior-3da03e

Conversation

@dwachsmuth

Copy link
Copy Markdown

What this does

bart() and bcf() take zero_random_effects_params, which sets the prior of the ZINB zero-part random effects separately from the count part's. It accepts the six prior keys of random_effects_params. Keys left out take the count part's values, so the default list() gives the same draws as before. Groups, basis (model_spec) and unseen_groups stay shared, and the list refuses them. A non-empty list without family = "zinb", group ids and zero_random_effects = TRUE is an error.

  • R only. .zinbZeroRfxPrior() (R/negbin.R) resolves the zero part's starting values and priors. They replace the count part's at every place the zero-part RandomEffectsModel is set up or reset: the initial set-up, GFR and root chain starts, and warm starts with and without previous samples. The C++ needed no change: the zero part already has its own model object, whose priors go through the existing setters. The count part's code is untouched.
  • Exact half-Cauchy mapping, documented in the roxygen. The effect is alpha * xi_k, with alpha ~ N(0, working_parameter_prior_cov), xi_k ~ N(0, s2) and s2 ~ IG(shape, scale) (1 / s2 ~ Gamma(shape, rate = scale)). Both conditionals have zero prior mean; the prior means are starting values only. With shape = scale = 1/2, |alpha| sqrt(s2) is half-Cauchy(0, sqrt(cov)) (Gelman 2006). For example, list(working_parameter_prior_cov = A^2, variance_prior_shape = 0.5, variance_prior_scale = 0.5) gives a half-Cauchy(0, A) prior on the intercept SD. The default (1, 1, cov 1) is half-t₂(0, 1), with prior median 0.82.

Tests (NOT_CRAN=true, installed scratch library, macOS arm64)

  • Full suite: 2,145 expectations in 202 tests (30 files): 0 failures, 0 errors, 2 skipped (test-api-combinations.R, "skipping slow tests"). The 13 warnings are upstream sampler notices (cloglog leaf scale, variance-forest σ², multivariate leaf).
  • New test-zinb-zero-rfx-prior.R: 88 expectations.
    • Bitwise against seeded references from a build of 1273f12 (fixtures/zinb-zero-rfx-prior-reference.rds, generator alongside): Gaussian, probit and NB bart() / bcf() with group ids, cloglog bart(), and default-prior ZINB bart() / bcf() with zero-part rfx (GFR and root chain starts, warm starts).
    • The count prior written out as the zero prior, in full or key by key, reproduces the default bitwise. That includes a non-default count prior inherited by the zero part.
    • A tight zero prior holds the zero part below 0.01 at every chain start while the count part stays free, and the reverse also holds.
    • Half-Cauchy scale against strong group effects: scale 0.001 holds a true SD of about 1, and 0.1 lets it through, as a heavy tail should.
    • JSON round trips and validation.
  • The existing zinb-rfx-reference.rds checks (ZINB without group ids, switch off, NB) still pass.

Applied check

Run on an internal applied panel (count BCF, 109 groups, 8 chains). With the old call, this branch reproduced an earlier cma-rfx fit draw for draw.

  • The intercept prior works. A half-Cauchy prior matched to a reference model's scale brought the zero-part intercept SD to the reference's level: 0.16 against 0.12 probit, previously 0.31.
  • Nothing else moved: the zero-part treatment effect, the count side and the gated R-hat (≤ 1.018) all stayed put. The sensitivity at half and twice the scale gave the same result.
  • Mixing cost. The zero-part SD mixes more slowly under a tight prior on the expanded working parameter: R-hat 1.09 and bulk ESS 66 against 1.07 and 160.

Details are in the internal notes.

🤖 Generated with Claude Code

dwachsmuth and others added 4 commits November 9, 2026 16:51
…m effects their own prior

Gaussian, probit and NB bart() / bcf() with group ids, cloglog bart(), and
default-prior ZINB bart() / bcf() with zero-part random effects (GFR and root
chain starts, warm starts), generated from a build of cma-rfx 1273f12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bart() and bcf() take zero_random_effects_params, with any of the six prior
keys of random_effects_params. Keys left out take the count part's values, so
the default list() keeps the shared prior draw for draw. The zero part's
starting values and priors are resolved by .zinbZeroRfxPrior() and used at
every place its RandomEffectsModel is set up or reset (initial set-up, GFR and
root chain starts, warm starts). The count part's code and the C++ sampler are
unchanged: the zero part already has its own model object.

Groups, basis and unseen-group policy stay shared and are refused here; a
non-empty list without family = 'zinb', group ids and zero_random_effects =
TRUE is an error. The roxygen documents the parameter expansion and the exact
half-Cauchy mapping (shape = scale = 1/2, working-parameter variance A^2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bitwise references for the unchanged paths; the count prior written out as the
zero prior reproduces the default draws; a tight zero prior holds the zero part
at every chain start while the count part stays free, and the reverse; a
half-Cauchy prior's scale against strong group effects; JSON round trips;
validation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dwachsmuth
dwachsmuth marked this pull request as ready for review November 9, 2026 16:03
@dwachsmuth
dwachsmuth merged commit 19f70ab into cma-rfx Nov 9, 2026
2 checks passed
@dwachsmuth
dwachsmuth deleted the claude/zinb-zero-rfx-prior-3da03e branch November 9, 2026 16:03
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.

1 participant