Test the multinomial functions against their binomial special case - #147
Merged
Conversation
joethorley
marked this pull request as ready for review
August 25, 2026 09:29
joethorley
force-pushed
the
multinom-binom-tests
branch
from
August 25, 2026 09:30
5a589a2 to
bd31b5d
Compare
nehill197
approved these changes
Aug 25, 2026
joethorley
force-pushed
the
multinom-binom-tests
branch
from
August 26, 2026 06:06
bd31b5d to
8604573
Compare
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
force-pushed
the
multinom-binom-tests
branch
from
August 26, 2026 06:07
8604573 to
a932e22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 againstdmultinom()andglmnet).log_lik_multinom(): the trial-summed log-likelihood equalslog_lik_binom()on the first category.dev_multinom(): trial-summed deviances equaldev_binom(), confirming thePoisson-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"residualsequal
res_binom(), and the second category's standardized residual is itsnegative.
ran_multinom(): a seeded two-category call returns fixed values(repeatability only, no comparison to
rbinom()or its distribution).Test cases include the
x = 0andx = sizeboundaries, where thePoisson-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 thatair format --checkstill flags werealready flagged at the base commit.
Targets
multinom-references(#146), which targetsadd-multinom(#145).Refs #62.
🤖 Generated with Claude Code