Skip to content

Commit a5436be

Browse files
topepohfrick
andauthored
updated GAM documentation (#524)
* updated GAM documentation * better description of the select_features parameter * Update man/rmd/gen_additive_mod_mgcv.Rmd Co-authored-by: Hannah Frick <hfrick@users.noreply.github.com> * more wordsmithing Co-authored-by: Hannah Frick <hfrick@users.noreply.github.com>
1 parent 0f235f5 commit a5436be

File tree

7 files changed

+243
-115
lines changed

7 files changed

+243
-115
lines changed

R/gen_additive_mod.R

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,40 @@
1-
# gen_additive_mod() - General Interface to Linear GAM Models
2-
# - backend: gam
3-
# - prediction:
4-
# - mode = "regression" (default) uses
5-
# - mode = "classification"
6-
71
#' Generalized additive models (GAMs)
82
#'
3+
#' @description
94
#' `gen_additive_mod()` defines a model that can use smoothed functions of
105
#' numeric predictors in a generalized linear model.
116
#'
127
#' There are different ways to fit this model. See the engine-specific pages
138
#' for more details
149
#'
15-
#' More information on how `parsnip` is used for modeling is at
16-
#' \url{https://www.tidymodels.org}.
17-
#'
18-
#' @inheritParams boost_tree
19-
#' @param select_features TRUE or FALSE. If this is TRUE then can add an
20-
#' extra penalty to each term so that it can be penalized to zero.
21-
#' This means that the smoothing parameter estimation that is part of
22-
#' fitting can completely remove terms from the model. If the corresponding
23-
#' smoothing parameter is estimated as zero then the extra penalty has no effect.
24-
#' Use `adjust_deg_free` to increase level of penalization.
25-
#' @param adjust_deg_free If `select_features = TRUE`, then acts as a multiplier for smoothness.
26-
#' Increase this beyond 1 to produce smoother models.
27-
#'
28-
#'
29-
#' @return
30-
#' A `parsnip` model specification
31-
#'
32-
#' @details
33-
#'
34-
#' This function only defines what _type_ of model is being fit. Once an engine
35-
#' is specified, the _method_ to fit the model is also defined.
36-
#'
37-
#' The model is not trained or fit until the [fit.model_spec()] function is used
38-
#' with the data.
10+
#' \Sexpr[stage=render,results=rd]{parsnip:::make_engine_list("gen_additive_mod")}
3911
#'
40-
#' __gam__
12+
#' More information on how \pkg{parsnip} is used for modeling is at
13+
#' \url{https://www.tidymodels.org/}.
4114
#'
42-
#' This engine uses [mgcv::gam()] and has the following parameters,
43-
#' which can be modified through the [set_engine()] function.
44-
#'
45-
#' ``` {r echo=F}
46-
#' str(mgcv::gam)
47-
#' ```
48-
#'
49-
#' @section Fit Details:
50-
#'
51-
#' __MGCV Formula Interface__
52-
#'
53-
#' Fitting GAMs is accomplished using parameters including:
15+
#' @inheritParams boost_tree
16+
#' @param select_features `TRUE` or `FALSE.` If `TRUE`, the model has the
17+
#' ability to eliminate a predictor (via penalization). Increasing
18+
#' `adjust_deg_free` will increase the likelihood of removing predictors.
19+
#' @param adjust_deg_free If `select_features = TRUE`, then acts as a multiplier
20+
#' for smoothness. Increase this beyond 1 to produce smoother models.
5421
#'
55-
#' - [mgcv::s()]: GAM spline smooths
56-
#' - [mgcv::te()]: GAM tensor product smooths
22+
#' @template spec-details
5723
#'
58-
#' These are applied in the `fit()` function:
24+
#' @template spec-references
5925
#'
60-
#' ``` r
61-
#' fit(value ~ s(date_mon, k = 12) + s(date_num), data = df)
62-
#' ```
26+
#' @seealso \Sexpr[stage=render,results=rd]{parsnip:::make_seealso_list("gen_additive_mod")}
6327
#'
64-
#' @references \url{https://www.tidymodels.org},
65-
#' [_Tidy Models with R_](https://tmwr.org)
6628
#' @examples
29+
#' show_engines("gen_additive_mod")
6730
#'
68-
#' #show_engines("gen_additive_mod")
69-
#'
70-
#' #gen_additive_mod()
71-
#'
31+
#' gen_additive_mod()
7232
#'
7333
#' @export
7434
gen_additive_mod <- function(mode = "unknown",
7535
select_features = NULL,
76-
adjust_deg_free = NULL) {
36+
adjust_deg_free = NULL,
37+
engine = "mgcv") {
7738

7839
args <- list(
7940
select_features = rlang::enquo(select_features),
@@ -86,7 +47,7 @@ gen_additive_mod <- function(mode = "unknown",
8647
eng_args = NULL,
8748
mode = mode,
8849
method = NULL,
89-
engine = NULL
50+
engine = engine
9051
)
9152

9253
}

R/gen_additive_mod_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ set_fit(
131131
protect = c("formula", "data"),
132132
func = c(pkg = "mgcv", fun = "gam"),
133133
defaults = list(
134-
family = stats::binomial(link = "logit")
134+
family = quote(stats::binomial(link = "logit"))
135135
)
136136
)
137137
)

R/gen_additive_mod_mgcv.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#' Generalized additive models via mgcv
2+
#'
3+
#' [mgcv::gam()] fits a generalized linear model with additive smoother terms
4+
#' for continuous predictors.
5+
#'
6+
#' @includeRmd man/rmd/gen_additive_mod_mgcv.Rmd details
7+
#'
8+
#' @name details_gen_additive_mod_mgcv
9+
#' @keywords internal
10+
NULL

man/details_gen_additive_mod_mgcv.Rd

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gen_additive_mod.Rd

Lines changed: 22 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/parsnip_update.Rd

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)