Repository navigation
Conversation
With reflect = TRUE, fit_hal and enumerate_basis build the basis on cbind(X, -X), without tensor products that pair a covariate with its own reflection, and predict augments new_data the same way. The basis is then the same set of functions when any covariate is negated, so the fit does not depend on the sign coding of the covariates. Default unchanged. Closes tlverse#117. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Closes #117.
Every HAL basis function switches on as a covariate increases, so negating a covariate changes the penalty and the fit (example in #117). This adds an opt-in
reflectargument tofit_hal()andenumerate_basis().What changes
enumerate_basis(..., reflect = TRUE)builds the basis oncbind(x, -x).basis_of_degree()andenumerate_edge_basis()get an internalreflected_fromargument, which drops tensor products that pair a covariate with its own reflection.fit_hal(..., reflect = TRUE)makes the design matrix fromcbind(X, -X), names the reflected columns-x1,-x2, ... (sosummary()reads, e.g.,I(-x1 >= -0.5)), and storesreflectin the fit.predict()augmentsnew_datathe same way.reflect = TRUEwithformulastops with an error.reflect = FALSE, is unchanged.The quantizer and the edge basis work column by column, so negating a covariate only swaps the two copies of it: the reflected basis is the same set of functions under any sign coding, with no change to
quantizer().Tests (
tests/testthat/test-reflect.R)thresh = 1e-12; observed 2e-5 to 3e-5).predict()on new data andsummary()work;formulawithreflect = TRUEerrors.Checks
devtools::test(): 52 passing, 0 failures.devtools::check(build_args = "--no-build-vignettes"): 0 errors, 4 warnings, 1 note, identical to master on the same machine (vignettes not built, Rcpp build version,halin tests, a lost brace informula_helpers.Rd).devtools::document()regenerated only the four affected Rd files; I leftRoxygenNoteat 7.3.1.Targets
master, sincedevelis contained in it; happy to retarget.🤖 Generated with Claude Code