The function preCKrige
computes (approximated) spatial
variance-covariance matrices for user-defined sets of points or polygons
(blocks) of any shape for two-dimensional isotropic random fields. The
areas of a set of polygons (polygon neighbourhood configuration) are
approximated by pixels and the block-block covariances are approximated by
averaging covariances between the pixels used to approximate the polygons.
The object returned by preCKrige
is needed by CKrige
for computing spatial point or block predictions by constrained,
covariance-matching constrained or universal (external drift) Kriging.
preCKrige(newdata, neighbours, model, ...)
# S4 method for SpatialPoints,ANY,covmodel
preCKrige(newdata, neighbours, model)
# S4 method for SpatialPointsDataFrame,ANY,covmodel
preCKrige(newdata, neighbours, model)
# S4 method for SpatialPolygons,ANY,covmodel
preCKrige(newdata, neighbours, model,
pwidth = 0, pheight = 0, napp = 1, ncores = 1L,
fork = !identical( .Platform[["OS.type"]], "windows"))
# S4 method for SpatialPolygonsDataFrame,ANY,covmodel
preCKrige(newdata, neighbours,
model, pwidth = 0, pheight = 0, napp = 1, ncores = 1L,
fork = !identical( .Platform[["OS.type"]], "windows"))
preCKrige
returns an S4 object, either of class
“preCKrigePolygons
” if
newdata
is of class
“SpatialPolygons
” or
“SpatialPolygonsDataFrame
” or an S4 object of class
“preCKrigePoints
” if
newdata
is of class “SpatialPoints
” or
“SpatialPointsDataFrame
”.
Notation:
\(n\) | number of polygons or points in newdata ,
i = 1, ..., \(n\) |
\(m_i\) | size of point or polygon neighbourhood configuration |
\(m_i\) = 1 + number of (defined) neighbours of the ith point or ith polygon | |
\(r_{\mathrm{pix}}\) | number of pixel grid rows |
\(c_{\mathrm{pix}}\) | number of pixel grid columns |
\(n_{\mathrm{pix}}\) | number of pixels in pixel grid \(n_{\mathrm{pix}} = r_{\mathrm{pix}} \cdot c_{\mathrm{pix}}\) |
An object of class “preCKrigePoints
” contains the
following slots:
a list of length \(n\), the \(i\)th list component contains the point-point covariance matrix of the \(i\)th prediction point and its neighbours, i.e. of the \(i\)th point neighbourhood configuration.
a list of length \(n\), the \(i\)th list component contains a vector with the row indices of the \(m_i - 1\) neighbours in the \(i\)th point neighbourhood configuration.
an object of class “covmodel
” with the
parameters of the used covariance function.
a data frame, which is the data
slot of the
SpatialPointsDataFrame
object. This data frame is used to
build the design matrix of the prediction points by the
CKrige
function. data
is empty with
dim(data)
= (0, 0) if newdata
is an object of class
“SpatialPoints
”.
a matrix with dim(coords)
= (\(n\), 2) with the
coordinates of the prediction points.
An object of class “preCKrigePolygons
” contains the
following slots:
a list of length \(n\), the \(i\)th list component contains the approximated block-block covariance matrix of the \(i\)th polygon and its neighbours, i.e. of the \(i\)th polygon neighbourhood configuration.
a list of length \(n\), the \(i\)th list
component contains a matrix with the standard errors of the
approximated block-block covariances of the \(i\)th polygon
neighbourhood configuration. Values are equal to NaN
for
argument napp = 1
, see Details.
a list of lists of length \(n\), the \(i\)th list
component contains a list with the information about the pixels used
for the covariance approximation of the \(i\)th polygon
neighbourhood configuration. The components of pixconfig
are
described below.
a matrix, dim(matrix)
=
(\(n_{\mathrm{pix}}\), \(n_{\mathrm{pix}}\) ), with
the covariance matrix of the pixels.
an object of class “covmodel
” with the
parameters of the used covariance function.
a data frame which is the data
slot of the
SpatialPolygonsDataFrame
object. This data frame is used to
build the design matrix of the prediction polygons by the
CKrige
function. data
is empty with
dim(data)
= (0, 0) if newdata
is an object of class
“SpatialPolygons
”.
a SpatialPolygons
object. A list of length
\(n\) with the polygons of the newdata
object.
The \(i\)th component of pixconfig
is a list with the
following 10 components:
a matrix with dim(pixcenter)
=
(\(n_{\mathrm{pix}}\), 2) with the coordinates of the pixels
centroids for the \(i\)th polygon neighbourhood configuration.
preCKrige
input argument pheight
.
preCKrige
input argument pwidth
.
a numeric scalar with number of rows \(r_{\mathrm{pix}}\) of the pixel grid.
a numeric scalar with number of columns \(c_{\mathrm{pix}}\) of the pixel grid.
a numeric vector of length \(m_i\), each number indicates by how many pixels a polygon of the \(i\)th polygon configuration is approximated.
a logical vector of length \(m_i\), TRUE means that the \(i\)th polygon is treated as a point because its area is smaller than the area of a pixel, and FALSE means that the polygon is approximated by pixels, see Note for more details.
a matrix with dim(polygon.centroids)
=
(\(m_i\), 2) with the coordinates of the polygon centroids of the
\(i\)th polygon neighbourhood configuration.
an integer vector of length \(m_i\) with indices of
the \(i\)th polygon and its neighbours as defined by the argument
neighbours
.
is a binary matrix with dim(pix.in.poly)
=
(\(n_{\mathrm{pix}}\), \(m_i\)). pix.in.poly[k, j] = 1
indicates that the centroid of the kth pixel lies in the
jth polygon, and pix.in.poly[k, j] = 0
indicates that the
kth pixel centroid does not lie in the jth
polygon.
either an object of the class
“SpatialPointsDataFrame
”
or “SpatialPoints
” that contains the coordinates of the
prediction points and optionally additional information (covariates) stored
in the data
slot of the SpatialPointsDataFrame
,
or an object of the class “SpatialPolygonsDataFrame
” or
“SpatialPolygons
”
with the coordinates of the polygons (blocks) for which predictions are
computed and optionally additional information (covariates) stored in the
data
slot of the
SpatialPolygonsDataFrame
.
a list of length n with integer vectors as
components. n is equal to the number of points if
newdata
is an object of class
“SpatialPointsDataFrame
” or
“SpatialPoints
” or equal to number of polygons (blocks)
if newdata
is an object of class
“SpatialPolygonsDataFrame
” or
“SpatialPolygons
”.
The ith list component defines the neighbours of the ith
point or ith polygon (block) in newdata
, which form
jointly with the ith point or polygon the so-called point
or polygon neighbourhood configuration. If newdata
is
an object of class “SpatialPolygonsDataFrame
” or
“SpatialPolygons
” the ith list component contains
the indices of the neighbouring polygons for the ith polygon.
If newdata
is an object of class “SpatialPoints
”
or “SpatialPointsDataFrame
” the ith list component
contains the row indices of the neighbouring points in the point
coordinate matrix. The ith list component is set to
integer(0)
if the ith polygon or ith point have no
(defined) neighbours. By default, the points or polygons have no
neighbours.
See the second example below where the function poly2nb
of the
package spdep is used to build a list of neighbours for target
polygons of the data set meuse.blocks
.
an object of class “covmodel
”. The object
contains the parameters of the isotropic covariance function,
generated by the function covmodel
.
further arguments if newdata
is of class
“SpatialPolygonsDataFrame
” or
“SpatialPolygons
”.
a positive numeric scalar, defines the width of the pixels used to approximate the polygon (block) areas.
a positive numeric scalar, defines the height of the pixels used to approximate the polygon (block) areas.
a positive integer scalar. napp
> 1 reduces the
block-block variance-covariance approximation error. By default,
napp
= 1, see Details.
a positive integer scalar with the number of CPUs to use for parallel computations.
Christoph Hofer, christoph.hofer@alumni.ethz.ch
If the object newdata
is of class
“SpatialPolygonsDataFrame
” or
“SpatialPolygons
” then
preCKrige
searches the
polygon neighbourhood configuration (defined by neighbours
)
with the largest bounding box and generates a pixel grid that
completely covers the largest bounding box. Subsequently, the
covariance matrix of this set of pixels is calculated by the
spatialCovariance package and the polygon (block) areas of each
polygon neighbourhood configuration are approximated by intersecting
the polygons with the shifted pixel grid, which yields a pixel
representation of the polygon neighbourhood configuration. Finally,
the block-block covariances of the polygons are approximated by
averaging the covariances of the pixel representation of the
polygon neighbourhood configuration.
By default, napp = 1
, which means that the approximation of the
block-block variance-covariance matrix for each polygon neighbourhood
configuration is computed just once. If napp
> 1 the
approximation of the block-block variance-covariance matrix for one
polygon neighbourhood configuration is based on the mean of
napp
repetitions of the approximation to reduce the
approximation error. Each of the napp
block-block
variance-covariance approximations are based on a new, randomly
shifted pixel gird which results each time in a new pixel
representation of the polygon neighbourhood configuration. Large
values of the argument napp
increases the computation time.
There is a plot method plot.preCKrigePolygons
for
preCKrige
output objects of class
“preCKrigePolygons
” to visually control the polygon
(block) area approximation by the pixels.
Hofer, C. and Papritz, A. (2011). constrainedKriging: an R-package for customary, constrained and covariance-matching constrained point or block Kriging. Computers & Geosciences. 37, 1562--1569, tools:::Rd_expr_doi("10.1016/j.cageo.2011.02.009")
CKrige
# \donttest{
### first example
### load data
data(meuse, package = "sp")
data(meuse.blocks)
### plot blocks
plot(meuse.blocks)
### compute the approximated block variance of each block in meuse.blocks
### without any neighbouring blocks (default, required for in universal
### and constrained Kriging) for an exponential covariance function without
### a measurement error, a nugget = 0.15 (micro scale white noise process),
### a partial sill variance = 0.15 and a scale parameter = 192.5
### approximation of block variance by pixel of size 75m x 75m
preCK_1 <- preCKrige(newdata = meuse.blocks, model = covmodel(modelname =
"exponential", mev = 0, nugget = 0.05, variance = 0.15,
scale = 192.5), pwidth = 75, pheight = 75)
### plot block approximation for block 59
plot(preCK_1, 59)
### second example
### define neighbours by using the poly2nb function
### of the spdep package
if(!requireNamespace("spdep", quietly = TRUE)){
stop("install package spdep to run example")
}
neighbours <- spdep::poly2nb(meuse.blocks)
class(neighbours)
### neighbours should be an object of class "list"
class(neighbours) <- "list"
### compute the approximated block variance-covariance
### matrices of each block in meuse.blocks without the
### defined block neighbours
preCK_2 <- preCKrige(newdata = meuse.blocks, neighbours = neighbours,
model = covmodel("exponential", nugget = 0.05, variance = 0.15,
scale = 192.5), pwidth = 75, pheight = 75)
### plot block approximation of block 59 and its
### block neighbours
plot(preCK_2, 59)
# }
Run the code above in your browser using DataLab