New function to compute optimal value of regularization parameter based on K-fold cross-validation

mc_cv(
  fit,
  Kfold = 5,
  nweight = NULL,
  weighting = TRUE,
  wtype = "size",
  type = "MSFE",
  l1length = 100,
  normalize = TRUE
)

Arguments

fit

fitted object returned from mc_reg()

Kfold

K-fold cross-validation

nweight

vector of length K indicating weights for MSFE measure

type

MSFE or MAFE

l1length

length sparsity grid l1 penalty

asym

flag: asymmetric forecast error measure or not

Value

A list with the following components

train

list of the training splits used

test

list of the testing splits used

mc_fits

List of length Kfold. Each element is a mc_reg() object that was fit on a training split.

fe

A data frame of forecast errors. Includes CV prediction (yhat), observed value (y), class and knot.

pooled_fe
class_knot_fold_summary

One MSFE and MAFE for each fold, knot, class combination.

class_knot_summary

One MSFE and MAFE for each knot and each class.

knot_summary

One MSFE and MAFE for each knot.

pooled_class_fold_summary

One MSFE and MAFE for each fold and each class.

pooled_class_summary

One MSFE and MAFE for each class.

pooled_summary

One overall MSFE and MAFE for the pooled model.

fit_MSFE

Data frame with the coefficients from the full fitted model that correspond to the optimal knot as defined by MSFE cross validation, this is a subset of fit$coef_df which is supplied as an argument to the CV function.

fit_MAFE

Data frame with the coefficients from the full fitted model that correspond to the optimal knot as defined by MAFE cross validation, this is a subset of fit$coef_df which is supplied as an argument to the CV function.

Examples

p <- 7
k <- 2
n <- 500
beta <- c(1, 2)
set.seed(1)
X <- list(matrix(rnorm(p * n), ncol = p), matrix(rnorm(p * n), ncol = p))
Y <- list(rnorm(n), rnorm(n))
df = lists_to_data(Y, X)
res = mc_reg(df)
cv_res <- mc_cv(res)