Skip to content

Test the multinomial functions against their binomial special case - #147

Merged
joethorley merged 3 commits into
mainfrom
multinom-binom-tests
Aug 26, 2026
Merged

Test the multinomial functions against their binomial special case#147
joethorley merged 3 commits into
mainfrom
multinom-binom-tests

Conversation

@joethorley

@joethorley joethorley commented Aug 25, 2026

Copy link
Copy Markdown
Member

Tests only. A two-category multinomial is a binomial, which gives an
independent check on three of the multinomial functions against the existing
*_binom() functions (previous checks were against dmultinom() and
glmnet).

  • log_lik_multinom(): the trial-summed log-likelihood equals
    log_lik_binom() on the first category.
  • dev_multinom(): trial-summed deviances equal dev_binom(), confirming the
    Poisson-form row offsets cancel within a trial; summed squared deviance
    residuals do too, and the first category's sign matches res_binom().
  • res_multinom(): the first category's "raw" and "standardized" residuals
    equal res_binom(), and the second category's standardized residual is its
    negative.
  • ran_multinom(): a seeded two-category call returns fixed values
    (repeatability only, no comparison to rbinom() or its distribution).

Test cases include the x = 0 and x = size boundaries, where the
Poisson-form deviance rows carry offsets the binomial form does not.

All four test files pass (175 tests, 1517 expectations, 0 failures). The new
code is air-clean; the three files that air format --check still flags were
already flagged at the base commit.

Targets multinom-references (#146), which targets add-multinom (#145).
Refs #62.

🤖 Generated with Claude Code

@joethorley
joethorley marked this pull request as ready for review August 25, 2026 09:29
@joethorley
joethorley requested a review from nehill197 as a code owner August 25, 2026 09:29
@joethorley
joethorley force-pushed the multinom-binom-tests branch from 5a589a2 to bd31b5d Compare August 25, 2026 09:30
@joethorley
joethorley force-pushed the multinom-binom-tests branch from bd31b5d to 8604573 Compare August 26, 2026 06:06
Base automatically changed from multinom-references to main August 26, 2026 06:07
joethorley and others added 3 commits August 26, 2026 07:07
A two-category multinomial is a binomial, which gives an independent
check on all four functions: trial-summed log-likelihoods match
log_lik_binom(), trial-summed deviances (and summed squared deviance
residuals) match dev_binom(), the standardized residual of the first
category matches res_binom() with the second its negative, and a
two-category draw is stream-identical to ran_binom() with binomial
marginal mean and variance.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Stream-identity to rbinom() relies on rmultinom() internals rather than a
documented guarantee. ran_multinom() now checks the first category's mean,
variance and count distribution against the binomial instead, and the
res_multinom() simulate check is dropped as redundant with it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Assert that a seeded two-category call returns fixed values rather than
checking the marginal distribution over 20,000 trials.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@joethorley
joethorley force-pushed the multinom-binom-tests branch from 8604573 to a932e22 Compare August 26, 2026 06:07
@joethorley
joethorley merged commit 68321ee into main Aug 26, 2026
9 checks passed
@joethorley
joethorley deleted the multinom-binom-tests branch August 26, 2026 06:07
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.

2 participants