Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor drop_trends handling #34

Closed
tsostarics opened this issue Sep 10, 2024 · 2 comments
Closed

refactor drop_trends handling #34

tsostarics opened this issue Sep 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@tsostarics
Copy link
Owner

tsostarics commented Sep 10, 2024

currently, warnings about dropped trends only comes up with set_contrasts. Something like enlist_contrasts(df, x ~ sum_code - 3:4) will just ignore the - operator at the level of use_contrasts.

I think this can be refactored entirely at the level of .make_parameters, specifically with .process_code_by by checking if params[['code_by']] is a polynomial scheme and if params[['drop_trends']] is not NA. If both are true, then the latter can be reset to NA and a warning can be issued, which will be present regardless of set/enlist/glimpse_contrasts. .reinstate_dropped_trends can then be removed entirely, omitting the regular expression wellformedness check.

@tsostarics tsostarics added the enhancement New feature or request label Sep 10, 2024
@tsostarics tsostarics added this to the CRAN submission milestone Sep 10, 2024
@tsostarics
Copy link
Owner Author

just a note but most of this can be put on .make_parameters, but there does need to be some way to check whether this is occurring within set_contrasts or not, otherwise set_contrasts(df, x ~ contr.poly - 3:5) will still work when it shouldn't

tsostarics added a commit that referenced this issue Sep 11, 2024
@tsostarics
Copy link
Owner Author

tsostarics commented Sep 11, 2024

This is implemented now, and .reinstate_dropped_trends has indeed been completely removed 🎉.

The implementation has set_contrasts set an attribute on the list of formulas, which is checked in enlist_contrasts. If present, .process_contrasts will ignore the - operator via the omit_drop parameter. The user can replicate this behavior by setting the omit_drop attribute themselves but by and large i doubt people would bother.

.make_parameters will handle the separate warning when the - operator is used with non-polynomial scheme functions. This already prevents the drop_trends parameter from being set to anything besides NA, so you don't get 2 warnings for things like set_contrasts(mtcars, carb ~ contr.sum - 4:6).

The one downside is that the user will get multiple warnings for every formula containing a - operator when used with a polynomial scheme in set_contrasts rather than a single warning listing all the problematic formulas. But, hopefully this drives home the point that this usage is not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant