getCovMatNSR: Create a covariance matrix.

Description Usage Arguments Details Value Note See Also Examples

View source: R/getCoxMatsR.R

Description

getCovMatNSR returns a non-stationary covariance matrix (with nugget).

Usage

1
getCovMatNSR(V, R, sig2eps)

Arguments

V

A positive vector of length n.

R

An n x n correlation matrix.

sig2eps

A positive scalar representing the variance of the noise (or nugget).

Details

This creates a covariance matrix, C, where

C = V^{0.5}RV^{0.5} + σ^2_ε I

where V is a matrix with process variances (from vector V above) on the diagonal, R is a correlation matrix, and σ^2_ε is the variance of the noise (or nugget).

Value

An n x n covariance matrix

Note

Surprisingly, this method is substantially faster, even for relatively large matrices (tested up to 5000 x 5000), than doing sparse matrix multiplication in the Matrix package. Sparse matrix multiplication was orders of magnitude slower for small matrices than the method implemented above or for diag(V)^0.5 %*% R %*% diag(V)^0.5, which was roughly the same speed as above for small matrices, but much slower for large matrices.

See Also

Other correlation and covariance functions: combineCorMatsR, getCorMatR, getCovMatSR

Examples

1
2
3
4
5
6
7
8
n <- 10
d <- 2
x <- matrix(runif(n * d), nrow = n, ncol = d)
rho <- runif(d, 0, 1)
R <- getCorMat(x, rho)
sig2eps <- 0.01
V <- rlnorm(n, -0.1, 0.1)
getCovMatNSR(V, R, sig2eps)

cbdavis33/bcgp documentation built on Oct. 1, 2019, 8:07 a.m.