parse_cvek_formula: Parses user-supplied formula to fixed-effect and kernel...

Description Usage Arguments Details Value Author(s) Examples

Description

Parses user-supplied formula to fixed-effect and kernel matrices.

Usage

1
2
parse_cvek_formula(formula, kern_func_list, data, data_new = NULL,
  verbose = FALSE)

Arguments

formula

(formula) A user-supplied formula.

kern_func_list

(list) a list of kernel functions in the kernel library

data

(data.frame, n*d) a data.frame, list or environment (or object coercible by as.data.frame to a data.frame), containing the variables in formula. Neither a matrix nor an array will be accepted.

data_new

(data.frame, n_new*d) new data for computing predictions.

verbose

(logical) Whether to print additional messages.

Details

The formula object is exactly like the formula for a GLM except that user can use k() to specify kernel terms. Additionally, user can specify interaction between kernel terms (using either '*' and ':'), and exclude interaction term by including -1 on the rhs of formula.

Value

A list of three slots:

Y

(matrix, n*1) The vector of response variable.

X

(matrix, n*d_fix) The fixed effect matrix.

K

(list of matrices) A nested list of kernel term matrices. The first level corresponds to each base kernel function in kern_func_list, the second level corresponds to each kernel term specified in the formula.

Author(s)

Jeremiah Zhe Liu

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
# create data
data <- as.data.frame(matrix(rnorm(700), ncol = 7,
dimnames = list(NULL, paste0("x", 1:7))))
data_new <- as.data.frame(matrix(rexp(700), ncol = 7,
dimnames = list(NULL, paste0("x", 1:7))))
data$y <- as.matrix(data) %*% rnorm(7)
formula <- y ~ x1 + x2 + k(x3, x4) + k(x5, x6) + k(x7) + k(x3, x4) * k(x5, x6) * x7
kern_par <- data.frame(method = c("rbf", "polynomial", "matern"),
l = c(.5, 1, 1.5), d = 1:3, stringsAsFactors = FALSE)

# define kernel library
kern_func_list <- list()
for (d in 1:nrow(kern_par)) {
kern_func_list[[d]] <- generate_kernel(kern_par[d,]$method,
kern_par[d,]$l, kern_par[d,]$d)
}

# produce training data 
parse_cvek_formula(formula, kern_func_list = kern_func_list, 
data = data, data_new = NULL)

# produce prediction data from data_new
parse_cvek_formula(formula, kern_func_list = kern_func_list, 
data = data, data_new = data_new)

statmlhb/CVEK documentation built on May 5, 2019, 3:47 a.m.