cvfit | R Documentation |
Using cross-validation automatically select explanatory variables jointly with curve type.
When running cvfit
there is no need to use varselect
separately.
cvfit(
x,
y,
folds = 10,
constant = c(TRUE, FALSE),
sign = NULL,
reps = 3,
parallel = c(FALSE, TRUE),
usepbapply = c(FALSE, TRUE),
alltype = c("logistic", "redLogistic", "doubleExp", "exponential", "arctan", "linear"),
search = c("backward", "forward"),
wsel = c("select", "combine"),
dummy = NULL
)
x |
A matrix of explanatory variables. Excess reserve must be the first input.Additional regressor follow (optional). |
y |
A vector of normalised interest rates. |
folds |
Folds to use for cross-validation. |
constant |
A logical ( |
sign |
A vector of equal length to the number of additional regressors in |
reps |
Number of repetitions for the particle swarm optimisation. |
parallel |
Initialise and use parallel processing for the cross-validation. Note that the maximum number of cores that will be used is equal to the alternative types of curves that are evaluated ( |
usepbapply |
A logical to indicate whether to use pbapply to report on the parallel calculation progress. Note that pbapply does not support load balancing. |
alltype |
A vector of the curve types to consider in the selection process. |
search |
Search strategy for variable inclusion. With |
wsel |
Use the minimum error set of parameters ( |
dummy |
Optional input to signify a regime change (vertical shifts in the curve). Must be a vector of equal length to the rows of |
Returns a list with the recommended variable selection choice:
type
the type of selected curve.
keep
a logical vector with which variables to keep.
varRes
the result from varselect
for each evaluated curve type.
cvIndex
a matrix detailing how the sample was split for the cross-validation. First column is the fold number and second column is the index of the observation.
Use cvfitplot
to visualise the output.
Nikolaos Kourentzes, nikolaos@kourentzes.com
Chen, Z., Kourentzes, N., & Veyrune, R. (2023). Modeling the Reserve Demand to Facilitate Central Bank Operations. IMF Working Papers, 2023(179).
cvfitplot
, curve
, and varselect
.
# Use ECB example data
rate <- ecb$rate
x <- ecb$x[,1:3,drop=FALSE]
cvKeep <- cvfit(x,rate,folds=5,alltype=c("logistic","arctan"),parallel=TRUE)
# Print result
print(cvKeep)
# Fit curve with the selected variables
curve(x[,cvKeep$keep,drop=FALSE],rate,type=cvKeep$type)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.