covMat-methods: Covariance Matrix for a Covariance Kernel Object

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Covariance matrix for a covariance kernel object.

Usage

1
2
3
4
5
6
7
## S4 method for signature 'covMan'
covMat(object, X, Xnew, compGrad = hasGrad(object), 
       checkNames = NULL, index = 1L, ...)

## S4 method for signature 'covTS'
covMat(object, X, Xnew, compGrad = FALSE, 
       checkNames = TRUE, index = 1L, ...)

Arguments

object

An object with S4 class corresponding to a covariance kernel.

X

The matrix (or data.frame) of design points, with n rows and d cols where n is the number of spatial points and d is the 'spatial' dimension.

Xnew

An optional new matrix of spatial design points. If missing, the same matrix is used: Xnew = X.

compGrad

Logical. If TRUE a derivative with respect to a parameter will be computed and returned as an attribute of the result. For the covMan class, this is possible only when the gradient of the kernel is computed and returned as a "gradient" attribute of the result.

checkNames

Logical. If TRUE (default), check the compatibility of X with object, see checkX.

index

Integer giving the index of the derivation parameter in the official order. Ignored if compGrad = FALSE.

...

not used yet.

Details

The covariance matrix is computed in a C program using the .Call interface. The R kernel function is evaluated within the C code using eval.

Value

A (n_1, n_2) matrix with general element C[i, j] = K(X1[i, ], X2[j, ], θ) where K(x1, x2, θ) is the covariance kernel function.

Note

The value of the parameter θ can be extracted from the object with the coef method.

Author(s)

Y. Deville, O. Roustant, D. Ginsbourger, N. Durrande.

See Also

coef method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
myCov <- covTS(inputs = c("Temp", "Humid", "Press"),
               kernel = "k1PowExp",
               dep = c(range = "cst", shape = "cst"),
               value = c(shape = 1.8, range = 1.1))
n <- 100; X <- matrix(runif(n*3), nrow = n, ncol = 3)
try(C1 <- covMat(myCov, X)) ## bad colnames
colnames(X) <- inputNames(myCov)
C2 <- covMat(myCov, X)

Xnew <- matrix(runif(n * 3), nrow = n, ncol = 3)
colnames(Xnew) <- inputNames(myCov)
C2 <- covMat(myCov, X, Xnew)

## check with the same matrix in 'X' and 'Xnew'
CMM <- covMat(myCov, X, X)
CM <- covMat(myCov, X)
max(abs(CM - CMM))

Example output

Loading required package: Rcpp
Loading required package: testthat
Loading required package: nloptr
Error in .local(object, X, ...) : 
  all the elements of inputNames(object) must be in colnames(X)
[1] 0

kergp documentation built on March 18, 2021, 5:06 p.m.