##First create some random locations
x <- rnorm(5)
y <- rnorm(5)
##compute distance matrix
D <- as.matrix(dist( cbind(x,y) ))
##create a block diagonal matrix consisting of three parts with
##different sill and range (nugget=0) and exponential covariance
##function
sill <- c(2,1,3)
range <- c(.3,1,.5)
make.sigma.B(sill, range, D)
B <- make.sigma.B(sill, range, D)
B.alt <- matrix(0,length(sill)*dim(D)[1],length(sill)*dim(D)[1])
for(i in 1:length(sill)){
B.alt[((i-1)*dim(D)[1]+1):(i*dim(D)[1]),((i-1)*dim(D)[1]+1):(i*dim(D)[1])] <- sill[i]*exp(-D/range[i])
}
if( abs(max(B-B.alt)) > 1e-10){
stop("make.sigma.B: Results not equal")
}
Run the code above in your browser using DataLab