Added adj.r.squared and npar as outputs of glance.gam for mgcv::gam#1172
Merged
simonpcouch merged 4 commits intotidymodels:mainfrom Sep 6, 2023
Merged
Added adj.r.squared and npar as outputs of glance.gam for mgcv::gam#1172simonpcouch merged 4 commits intotidymodels:mainfrom
simonpcouch merged 4 commits intotidymodels:mainfrom
Conversation
Collaborator
|
Thanks for the PR! This looks solid. Wanted to make sure we wouldn't be increasing the time-to-tidy too drastically by introducing the additional library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.9-0. For overview type 'help("mgcv-package")'.
library(broom)
set.seed(2) ## simulate some data...
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
#> Gu & Wahba 4 term additive model
b <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat)
bench::mark(
gam = gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat),
tidy = tidy(b),
summary = summary(b),
check = FALSE,
relative = TRUE
)
#> # A tibble: 3 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 gam 36.1 36.1 1 34.9 1
#> 2 tidy 4.62 4.57 7.78 32.8 2.78
#> 3 summary 1 1 35.8 1 2.67Created on 2023-09-06 with reprex v2.0.2 Pushing some small changes before merging. |
|
This pull request has been automatically locked. If you believe the issue addressed here persists, please file a new PR (with a reprex: https://reprex.tidyverse.org) and link to this one. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
When using glance.gam for mgcv::gam, I was unpleasantly surprised to not find any results for adjusted R squared. This is one of the most important model evaluation statistics for statistical inference. Not only my colleagues and I, but also probably most other users of glance.gam would need this.
On examining the code, it seems that the only outputs provided by the current glance method are those directly available from the gam model object. But summary.gam provides some additional valuable outputs. So, I have modified the code to calculate the summary(x) on the model object (x) and then add in the other useful outputs (at least, those, that output a scalar numeric output.
That said, when examining modeltests::column_glossary, I could not find most of the additional outputs. So, I have added the only two outputs available in the modeltests::column_glossary (adj.r.squared and npar); for the other outputs, I have listed them in the code but commented them out--that way, if they are supported in the future in modeltests::column_glossary, the code can more easily be updated.
I have tested the updates with the unit tests in tests/testthat/test-mgcv.R; my modifications pass the tests. I hope you can accept this pull request.