Learn R Programming

SpatioTemporal (version 1.1.7)

makeSigmaNu: Create Block Covariance Matrix (Unequal Block Sizes)

Description

Function that creates a block covariance matrix with unequally sized blocks. Used to construct the Sigma_nu matrix.

Usage

makeSigmaNu(pars, dist, type = "exp", nugget = 0,
    random.effect = 0,
    symmetry = dim(dist)[1] == dim(dist)[2],
    blocks1 = dim(dist)[1], blocks2 = dim(dist)[2],
    ind1 = 1:dim(dist)[1], ind2 = 1:dim(dist)[2],
    ind2.to.1 = 1:dim(dist)[2], sparse = FALSE)

Arguments

pars

Vector of parameters, as suggested by parsCovFuns.

dist

Distance matrix.

type

Name of the covariance function to use, see namesCovFuns.

nugget

A value of the nugget or a vector of length dim(dist)[1] giving (possibly) location specific nuggets.

random.effect

A constant variance to add to the covariance matrix, can be interpereted as either and partial sill with infinite range or as a random effect with variance given by random.effect for the mean value.

symmetry

TRUE/FALSE flag if the dist matrix is symmetric. If also ind1==ind2 and blocks1==blocks2 the resulting covariance matrix will be symmetric.

blocks1,blocks2

Vectors with the size(s) of each of the diagonal blocks, usually mesa.model$nt. If symmetry=TRUE and then blocks2 defaults to blocks1 if missing.

ind1,ind2

Vectors indicating the location of each element in the covariance matrix, used to index the dist-matrix to determine the distance between locations, usually mesa.model$obs$idx. If symmetry=TRUE and then ind2 defaults to ind1 if missing.

ind2.to.1

Vectors, that for each index along the second dimension, ind2, gives a first dimension index, ind1, used only if symmetry=FALSE to determine which covariances should have an added nugget (collocated sites).

sparse

If TRUE, return a block diagonal sparse matrix, see bdiag.

Value

Block covariance matrix of size length(ind1)-by-length(ind2).

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, makeSigmaB, solveTriBlock

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

Examples

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

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

#a vector of locations
I <- c(1,2,3,1,4,4,3,2,1,1)
T <- c(1,1,1,2,2,3,3,3,3,4)

##create a block diagonal matrix consisting of four parts with
##exponential covariance.
sigma.nu <- makeSigmaNu(c(.4,2), D, "exp", nugget=0.1,
                        blocks1 = c(3,2,4,1), ind1 = I)
##and cross covariance
sigma.nu.c <- makeSigmaNu(c(.4,2), D, "exp", nugget=0.1,
                          blocks1 = c(3,2,4,1), ind1 = I, 
                          blocks2 = c(0,0,3,1), ind2 = I[7:10])

##compare the cross-covariance with the relevant part of sigma.nu
range(sigma.nu.c-sigma.nu[,7:10])
# }
# NOT RUN {
##an alternative showing the use of loc.ind2.to.1
sigma.nu.c <- makeSigmaNu(c(.4,2), D[,4:3], "exp", nugget=0.1,
                          blocks1 = c(3,2,4,1), ind1 = I, 
                          blocks2 = c(0,0,2,0), ind2 = 1:2,
                          ind2.to.1=4:3)
##compare the cross-covariance with the relevant part of sigma.nu
range(sigma.nu.c-sigma.nu[,6:7])
# }

Run the code above in your browser using DataLab