Learn R Programming

kergp (version 0.5.7)

as.list, covTP-method: Coerce a covTP Object into a List

Description

Coerce a covTP object representing a Tensor-Product covariance kernel on the \(d\)-dimensional Euclidean space into a list containing \(d\) one-dimensional kernels.

Usage

# S4 method for covTP
as.list(x)

Value

A list with length d or d + 1 where d is the "dimension" slot x@d of the object x. The first d

elements of the list are one-dimensional correlation kernel objects with class "covTP". When x is a

covariance kernel (as opposed to a correlation kernel), the list contains one more element which gives the variance.

Arguments

x

A covTP object representing a Tensor-Product covariance kernel.

Caution

When x is not a correlation kernel the (d + 1)-th element of the returned list may be different in future versions: it may be a constant covariance kernel.

See Also

covTP and covTP-class.

Examples

Run this code
set.seed(123)
d <- 6
myCov1 <- covTP(d = d, cov = "corr")
coef(myCov1) <- as.vector(simulPar(myCov1, nsim = 1))
as.list(myCov1)

## more examples and check the value of a 'covMat'
L <- list()
myCov <- list()

myCov[[1]] <- covTP(d = d, cov = "corr")
coef(myCov[[1]]) <- as.vector(simulPar(myCov[[1]], nsim = 1))
L[[1]] <- as.list(myCov[[1]])

myCov[[2]] <- covTP(k1Fun1 = k1Fun1PowExp, d = d, cov = "corr")
coef(myCov[[2]]) <- as.vector(simulPar(myCov[[2]], nsim = 1))
L[[2]] <- as.list(myCov[[2]])

myCov[[3]] <- covTP(k1Fun1 = k1Fun1PowExp, d = d, iso1 = 0L, cov = "corr")
coef(myCov[[3]]) <- as.vector(simulPar(myCov[[3]], nsim = 1))
L[[3]] <- as.list(myCov[[3]])

n <- 10
X <- matrix(runif(n * d), nrow = n,
            dimnames = list(NULL, paste("x", 1:d, sep = "")))
for (iTest in 1:3) {
   C <- covMat(L[[iTest]][[1]], X[ , 1, drop = FALSE])
   for (j in 2:d) {
      C <- C * covMat(L[[iTest]][[j]], X[ , j, drop = FALSE])
   }
   CTest <- covMat(myCov[[iTest]], X)
   print(max(abs(abs(C - CTest))))
}

Run the code above in your browser using DataLab