Conversation
coef.pffr() gains `bias_ref`: given a second fit of the same model and data (typically REML for an NCV fit), each coefficient table gets a `delta` column (estimate difference through the same linear map as the SE) and pointwise z intervals use sqrt(se^2 + delta^2). New exported pffr_predict_ci() gives pointwise intervals for the linear predictor or conditional mean at fitted points or newdata, with sandwich/freq/cluster choices as in coef.pffr() and optional bias_ref; response-scale intervals transform the link-scale endpoints. The reference fit is checked for identical coefficient layout, model frame, weights, offsets, smooth bases, ffpc/pcre metadata, family and link. Tests reproduce the pffr-ci restart study's interval (NCV estimate, exact Bayesian CL2 SE, NCV-REML difference) for Gaussian and Poisson fits, delta = 0 for a fit as its own reference, seWithMean, missing dense and sparse responses, covariance passthrough, and rejections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JtmaCapnpxpQhDG2q2CQny
…st fixes - With `bias_ref`, coef.pffr() and pffr_predict_ci() default to the covariance the interval was evaluated with: sandwich = NULL -> "cl2", cl2_adjustment = NULL -> "exact" (Bayesian form via freq = FALSE). Explicit choices are respected; without bias_ref nothing changes. - Document the full functional intercept alpha(t): Intercept(yindex) is centred and the level sits in "(Intercept)"; pffr_predict_ci() at covariate values where all other terms vanish gives alpha(t) with its bias-aware interval (exact intercept rows; tested and in the example). - Document seWithMean for the bias-aware path: keep the default TRUE. It acts only on constrained terms (the intercept; ff() and varying coefficients are unconstrained by-variable smooths). In the pffr-ci study cells TRUE matched the exact full-intercept rows, FALSE undercovered alpha by 7-15 pp. - Add pffr-bias-aware.R to Collate (it was missing, so an installed build lacked pffr_predict_ci()). - test-pffr-ncv: the NCV covariance test no longer asserts mgcv's buggy Vc < Vp; it checks Vc != Vp and that refund returns Vp, under both unpatched and patched mgcv 1.9-5. - test-pffr-ar: the mgcv 1.9-5 skip helper called the nonexistent utils::package_version(); use base package_version(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JtmaCapnpxpQhDG2q2CQny
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Two moderate unresolved findings affect missing-response alignment and multi-predictor validation.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds bias-aware pointwise confidence intervals for pffr coefficients and predictions using an NCV–REML reference contrast.
Changes:
- Adds
bias_refsupport tocoef.pffr(). - Adds exported
pffr_predict_ci(). - Adds validation, covariance defaults, documentation, and tests.
- Updates related NCV and version-check tests.
| File | Summary |
|---|---|
tests/testthat/test-pffr-ncv.R |
Updates NCV covariance expectations. |
tests/testthat/test-pffr-bias-aware.R |
Adds bias-aware interval coverage. |
tests/testthat/test-pffr-ar.R |
Fixes package-version checking. |
R/pffr-methods.R |
Integrates bias-aware coefficient intervals. Moderate finding (2 votes): missing multi-linear-predictor validation. |
R/pffr-bias-aware.R |
Implements bias-aware calculations and prediction intervals. Moderate finding (1 vote): duplicate removal of missing-response rows. |
NEWS.md |
Documents the new functionality. |
NAMESPACE |
Exports pffr_predict_ci(). |
man/pffr_predict_ci.Rd |
Documents prediction intervals. |
man/pffr_bias_ref_difference.Rd |
Documents reference-fit validation. |
man/pffr_bias_aware_se.Rd |
Documents interval-width calculation. |
man/pffr_bias_aware_cov_defaults.Rd |
Documents covariance defaults. |
man/compute_coef_delta.Rd |
Documents coefficient-difference evaluation. |
man/coef.pffr.Rd |
Documents bias_ref support. |
man/coef_get_predictions.Rd |
Documents the extended helper interface. |
DESCRIPTION |
Adds the new source file to collation. |
Files not reviewed (7)
- man/coef.pffr.Rd: Generated file
- man/coef_get_predictions.Rd: Generated file
- man/compute_coef_delta.Rd: Generated file
- man/pffr_bias_aware_cov_defaults.Rd: Generated file
- man/pffr_bias_aware_se.Rd: Generated file
- man/pffr_bias_ref_difference.Rd: Generated file
- man/pffr_predict_ci.Rd: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1669
to
+1670
| if (!is.null(bias_ref)) { | ||
| if (raw) { |
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.

Adds bias-aware pointwise confidence intervals for pffr fits, the interval recipe evaluated in the pffr dependence study (NCV fit, exact CL2 sandwich, plus the NCV–REML difference as a bias allowance).
For a linear estimand L the interval is
on the link scale; response-scale intervals transform the endpoints. δ cannot see bias that both fits share.
API
The user passes both fits; refund never refits silently.
coef(fit_ncv, bias_ref = fit_reml): every coefficient table gets adeltacolumn, and pointwise intervals (crit = "z") use z·sqrt(se² + δ²).pffr_predict_ci(fit_ncv, newdata, bias_ref = fit_reml, type = "link" | "response"): pointwise intervals for the linear predictor or the conditional mean.bias_ref, both default tosandwich = "cl2", cl2_adjustment = "exact"(Bayesian form). Explicit arguments are respected, and nothing changes withoutbias_ref.raw = TRUE, simultaneous bands andcrit != "z"are rejected whenbias_refis given.seWithMean = TRUE(the default) is the recommended setting. It only affects terms with a centring constraint (in pffr, the functional intercept). In a paired comparison on the study's cells it gave clearly better intercept coverage and interval scores thanFALSE.Intercept(yindex)fromcoef()is mean-centred).Checks
test-pffr-bias-aware.R: 10 tests, 104 expectations, 0 failures.test-pffr-ncv.Rno longer assumes mgcv's NCVVcis smaller thanVp; that only held under an mgcv bug. It passes with patched and unpatched mgcv 1.9-5.test-pffr-ar.Rused a nonexistentutils::package_version.R/pffr-bias-aware.Ris added toCollate.R CMD checkare running separately; the results will be posted here.🤖 Generated with Claude Code
https://claude.ai/code/session_01JtmaCapnpxpQhDG2q2CQny