Skip to content

Test Poisson/binomial NCV against fixed-penalty curve deletion - #129

Merged
fabian-s merged 1 commit into
pffr-refactorfrom
ncv-glm-deletion-test
Sep 25, 2026
Merged

fabian-s merged 1 commit into
pffr-refactorfrom
ncv-glm-deletion-test

Conversation

@fabian-s

Copy link
Copy Markdown
Member

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:

  • the hand IRLS reproduces the full-data coefficients (tolerance 1e-7), which confirms the penalty scaling;
  • the NCV loss (sum of deviances) is within 1% of the brute-force loss;
  • mgcv's deletion predictions (attr(gcv.ubre, "eta.cv")) are within 0.03 on the link scale.

Observed on the test data, mgcv 1.9-5:

family loss error max prediction error
Poisson 0.18% 0.013
binomial < 0.01% 0.0014

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.R and is shared by both tests. There are no package code changes.

Test plan

  • tests/testthat/test-pffr-ncv.R passes locally (mgcv 1.9-5, NOT_CRAN=true)
  • mutation check: point-deletion refits fail the new assertions for both families

🤖 Generated with Claude Code

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>
Copilot AI lite review requested due to automatic review settings September 25, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fabian-s
fabian-s merged commit d59cced into pffr-refactor Sep 25, 2026
1 check passed
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