predict.cvek: Predicting New Response

Description Usage Arguments Details Value Author(s) Examples

View source: R/predict.R

Description

Predicting new response based on given design matrix and the estimation result.

Usage

1
2
## S3 method for class 'cvek'
predict(object, newdata, ...)

Arguments

object

(list) Estimation results returned by cvek() procedure.

newdata

(dataframe) The new set of predictors, whose name is the same as those of formula in cvek().

...

Further arguments passed to or from other methods.

Details

After we obtain the estimation result, we can predict new response.

Value

y_pred

(matrix, n*1) Predicted new response.

Author(s)

Wenying Deng

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
kern_par <- data.frame(method = rep("rbf", 3),
l = rep(3, 3), p = rep(2, 3), 
stringsAsFactors = FALSE)
# define kernel library
kern_func_list <- define_library(kern_par)

n <- 10
d <- 4
formula <- y ~ x1 + x2 + k(x3, x4)
set.seed(1118)
data <- as.data.frame(matrix(
  rnorm(n * d),
  ncol = d,
  dimnames = list(NULL, paste0("x", 1:d))
))
beta_true <- c(1, .41, 2.37)
lnr_kern_func <- generate_kernel(method = "rbf", l = 3)
kern_effect_lnr <-
  parse_kernel_variable("k(x3, x4)", lnr_kern_func, data)
alpha_lnr_true <- rnorm(n)

data$y <- as.matrix(cbind(1, data[, c("x1", "x2")])) %*% beta_true +
  kern_effect_lnr %*% alpha_lnr_true

data_train <- data[1:6, ]
data_test <- data[7:10, ]

result <- cvek(formula,
               kern_func_list,
               data_train,
               mode = "loocv",
               strategy = "stack",
               beta_exp = 1,
               lambda = exp(seq(-2, 2)),
               test = "asymp",
               alt_kernel_type = "linear",
               verbose = FALSE)

predict(result, data_test)

CVEK documentation built on Jan. 8, 2021, 5:42 p.m.