Learn R Programming

SpatioTemporal (version 1.1.2)

makeSigmaB: Create Block Covariance Matrix (Equal Block Sizes)

Description

Function that creates a block covariance matrix with equal sized blocks. Used to construct the Sigma_B matrix.

Usage

makeSigmaB(pars, dist, type = "exp", nugget = 0,
    symmetry = dim(dist)[1] == dim(dist)[2],
    ind2.to.1 = 1:dim(dist)[2])

Arguments

pars
List of parameters for each block; if not a list a single block matrix is assumed. Should match parameters suggested by parsCovFuns.
dist
Distance matrix.
type
Name(s) of covariance functions, see namesCovFuns.
nugget
Vector of nugget(s) to add to the diagonal of each matrix.
symmetry
TRUE/FALSE flag if the dist is symmetric, resulting in a symmetric covariance matrix.
ind2.to.1
Vectors, that for each index along the second dimension gives a first dimension index, used only if symmetry=FALSE to determine which covariances should have an added nugget (collocated sites).

Value

  • Block covariance matrix of size dim(dist)*n.blocks.

Details

Any parameters given as scalars will be rep-ed to match length(pars).

See Also

Other block matrix functions: blockMult, calc.FX, calc.FXtF2, calc.iS.X, calc.mu.B, calc.tFX, calc.tFXF, calc.X.iS.X, invCholBlock, makeCholBlock, makeSigmaNu, solveTriBlock

Other covariance functions: crossDist, evalCovFuns, makeSigmaNu, namesCovFuns, parsCovFuns, updateCovf

Examples

Run this code
##First create some random locations
x <- rnorm(5)
y <- rnorm(5)

##compute distance matrix
D <- crossDist( cbind(x,y) )

##create a block diagonal matrix exponential covariance matrix
##with different range, sill, and nugget
pars <- list(c(.3,2), c(2,1), c(1,3))
nugget <- c(.5,0,1)

Sigma1 <- makeSigmaB(pars, D, type="exp", nugget=nugget)
##or using different covariance functions for each block
Sigma2 <- makeSigmaB(pars, D, type=c("exp","exp2","cubic"),
                     nugget=nugget)

##make a cross-covariance matrix
Dcross <- D[1:3,c(1,1,2,2)]
Sigma.cross <- makeSigmaB(pars, Dcross, type="exp", nugget=nugget,
                          ind2.to.1=c(1,1,2,2))

Sigma.alt <- matrix(0, length(pars)*dim(D)[1], length(pars)*dim(D)[1])
  for(i in 1:length(pars)){
    Ind <- (1:dim(D)[1]) + (i-1)*dim(D)[1]
    Sigma.alt[Ind, Ind] <- pars[[i]][2]*exp(-D/pars[[i]][1])
    diag(Sigma.alt[Ind, Ind]) <- diag(Sigma.alt[Ind, Ind])+nugget[i]
  }
  if( abs(max(Sigma1-Sigma.alt)) > 1e-13){
    stop("makeSigmaB: Results not equal, covariance")
  }
  Ind <- c(1,1,2,2)
  Sigma.alt.cross <- Sigma.alt[c(1:3,6:8,11:13),c(Ind, 5+Ind, 10+Ind)]
  if( abs(max(Sigma.cross-Sigma.alt.cross)) > 1e-13){
    stop("makeSigmaB: Results not equal, cross-covariance")
  }

Run the code above in your browser using DataLab