Learn R Programming

SLOPE (version 2.0.0)

cvSLOPE: Tune SLOPE with Cross-Validation

Description

This function trains a model fit by SLOPE() by tuning its parameters through cross-validation.

Usage

cvSLOPE(
  x,
  y,
  q = 0.2,
  gamma = 0,
  n_folds = 10,
  n_repeats = 1,
  measure = c("mse", "mae", "deviance", "misclass", "auc"),
  refit = TRUE,
  ...
)

Value

An object of class "TrainedSLOPE", with the following slots:

summary

a summary of the results with means, standard errors, and 0.95 confidence levels

data

the raw data from the model training

optima

a data.frame of the best (mean) values for the different metrics and their corresponding parameter values

measure

a data.frame listing the used metric and its label

model

the model fit to the entire dataset using optimal parameters (only present if refit = TRUE)

call

the call

Arguments

x

the design matrix, which can be either a dense matrix of the standard matrix class, or a sparse matrix inheriting from Matrix::sparseMatrix. Data frames will be converted to matrices internally.

y

the response, which for family = "gaussian" must be numeric; for family = "binomial" or family = "multinomial", it can be a factor.

q

a vector of quantiles for the q parameter in SLOPE

gamma

relaxation parameter for SLOPE. Default is 0.0, which implies to relaxation of the penalty.

n_folds

number of folds (cross-validation)

n_repeats

number of folds (cross-validation)

measure

DEPRECATED

refit

logical; if TRUE, refits the model on the full dataset using the optimal parameters. Default is TRUE.

...

other arguments to pass on to SLOPE()

See Also

Other model-tuning: plot.TrainedSLOPE(), refit(), summary.TrainedSLOPE(), trainSLOPE()

Examples

Run this code
# 8-fold cross-validation
tune <- cvSLOPE(
  subset(mtcars, select = c("mpg", "drat", "wt")),
  mtcars$hp,
  q = c(0.1, 0.2),
  n_folds = 8,
  n_repeats = 2,
  measure = "mse"
)

# Access the refitted model
tune$model

# Or use refit() to refit with different measure
fit <- refit(
  tune,
  subset(mtcars, select = c("mpg", "drat", "wt")),
  mtcars$hp
)
coef(fit)

Run the code above in your browser using DataLab