| crossval | R Documentation |
Estimator of the mean squared prediction error of different learners using cross-validation.
crossval(
y,
X,
Z = NULL,
learners,
cv_folds = 5,
cv_subsamples = NULL,
silent = FALSE,
progress = NULL
)
y |
The outcome variable. |
X |
A (sparse) matrix of predictive variables. |
Z |
Optional additional (sparse) matrix of predictive variables. |
learners |
Omission of the |
cv_folds |
Number of folds used for cross-validation. |
cv_subsamples |
List of vectors with sample indices for cross-validation. |
silent |
Boolean to silence estimation updates. |
progress |
String to print before learner and cv fold progress. |
crossval returns a list containing the following components:
mspeA vector of MSPE estimates, each corresponding to a base learners (in chronological order).
oos_residA matrix of out-of-sample prediction errors, each column corresponding to a base learners (in chronological order).
cv_subsamplesPass-through of cv_subsamples.
See above.
Other utilities:
crosspred(),
shortstacking()
# Construct variables from the included Angrist & Evans (1998) data
y = AE98[, "worked"]
X = AE98[, c("morekids", "age","agefst","black","hisp","othrace","educ")]
# Compare ols, lasso, and ridge using 4-fold cross-validation
cv_res <- crossval(y, X,
learners = list(list(fun = ols),
list(fun = mdl_glmnet),
list(fun = mdl_glmnet,
args = list(alpha = 0))),
cv_folds = 4,
silent = TRUE)
cv_res$mspe
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.