| offGridWeights {fields} | R Documentation |
Based on a stationary Gaussian process model creates a sparse matrix to predict off grid values (aka interpoltate) from an equally spaced rectangular grid. The sparsity comes about because only a fixed number of neighboring grid points (np) are used in the prediction. The prediction variance is also give in the returned object. This function is used as the basis for approximate conditional simulation for large spatial datasets.
offGridWeights(s, gridList, np = 2, mKrigObject = NULL, Covariance = NULL, covArgs = NULL, aRange = NULL, sigma2 = NULL, giveWarnings = TRUE, debug=FALSE)
s |
Off grid spatial locations |
gridList |
A list as the gridList format ( x and y components) that describes the rectagular grid. The grid must have at least np extra grid points beyond the range of the points in |
np |
Number of nearest neighbor grid points to use for prediction. |
mKrigObject |
The output object (aka list) from either mKrig or spatialProcess. This has the information about the covariance function used to do the Kriging. The following items are coded in place of not supplying this object. See the example below for more details. |
Covariance |
The stationary covariance function (taking pairwise distances as its first argument.) |
covArgs |
If |
aRange |
The range parameter. |
sigma2 |
Marginal variance of the process. |
giveWarnings |
If TRUE will warn if two or more observations are in the same grid box. See details below. |
debug |
If TRUE returns intermediate calculations and structures for debugging and checking. |
This function creates the interpolation weights taking advantage of some efficiency in the covariance function being stationary, use of a fixed configuration of nearest neighbors, and Kriging predictions from a rectangular grid.
The returned matrix is in spam sparse matrix format. See example below for the "one-liner" to make the prediction once the weights are computed. Although created primarily for conditional simulation of a spatial process this function is also useful for interpolating to off grid locations from a rectangular field.
The interpolation errors are also computed based on the nearest neighbor
predictions. This is returned as a sparse matrix in the component SE.
If all observations are in different grid boxes then SE is diagonal
and agrees with the square root of the component predctionVariance but
if multiple observations are in the same grid box then SE has blocks of upper
triangular matrices that can be used to simulate the prediction error
dependence among observations in the same grid box.
Explicitly if obj is the output object and there are nObs
observations then
error <- obj$SE%*% rnorm( nObs)
will simulate a prediction error that includes the dependence. Note that in the case that there all observations are in separate grid boxes this code line is the same as
error <- sqrt(obj$predictionVariance)*rnorm( nObs)
It is always true that the prediction variance is given by
diag( obj$SE%*% t( obj$SE)).
The user is also referred to the testing scripts
offGridWeights.test.R and
offGridWeights.testNEW.Rin tests where the
Kriging predictions and standard errorsa are computed explicitly and tested against the sparse
matrix computation. This is helpful in defining exactly what
is being computed.
B |
A sparse matrix that is of dimension mXn with m the number of locations (rows) in |
predictionVariance |
A vector of length as the rows of |
SE |
A sparse matrix that can be used to simulate dependence among prediction errors for observations in the same grid box. (See explanation above.) |
Douglas Nychka and Maggie Bailey
# an M by M grid
M<- 400
xGrid<- seq( -1, 1, length.out=M)
gridList<- list( x= xGrid,
y= xGrid
)
np<- 3
n<- 100
# sample n locations but avoid margins
set.seed(123)
s<- matrix( runif(n*2, xGrid[(np+1)],xGrid[(M-np)]),
n, 2 )
obj<- offGridWeights( s, gridList, np=3,
Covariance="Matern",
aRange = .1, sigma2= 1.0,
covArgs= list( smoothness=1.0)
)
# make the predictions by obj$B%*%c(y)
# where y is the matrix of values on the grid
# try it out on a simulated Matern field
CEobj<- circulantEmbeddingSetup( gridList,
cov.args=list(
Covariance="Matern",
aRange = .1,
smoothness=1.0)
)
set.seed( 333)
Z<- circulantEmbedding(CEobj)
#
# Note that grid values are "unrolled" as a vector
# for multiplication
# predOffGrid<- obj$B%*% c( Z)
predOffGrid<- obj$B%*% c( Z)
set.panel( 1,2)
zr<- range( c(Z))
image.plot(gridList$x, gridList$y, Z, zlim=zr)
bubblePlot( s[,1],s[,2], z= predOffGrid , size=.5,
highlight=FALSE, zlim=zr)
set.panel()