iprior_cv {iprior} | R Documentation |
Perform a cross-validation experiment with the iprior function
Description
A convenience function to perform a k-fold cross-validation experiment and
obtain mean squared error of prediction. Most of the arguments are similar to
iprior()
and kernL()
.
Usage
## Default S3 method:
iprior_cv(
y,
...,
folds = 2,
par.cv = TRUE,
kernel = "linear",
method = "direct",
control = list(),
interactions = NULL,
est.lambda = TRUE,
est.hurst = FALSE,
est.lengthscale = FALSE,
est.offset = FALSE,
est.psi = TRUE,
fixed.hyp = NULL,
lambda = 1,
psi = 1,
nystrom = FALSE,
nys.seed = NULL
)
## S3 method for class 'formula'
iprior_cv(
formula,
data,
folds = 2,
one.lam = FALSE,
par.cv = TRUE,
kernel = "linear",
method = "direct",
control = list(),
est.lambda = TRUE,
est.hurst = FALSE,
est.lengthscale = FALSE,
est.offset = FALSE,
est.psi = TRUE,
fixed.hyp = NULL,
lambda = 1,
psi = 1,
nystrom = FALSE,
nys.seed = NULL,
...
)
Arguments
y |
Vector of response variables |
... |
Only used when fitting using non-formula, enter the variables (vectors or matrices) separated by commas. |
folds |
The number of cross-validation folds. Set equal to sample size
or |
par.cv |
Logical. Multithreading to fit the models? Defaults to
|
kernel |
Character vector indicating the type of kernel for the variables. Available choices are:
The |
method |
The estimation method. One of:
|
control |
(Optional) A list of control options for the estimation procedure:
|
interactions |
Character vector to specify the interaction terms. When
using formulas, this is specified automatically, so is not required. Syntax
is |
est.lambda |
Logical. Estimate the scale parameters? Defaults to
|
est.hurst |
Logical. Estimate the Hurst coefficients for fBm kernels?
Defaults to |
est.lengthscale |
Logical. Estimate the lengthscales for SE kernels?
Defaults to |
est.offset |
Logical. Estimate the offsets for polynomial kernels?
Defaults to |
est.psi |
Logical. Estimate the error precision? Defaults to
|
fixed.hyp |
Logical. If |
lambda |
Initial/Default scale parameters. Relevant especially if
|
psi |
Initial/Default value for error precision. Relevant especially if
|
nystrom |
Either logical or an integer indicating the number of Nystrom
samples to take. Defaults to |
nys.seed |
The random seed for the Nystrom sampling. Defaults to
|
formula |
The formula to fit when using formula interface. |
data |
Data frame containing variables when using formula interface. |
one.lam |
Logical. When using formula input, this is a convenient way of
letting the function know to treat all variables as a single variable (i.e.
shared scale parameter). Defaults to |
Details
Uses a multicore loop to fit the folds by default, set par.cv = FALSE
to not use multithreading.
Value
An iprior_xv
object containing a data frame of the
cross-validated values such as the log-likelihood, training MSE and test
MSE.
Examples
## Not run:
# 5-fold CV experiment
(mod.cv <- iprior_cv(y ~ X, gen_smooth(100), kernel = "se", folds = 5))
# LOOCV experiment
(mod.cv <- iprior_cv(y ~ X, gen_smooth(100), kernel = "se", folds = Inf))
# Can also get root MSE
print(mod.cv, "RMSE")
## End(Not run)