Registry Mirror
Skip to content

Conversation

@avehtari

Copy link
Copy Markdown
Member

#626 removes a linear term that is also an argument of a smooth term, such as x next to s(x). parse_additive_terms() should reject a named argument of s() or t2(), but its regex \(.+,.*=.+\) finds an = only after a comma. Thus s(by = g, x), s(k = 5, x), s(x = x1) and t2(k = 4, x, z) passed the check. With y ~ x + g + s(by = g, x), smooth_covered_terms() then returned x and g, and the projection removed the linear term g. A smooth term with by = g does not contain the main effect of g.

Changes

parse_additive_terms() parses each smooth term with str2lang() and calls the new helper has_named_smooth_arg(). The helper finds a named argument at any position in an s() or t2() call, also in a call inside it, such as s(poly(x, degree = 2)). The error message does not change. The PR adds a NEWS item.

This follows the review suggestion on #626 to keep only the unnamed arguments in smooth_args(). With only that filter, s(by = g, x) would pass the check, and the projection would keep the linear term x1 next to s(x = x1). The new check rejects both, so smooth_args() gets only unnamed arguments.

As before this PR, smooth terms inside an interaction, such as s(x, k = 5):z, go to the interaction terms and are not checked.

Tests

test_formula.R has a new test block. It checks the error for 8 term forms, no error for 4 smooth terms without named arguments, and extract_terms_response() for y ~ x + g + s(by = g, x). With the R/formula.R of master 6fef1de, 5 expectations fail: the 4 forms that passed the check, and extract_terms_response().

Full suite with NOT_CRAN=true on Triton: 60,084 expectations, 0 failed, 5 skipped, 19 warnings (CHOLMOD, generalized Pareto, Pareto k). The same warnings occur on master. Versions: R 4.5.3, testthat 3.3.2, lme4 2.0.6, mgcv 1.9.4, gamm4 0.3.0, brms 2.23.1, rstanarm 2.32.2.

This PR was assisted by Claude

@avehtari avehtari added the bug Bugs. label Nov 13, 2026
@avehtari
avehtari merged commit 105a309 into master Nov 15, 2026
5 checks passed
@avehtari
avehtari deleted the smooth-named-args branch November 15, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants