Learn R Programming

kergp (version 0.5.7)

corLevDiag: Correlation or Covariance Matrix for a Diagonal Structure

Description

Compute the correlation or covariance matrix for a diagonal structure.

Usage

corLevDiag(par, nlevels, levels, lowerSQRT = FALSE, compGrad = TRUE,
  cov = 0)

Value

A correlation matrix (or its Cholesky root) with the optional gradient attribute.

Arguments

par

A numeric vector with length npVar where npVar is the number of variance parameters, namely 0, 1 or nlevels corresponding to the values of cov: 0, 1 and 2.

nlevels

Number of levels.

levels

Character representing the levels.

lowerSQRT

Logical. When TRUE the (lower) Cholesky root \(\mathbf{L}\) of the correlation or covariance matrix \(\mathbf{C}\) is returned instead of the correlation matrix.

compGrad

Logical. Should the gradient be computed?

cov

Integer 0, 1 or 2. If cov is 0, the matrix is a correlation matrix (or its Cholesky root) i.e. an identity matrix. If cov is 1 or 2, the matrix is a covariance (or its square root) with constant variance vector for code = 1 and with arbitrary variance vector for code = 2.

Examples

Run this code
set.seed(123)
checkGrad <- TRUE
nlevels <- 12
sigma2 <- rexp(n = nlevels)
T0 <- corLevDiag(nlevels = nlevels, par = sigma2, cov = 2)
L0 <- corLevDiag(nlevels = nlevels, par = sigma2, cov = 2,
                 lowerSQRT = TRUE)

Run the code above in your browser using DataLab