Executes the 3 stage framework for GAM. This function uses a modified version of cv.gglasso from the gglasso package, and GAM functions from the mgcv package.

gam3(
  formula,
  data,
  gam.function = "gam",
  pred.loss = "L2",
  nfolds = c(5, 5),
  foldid,
  loss = "ls",
  nlambda = c(100, 100),
  lambda.factor = ifelse(nobs < nvars, 0.05, 0.001),
  lambda = list(NULL, NULL),
  pf = list(sqrt(bs), sqrt(bs)),
  eps = c(1e-08, 1e-08),
  maxit = c(3e+08, 3e+08),
  intercept = TRUE,
  ...
)

Arguments

formula

A GAM formula, as used in gam.

data

A dataframe containing the variables in the model.

gam.function

A character object that indicates which GAM function should be used. Options are "gam" and "bam". See the mgcv package for more details.

pred.loss

See cv.gglasso for details.

nfolds

A vector of length 2 providing the number of folds for cross-validtion in stage 1 and stage 2.

foldid

A list of length 2 providing the folds for each observations for cross-validation in stage 1 and stage 2.

loss

See gglasso for details.

nlambda

A vector of length 2 providing the number of lambda values to use in stage 1 and stage 2.

lambda.factor

A numeric value specifying the lambda.factor. See gglasso for details.

lambda

A list of length 2 providing the lambda sequences to use for stage 1 and stage 2.

pf

A list of length 2 providing the penalty factors to use for stage 1 and stage 2.

eps

A vector of length 2 for stage 1 and stage 2. See gglasso for details.

maxit

A vector a length 2 for stage 1 and stage 2. See gglasso for details.

intercept

Should the intercept be included in the model.

...

Additional parameters to pass to gam.function

Value

An object of class "gam" as described in gamObject.

Details

Executes the 3 stage framework for GAM. This function uses a modified version of cv.gglasso from the gglasso package, and GAM functions from the mgcv package.

References

Wood, S.N. (2017) Generalized Additive Models: an introduction with R (2nd edition), CRC

Yang, Y. and Zou, H. (2015),A Fast Unified Algorithm for Computing Group-Lasso Penalized Learning Problems. Statistics and Computing. 25(6), 1129-1141.

See also

Examples

require(mgcv)
#> Loading required package: mgcv
#> Loading required package: nlme
#> This is mgcv 1.8-31. For overview type 'help("mgcv-package")'.
require(gglasso)
#> Loading required package: gglasso
probs <- c(0.1, 0.1, 0.1, 0.1, 0.1, 0.5) simulated_data <- gamSim2(n = 1000, p = 200, test.n = 200, sigma = 0.1, probs = probs) data <- simulated_data$data m <- 2 k <- 8 terms <- paste("s(", names(data)[-1], ", bs = 'ps', ", "m = ", m, ", k = ", k, ")", sep = "") formula <- as.formula(paste("y ~", paste(terms, collapse = " + "))) lambda.factor <- 0.0001 gam3.mod <- gam3(formula, data, gam.function = "bam", lambda.factor = lambda.factor)
#> Starting stage 1
#> lambda.factor changed to 0.0509413801481638
#> Starting stage 2
#> Starting stage 3