Debian Codegraph @

R/leaps.R

raw
1 #' @templateVar class regsubsets
2 #' @template title_desc_tidy
3 #'
4 #' @param x A `regsubsets` object created by [leaps::regsubsets()].
5 #' @template param_unused_dots
6 #'
7 # # define the documentation manually since r-squared and BIC are unusual
8 # # elements of a tidy method output
9 #' @evalRd return_tidy(
10 #' r.squared = "R squared statistic, or the percent of variation explained by the model.",
11 #' adj.r.squared = "Adjusted R squared statistic",
12 #' BIC = "Bayesian information criterion for the component.",
13 #' mallows_cp = "Mallow's Cp statistic."
14 #' )
15 #'
16 #' @examplesIf rlang::is_installed("leaps")
17 #'
18 #' # load libraries for models and data
19 #' library(leaps)
20 #'
21 #' # fit model
22 #' all_fits <- regsubsets(hp ~ ., mtcars)
23 #'
24 #' # summarize model fit with tidiers
25 #' tidy(all_fits)
26 #'
27 #' @aliases leaps_tidiers
28 #' @export
29 #' @seealso [tidy()], [leaps::regsubsets()]
30 tidy.regsubsets <- function(x, ...) {
31 s <- summary(x)
32 inclusions <- as_tibble(s$which)
33 metrics <- with(
34 s,
35 tibble(
36 r.squared = rsq,
37 adj.r.squared = adjr2,
38 BIC = bic,
39 mallows_cp = cp
40 )
41 )
42 bind_cols(inclusions, metrics)
43 }