This function is to be called after calling sparse_log_contrast. It performs nfold-fold cross validation.

cv_sparse_log_contrast(
  fit,
  Z,
  y,
  folds = NULL,
  nfolds = 5,
  summary_function = stats::median
)

Arguments

fit

output of sparse_log_contrast function.

Z, y

same arguments as passed to sparse_log_contrast. C that is used will be taken from fit object.

folds

a partition of 1:nrow(Z).

nfolds

number of folds for cross-validation

summary_function

how to combine the errors calculated on each observation within a fold (e.g. mean or median)