Learn R Programming

kergp (version 0.5.7)

covMat-methods: Covariance Matrix for a Covariance Kernel Object

Description

Covariance matrix for a covariance kernel object.

Usage

# S4 method for covMan
covMat(object, X, Xnew, compGrad = hasGrad(object), 
       checkNames = NULL, index = 1L, ...)

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

Value

A \(n_1 \times n_2\) matrix with general element

\(C_{ij} := K(\mathbf{x}_{1,i},\,\mathbf{x}_{2,j};\,\boldsymbol{\theta})\) where

\(K(\mathbf{x}_1,\,\mathbf{x}_2;\,\boldsymbol{\theta})\) is the covariance kernel function.

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.

Author

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

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.

See Also

coef method

Examples

Run this code
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))

Run the code above in your browser using DataLab