Learn R Programming

SpatioTemporal (version 0.9.2)

make.sigma.B.full: The Covariance Matrix for Temporal Trends and beta Fields.

Description

Computes the full (cross)-covariance matrix for the beta fields multiplied by the temporal trends; i.e. F*sigmaB*F' where sigmaB is a block diagonal matrix, usually the output from make.sigma.B.

Usage

make.sigma.B.full(sill, range, loc.ind1, loc.ind2 = loc.ind1,
                  F1, F2 = F1, dists)

Arguments

sill, range
Vectors with the sill and range parameters for each of the block matrices.
loc.ind1,loc.ind2
Vectors indicating which location the rows in F1 and F2 corresponds to, usually mesa.data.model$obs$idx.
F1,F2
(number of obs.) - by - (number of temporal trends) matrices containing the temporal trends. Usually mesa.data.model$F, where mesa.data.model is obtained from
dists
Distance matrix giving the distances between the (observed) locations.

Value

  • Returns the covariance or cross-covariance matrix F'*sigmaB*F.

encoding

latin1

See Also

make.sigma.B, make.sigma.nu

This function is called by loglike.

Examples

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

##compute distance matrix
D <- as.matrix(dist( cbind(x,y) ))

##create a trend
trend <- cbind(rep(1,5),sin(1:5))
##an index of locations
idx <- c(rep(1:3,3),1:2,2:3)
##expand the F matrix to match the locations/times in idx/T.
F <- trend[c(rep(1:3,each=3),4,4,5,5),]

##compute F*sigmaB*F'
FsigmaF <- make.sigma.B.full(c(2,1), c(.3,1), loc.ind1=idx,
                             F1=F, dists=D)

##create the full F matrix
Falt <- matrix(0,dim(F)[1],dim(F)[2]*max(idx))
for(i in 1:dim(F)[1]){
  Falt[i,c(idx[i],idx[i]+max(idx))] <- F[i,]
}
##and compute F*sigmaB*F' using full matrices
sigma.B <- make.sigma.B(c(2,1), c(.3,1), D)
FsigmaF.alt <- Falt %*% sigma.B %*% t(Falt)

##compare the results
range(FsigmaF - FsigmaF.alt)
if( max(abs(FsigmaF - FsigmaF.alt)) > 1e-10 ){
  stop("make.sigma.B.full: Results not equal.")
}
##use the function to compute a cross covariance
FsigmaF.cross <- make.sigma.B.full(c(2,1), c(.3,1), loc.ind1=idx[1:6],
      loc.ind2=idx[7:13], F1=F[1:6,], F2=F[7:13,], dists=D)

##compare to the relevant part of the full matrix
range(FsigmaF.cross-FsigmaF[1:6,7:13])
if( max(abs(FsigmaF.cross-FsigmaF[1:6,7:13])) > 1e-10 ){
  stop("make.sigma.B.full: Results not equal - cross-covariance")
}

Run the code above in your browser using DataLab