Test Poisson/binomial NCV against fixed-penalty curve deletion - #129
Merged
Merged
Conversation
For non-Gaussian families mgcv approximates each deletion refit by a Newton step, so the existing Gaussian brute-force test did not cover them. The new test refits by penalized IRLS with each curve left out at the fitted penalties and compares both the NCV loss (1%) and mgcv's deletion predictions (0.03 on the link scale; observed 0.013 / 0.0014). The prediction check fails if deletion ignores the curve blocks, which the loss alone does not detect for binary data. Penalty assembly moves into the helper and is shared with the Gaussian test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The reviewed tests cover the added Poisson and binomial NCV paths with no unresolved issues.
Review effort: Lite
Findings: None
What changed in this PR
Adds Poisson and binomial NCV regression tests against curve-deleted penalized IRLS refits.
Changes:
- Adds GLM fixtures and PIRLS helpers.
- Validates NCV loss and link-scale predictions.
- Shares penalty-matrix construction with Gaussian tests.
| File | Description |
|---|---|
tests/testthat/test-pffr-ncv.R |
Adds non-Gaussian NCV validation. |
tests/testthat/helper-pffr-ncv.R |
Provides shared data, penalty, and PIRLS helpers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
The NCV tests checked mgcv's criterion against brute-force leave-one-curve-out refits only for Gaussian fits, where the deletion is exact. For Poisson and binomial, mgcv replaces each deletion refit with a Newton step from the full fit (
?mgcv::NCV), and nothing covered that path.The new test fits both families with curve-blocked NCV. At the fitted penalties it then refits by penalized IRLS with each curve left out, and checks:
attr(gcv.ubre, "eta.cv")) are within 0.03 on the link scale.Observed on the test data, mgcv 1.9-5:
Why the prediction check is needed: for binary data, point-deletion loss is only 0.2–1% away from curve-deletion loss, so the loss check alone cannot detect deletion that ignores the curve blocks. Feeding the test point-deletion refits instead makes the prediction check fail for both families (0.47 and 0.19 against 0.03).
Refactor: the penalty-matrix assembly that was inline in the Gaussian test moves to
helper-pffr-ncv.Rand is shared by both tests. There are no package code changes.Test plan
tests/testthat/test-pffr-ncv.Rpasses locally (mgcv 1.9-5,NOT_CRAN=true)🤖 Generated with Claude Code