This learner provides fitting procedures for generalized additive models, using the routines from mgcv through a call to the function gam. The mgcv package and the use of GAMs are described thoroughly (with examples) in Wood (2017) , while Hastie and Tibshirani (1990) also provided an earlier quite thorough look at GAMs.

Format

An R6Class object inheriting from Lrnr_base.

Value

A learner object inheriting from Lrnr_base with methods for training and prediction. For a full list of learner functionality, see the complete documentation of Lrnr_base.

Parameters

  • formula: An optional argument specifying the formula of GAM. Input type can be formula or string, or a list of them. If not specified, continuous covariates will be smoothened with the smooth terms represented using "penalized thin plate regression splines". For a more detailed description, please consult the documentation for gam.

  • family: An optional argument specifying the family of the GAM. See family and family.mgcv for a list of available family functions. If left unspecified, it will be inferred depending on the detected type of the outcome. For now, GAM supports binomial and gaussian outcome types, if formula is unspecified. For a more detailed description of this argument, please consult the documentation of gam.

  • method: An optional argument specifying the method for smoothing parameter selection. The default is global cross-validation (GCV). For more detaileds on this argument, consult the documentation of gam.

  • ...: Other parameters passed to gam. See its documentation for details.

References

Hastie TJ, Tibshirani RJ (1990). Generalized additive models, volume 43. CRC press.

Wood SN (2017). Generalized additive models: an introduction with R. CRC press.

Examples

data(cpp_imputed)
# create task for prediction
cpp_task <- sl3_Task$new(
  data = cpp_imputed,
  covariates = c("bmi", "parity", "mage", "sexn"),
  outcome = "haz"
)
# initialization, training, and prediction with the defaults
gam_lrnr <- Lrnr_gam$new()
gam_fit <- gam_lrnr$train(cpp_task)
gam_preds <- gam_fit$predict()