Skip to contents

model is any function model(X_tr, y_tr, X_te) returning predictions, so this is independent of any particular estimator; the default is OLS with an intercept. The reported se is across folds, which is what the one-standard-error rule uses – the folds share training data and so are positively correlated, biasing it downward.

Usage

morie_esl_cv_score(
  X,
  y,
  model = NULL,
  k = 5L,
  loss = "mse",
  stratify = FALSE,
  seed = 0L
)

Arguments

X

Predictors, n by p.

y

Response.

model

Function (X_tr, y_tr, X_te) -> predictions; defaults to OLS.

k

Number of folds, 2 to n.

loss

"mse", "mae" or "01".

stratify

Preserve class proportions per fold.

seed

Seed for the fold shuffle.

Value

List with cv, se, fold_scores, predictions, fold_id.

References

Hastie, T., et al. (2009). ESL (2nd ed.), Sec 7.10. Springer.

Examples

set.seed(1)
X <- matrix(rnorm(300), ncol = 3)
y <- X %*% c(1, -2, 0.5) + rnorm(100, sd = 0.3)
morie_esl_cv_score(X, y, k = 5)$cv < stats::var(y)
#>      [,1]
#> [1,] TRUE