cv.MRFA {MRFA} | R Documentation |
Compute K-fold cross-validated error for Multi-Resolution Functional ANOVA (MRFA) Model
Description
Computes the K-fold cross validated mean squared prediction error for multiresolution functional ANOVA model.
Usage
cv.MRFA(
X,
Y,
order = 10,
level = 10,
lambda = exp(seq(log(500), log(0.001), by = -0.01)),
K = 10,
plot.it = TRUE,
parallel = FALSE,
verbose = FALSE,
...
)
Arguments
X |
input for |
Y |
input for |
order |
input for |
level |
input for |
lambda |
lambda values at which CV curve should be computed. |
K |
a positive integer specifying the number of folds. |
plot.it |
logical. If |
parallel |
logical. If |
verbose |
logical. If |
... |
additional arguments to |
Value
lambda |
lambda values at which CV curve is computed. |
cv |
the CV curve at each value of lambda. |
cv.error |
the standard error of the CV curve |
Author(s)
Chih-Li Sung <iamdfchile@gmail.com>
See Also
MRFA_fit
for fitting a multiresolution functional ANOVA model.
Examples
## Not run:
##### Testing function: GRAMACY & LEE (2009) function #####
##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University #####
grlee09 <- function(xx)
{
x1 <- xx[1]
x2 <- xx[2]
x3 <- xx[3]
x4 <- xx[4]
x5 <- xx[5]
x6 <- xx[6]
term1 <- exp(sin((0.9*(x1+0.48))^10))
term2 <- x2 * x3
term3 <- x4
y <- term1 + term2 + term3
return(y)
}
library(MRFA)
##### Training data and testing data #####
set.seed(2)
n <- 100; n_rep <- 3; n_new <- 50; d <- 6
X.train <- matrix(runif(d*n), ncol = d)
X.train <- matrix(rep(X.train, each = n_rep), ncol = d)
Y.train <- apply(X.train, 1, grlee09)
Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05)
X.test <- matrix(runif(d*n_new), ncol = d)
Y.test <- apply(X.test, 1, grlee09)
##### Fitting #####
MRFA_model <- MRFA_fit(X.train, Y.train)
##### Computes the K-fold cross validated #####
cv.out <- cv.MRFA(X.train, Y.train, K = 5, lambda = seq(0.01,3,0.1))
##### Prediction : CV ######
lambda_cv <- cv.out$lambda[which.min(cv.out$cv)]
Y.pred <- predict(MRFA_model, X.test, lambda = lambda_cv)$y_hat
print(sqrt(mean((Y.test - Y.pred)^2)))
## End(Not run)