##First create some random locations
x <- rnorm(5)
y <- rnorm(5)
##compute distance matrix
D <- as.matrix(dist( 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 using same sill, range, and nugget, but
##different locations in each block.
sigma.nu <- make.sigma.nu(sill=2, nugget=.1, range=.4,
block.sizes=c(3,2,4,1), dists=D, loc.index=I)
print(sigma.nu)
sigma.nu.c <- make.sigma.nu.cross.cov(sill=2, nugget=.1, range=.4,
loc.ind1=I, loc.ind2=I[7:10], T1=T, T2=T[7:10], dists=D)
print(sigma.nu.c)
##compare the cross-covariance with the relevant part of sigma.nu
range(sigma.nu.c-sigma.nu[,7:10])
if( abs(max(sigma.nu.c-sigma.nu[,7:10])) > 1e-10 ){
stop("make.sigma.nu.cross.cov 1: Results not equal")
}
##an alternative showing the use of loc.ind2.to.1
sigma.nu.c <- make.sigma.nu.cross.cov(sill=2, nugget=.1, range=.4,
loc.ind1=I, loc.ind2=1:2, loc.ind2.to.1=4:3,
T1=T, T2=c(3,3), dists=D[,4:3])
print(sigma.nu.c)
##compare the cross-covariance with the relevant part of sigma.nu
range(sigma.nu.c-sigma.nu[,6:7])
if( abs(max(sigma.nu.c-sigma.nu[,6:7])) > 1e-10 ){
stop("make.sigma.nu.cross.cov 1: Results not equal")
}
Run the code above in your browser using DataLab