Repository navigation
Add resi_pe() for mgcv gam/bam fits - #58
Merged
Merged
Conversation
Smooth-term RESI from mgcv's Vp Wald statistic with Ref.df (f2S, or chisq2S when the scale is known); parametric terms via t2S/z2S; terms tested with mgcv's random-effect test (bs = 're', shrinkage, select = TRUE) return NA. resi() errors informatively (CIs not yet implemented). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonvandekar
added a commit
to simonvandekar/AIgams
that referenced
this pull request
Nov 19, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
resi_pe()point estimates formgcv::gamandmgcv::bamfits. Confidence intervals are not included yet.What it does
f2S(F, Ref.df, n - sum(edf), n)from mgcv'sVp-based Wald statistic, orchisq2Swhen the scale is known (e.g. binomial). This was chosen because mgcv's statistic uses a rank-Ref.dfpseudo-inverse, so its null mean is aboutRef.df, and the-df/ncorrection matches it.t2S/z2S.bs = "re", shrinkage bases,select = TRUE) returnNAwith a warning.resi()on a gam/bam stops with a message pointing toresi_pe(), since intervals aren't implemented.mgcvadded to Suggests,R/resi_pe_gam.Radded toCollate(otherwise an installed package omits the method), NEWS entry, regeneratedman/.Validation
tests/testthat/test-resi_pe_gam.R: 9 expectations pass; the full test suite passed on this branch.gamCalibrationSim/): the target is T2(k), the Wald noncentrality per observation of the fixed-basis projection (as for RESI under misspecification in other models). Scenarios include a threshold effect (truncation), a weak non-linear effect and heteroskedastic errors, with k in {5, 10, 20}. Null rejection rates are 0.03-0.06. Estimates are within 1% of T2(k) by n = 20000 (2% for the weak curve) and under 4% by n = 1000, except the weak curve, where REML often fits a straight line at small n (-36% at n = 200, -29% at 1000, -6% at 5000).insurance(AIgamstests/run_gam_insurance.R), including smoker x nonlinear age and smoker x bmi difference curves: real effects are within 2% by n = 1000 (smoker x bmi: -1% to -2% at n = 5000). The null term rejects at 0.044-0.068.Vp(parametric). mgcv'svcov.gam(sandwich = TRUE)was evaluated: it is consistent for the robust T2(k) and its SEs hold up under heteroskedasticity, whereVpSEs are 18-28% too small. Exposing it as an option is left for the CI work.Independent of #57: this branches from
masterand touches different files.