Conversation
avehtari
marked this pull request as draft
November 12, 2026 09:55
# Conflicts: # NEWS.md # tests/testthat/test_formula.R
avehtari
marked this pull request as ready for review
November 12, 2026 10:21
aloctavodia
reviewed
Nov 13, 2026
Comment on lines
+66
to
+69
| smooth_args <- function(smooth) { | ||
| cl <- str2lang(smooth) | ||
| return(unname(vapply(as.list(cl)[-1], deparse_combine, character(1)))) | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| smooth_args <- function(smooth) { | |
| cl <- str2lang(smooth) | |
| return(unname(vapply(as.list(cl)[-1], deparse_combine, character(1)))) | |
| } | |
| smooth_args <- function(smooth) { | |
| args <- as.list(str2lang(smooth))[-1] | |
| arg_nms <- names(args) | |
| if (is.null(arg_nms)) arg_nms <- rep("", length(args)) | |
| args <- args[arg_nms == ""] | |
| return(unname(vapply(args, deparse_combine, character(1)))) | |
| } |
Currently redundant, but more robust?
aloctavodia
approved these changes
Nov 13, 2026
This was referenced Nov 13, 2026
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
Fixes #150 and #384.
as.matrix.projection()for GAMs: Duplicated linear term #150: a submodel withxands(x)had both terms. With the default bases of mgcv,s(x)contains the linear term, so the coefficient ofxis not identifiable.as.matrix()showed this coefficient. The projection now dropsxfrom such a submodel, andproject()gives a message (optionprojpred.mssg_smooth_linearturns it off).formula.gamm4()added the variables of the smooth terms as linear terms to the reference model formula. For an rstanarm GAM, it did not. Now both formulas have only the terms of the model. The search candidates do not change, becausesplit_formula()adds these linear terms as candidates in both cases.Changes
proj_to_submodl()callsflatten_formula(duplicates = FALSE), which drops these linear terms. The helpersmooth_covered_terms()finds the linear terms that a smooth term contains; it parses the smooth call (the old regex stopped at the first)).formula.gamm4()adds only the group-level terms to the formula of thegampart.?project(argumentpredictor_terms) describes the drop.Notes
xand thens(x). The submodel of that size is now fitted ass(x), and its size counts a term that the fit does not use. In the mgcv check, the fitted values ofx + s(x)ands(x)differ by at most 1.8e-4 (REML), so the search order can change only in close cases.nterms_all(the number of terms of the reference model formula) of an rstanarm GAMM now has the same definition as for rstanarm GAMs and brms GAMMs. It feeds the warning about unstable full-model projections (Projection onto the full model for multilevel Gaussian models #323) and the "Could not suggest submodel size" warning ofsuggest_size(). For GAMs and GAMMs, this count is smaller than the largest search size, because the search also has the linear terms of the smooth variables.Tests
test_formula.R(no Stan fit):smooth_covered_terms(),flatten_formula(duplicates = FALSE)andformula.gamm4().test_project.R: for an rstanarm GAM, the projection ontoc("s.1", "s(s.1)")gives the message and the same fits and predictions as the projection onto"s(s.1)";"s.1"alone keeps the linear term.test_refmodel.R: the formulas of the rstanarm GAM and GAMM reference models have no linear term of a smooth variable.NOT_CRAN=true(R 4.5.3, lme4 2.0.6, gamm4 0.3.0, mgcv 1.9.4, rstanarm 2.32.2, brms 2.23.1): 58,560 expectations, 0 failures, 1 error in the newtest_project.Rtest. After the fix of this test, the three changed test files have 0 failures and 0 errors.This PR was assisted by Claude