Skip to content

Commit

Permalink
Added adj.r.squared and npar as outputs of glance.gam for mgcv::gam (#…
Browse files Browse the repository at this point in the history
…1172)

* Added adj.r.squared and npar as outputs of glance.gam for mgcv::gam

* remove commented out `glance()` entries

* add NEWS entry

* re`document()`

---------

Co-authored-by: simonpcouch <simonpatrickcouch@gmail.com>
  • Loading branch information
tripartio and simonpcouch committed Sep 6, 2023
1 parent dccaa3d commit cc679ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Moved forward with deprecation of tidiers for objects from the sp package. See resources linked in [tidymodels/broom#1142](https://github.com/tidymodels/broom/issues/1142) for more information on migration from retiring spatial packages.

* Added support for columns `adj.r.squared` and `npar` in `glance()` method for objects outputted from `mgcv::gam()` (#1172).

# broom 1.0.5

* `tidy.coxph()` will now pass its ellipses `...` to `summary()` internally (#1151 by `@ste-tuf`).
Expand Down
14 changes: 10 additions & 4 deletions R/mgcv-tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ tidy.gam <- function(x, parametric = FALSE, conf.int = FALSE,
class(sx) <- c("anova", "data.frame")
ret <- tidy(sx)
}

if (exponentiate && parametric) {
ret <- exponentiate(ret)
}

ret
}

Expand All @@ -94,14 +94,18 @@ tidy.gam <- function(x, parametric = FALSE, conf.int = FALSE,
#' "BIC",
#' "deviance",
#' "df.residual",
#' "nobs"
#' "nobs",
#' "adj.r.squared",
#' "npar"
#' )
#'
#'
#' @export
#' @family mgcv tidiers
#' @seealso [glance()], [mgcv::gam()]
glance.gam <- function(x, ...) {
s <- summary(x)

as_glance_tibble(
df = sum(x$edf),
logLik = as.numeric(stats::logLik(x)),
Expand All @@ -110,7 +114,9 @@ glance.gam <- function(x, ...) {
deviance = stats::deviance(x),
df.residual = stats::df.residual(x),
nobs = stats::nobs(x),
na_types = "irrrrii"
adj.r.squared = s$r.sq,
npar = s$np,
na_types = "irrrriiri"
)
}

Expand Down
2 changes: 2 additions & 0 deletions man/glance.gam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc679ed

Please sign in to comment.