run_cvfun | R Documentation |
cvfits
from cvfun
A helper function that can be used to create input for
cv_varsel.refmodel()
's argument cvfits
by running first cv_folds()
and
then the reference model object's cvfun
(see init_refmodel()
). This is
helpful if K
-fold CV is run multiple times based on the same K
reference model refits.
run_cvfun(object, ...)
## Default S3 method:
run_cvfun(object, ...)
## S3 method for class 'refmodel'
run_cvfun(
object,
K = if (!inherits(object, "datafit")) 5 else 10,
seed = NA,
...
)
object |
An object of class |
... |
For |
K |
Number of folds. Must be at least 2 and not exceed the number of observations. |
seed |
Pseudorandom number generation (PRNG) seed by which the same
results can be obtained again if needed. Passed to argument |
An object that can be used as input for cv_varsel.refmodel()
's
argument cvfits
.
# Data:
dat_gauss <- data.frame(y = df_gaussian$y, df_gaussian$x)
# The "stanreg" fit which will be used as the reference model (with small
# values for `chains` and `iter`, but only for technical reasons in this
# example; this is not recommended in general):
fit <- rstanarm::stan_glm(
y ~ X1 + X2 + X3 + X4 + X5, family = gaussian(), data = dat_gauss,
QR = TRUE, chains = 2, iter = 500, refresh = 0, seed = 9876
)
# Define the reference model object explicitly:
ref <- get_refmodel(fit)
# Run the reference model object's `cvfun` (with a small value for `K`, but
# only for the sake of speed in this example; this is not recommended in
# general):
cvfits <- run_cvfun(ref, K = 2, seed = 184)
# Run cv_varsel() (with L1 search and small values for `nterms_max` and
# `nclusters_pred`, but only for the sake of speed in this example; this is
# not recommended in general) and use `cvfits` there:
cvvs_L1 <- cv_varsel(fit, method = "L1", cv_method = "kfold",
cvfits = cvfits, nterms_max = 3, nclusters_pred = 10,
seed = 5555)
# Now see, for example, `?print.vsel`, `?plot.vsel`, `?suggest_size.vsel`,
# and `?ranking` for possible post-processing functions.
# The purpose of run_cvfun() is to create an object that can be used in
# multiple cv_varsel() calls, e.g., to check the sensitivity to the search
# method (L1 or forward):
cvvs_fw <- cv_varsel(fit, method = "forward", cv_method = "kfold",
cvfits = cvfits, nterms_max = 3, nclusters = 5,
nclusters_pred = 10, seed = 5555)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.