KFPLS {KFPLS} | R Documentation |
Kernel functional partial least squares (KFPLS) method for functional nonlinear models with scalar response and functional predictors. The Gaussian kernel is used.
KFPLS(X, Y, obser_time, nfold, n_comp, sigm_list, basis)
X |
An |
Y |
A |
obser_time |
A |
nfold |
An |
n_comp |
A |
sigm_list |
A |
basis |
A basis object denoting the basis that used for the smoothing of the functional predictors. It is created by functions in |
A list
containing the following components:
n |
A |
p |
A |
nk |
A |
T |
A |
U |
A |
K |
A |
K_c |
A |
Xfd_list |
A |
XX_list |
A |
Y_c |
A |
meanY |
A |
Y_hat |
A |
obser_time |
A |
basis |
A basis object denoting the basis that used for the smoothing of the functional predictors. |
sigm |
A |
CVscore |
A |
time |
A |
# Generate data
n <- 200
t_range <- c(0, 1)
obser_time <- seq(0, 1, length.out = 51)
beta_fun <- function(t){2 * sin(2 * pi * t)}
basis <- fda::create.bspline.basis(t_range, nbasis = 13, norder = 4,
breaks = seq(0, 1, length.out = 11))
beta_fd <- fda::smooth.basis(obser_time, beta_fun(obser_time), basis)$fd
X_basis <- fda::create.bspline.basis(t_range, nbasis = 23, norder = 4,
breaks = seq(0, 1, length.out = 21))
Bbeta <- fda::inprod(X_basis, beta_fd)
Xi_B <- splines::bs(obser_time, knots = seq(0, 1, length.out = 21)[-c(1, 21)],
degree = 3, intercept = TRUE)
a <- array(0, dim = c(n, 23, 1))
X <- array(0, dim = c(n, 51, 1))
Y <- NULL
for(i in 1:n){
a[i, , 1] <- stats::rnorm(23)
X[i, , 1] <- Xi_B %*% a[i, , 1]
aBbeta <- as.numeric(t(a[i, , 1]) %*% Bbeta)
Y[i] <- aBbeta + stats::rnorm(1, mean = 0, sd = 0.05)
}
# KFPLS
KFPLS_list <- KFPLS(X, Y, obser_time, nfold = 5, n_comp = 5, sigm_list = 0.005, basis)
plot(KFPLS_list$Y_hat, Y)
lines(Y, Y)