rtopKrige  R Documentation 
rtopKrige perform spatial interpolation or cross validation of data with areal support.
## S3 method for class 'rtop'
rtopKrige(object, varMatUpdate = FALSE, params = list(), ...)
## S3 method for class 'SpatialPolygonsDataFrame'
rtopKrige(object, predictionLocations = NULL,
varMatObs, varMatPredObs, varMat, params = list(),
formulaString, sel, ...)
## S3 method for class 'STSDF'
rtopKrige(object, predictionLocations = NULL,
varMatObs, varMatPredObs, varMat, params = list(),
formulaString, sel, olags = NULL, plags = NULL,
lagExact = TRUE, ...)
## Default S3 method:
rtopKrige(object, predictionLocations = NULL,
varMatObs, varMatPredObs, varMat, params = list(),
formulaString, sel, wret = FALSE, ...)
object 
object of class 
varMatUpdate 
logical; if TRUE, also existing variance matrices will
be recomputed, if FALSE, only missing variance matrices will be computed,
see also 
predictionLocations 

varMatObs 
covariance matrix of observations, where diagonal must consist
of internal variance, typically generated from call
to 
varMatPredObs 
covariance matrix between observation locations and
prediction locations, typically generated from call
to 
varMat 
list covariance matrices including the two above 
params 
a set of parameters, used to modify the default parameters for
the 
formulaString 
formula that defines the dependent variable as a linear model
of independent variables, see e.g. 
sel 
array of prediction location numbers, if only a limited number of locations are to be interpolated/crossvalidated 
wret 
logical; if TRUE, return a matrix of weights instead of the predictions, useful for batch processing of time series, see also details 
olags 
A vector describing the relative lag which should be applied for the observation locations. See also details 
plags 
A vector describing the relative lag which should be applied for the predicitonLocations. See also details 
lagExact 
logical; whether differences in lagtime should be computed exactly or approximate 
... 
from 
This function is the interpolation routine of the rtoppackage.
The simplest way of calling the function is with an rtopobject that
contains the fitted variogram model and all the other necessary data (see
createRtopObject
or rtoppackage
).
The function will, if called with covariance matrices between observations
and between observations and prediction locations, use these for the interpolation.
If the function is called without these matrices, varMat
will be
called to create them. These matrices can therefore be reused if necessary,
an advantage as it is computationally expensive to create them.
The interpolation that takes part within rtopKrige.default
is based on
the semivariance matrices between observations and between observations and prediction
locations. It is therefore possible to use this function also to interpolate
data where the matrices have been created in other ways, e.g. based on distances
in physiographical space or distances along a stream.
The function returns the weights rather than the predictions if wret = TRUE
.
This is useful for batch processing of time series, e.g. once the weights are
created, they can be used to compute the interpolated values for each time step.
rtop is able to take some advantage of multiple CPUs, which can be invoked with the
parameter nclus
. When it gets a number larger than one, rtopKrige
will start a cluster with nclus
workers,
if the parallel
package has been installed.
The parameter singularSolve
can be used when some areas are almost completely overlapping. In this case, the discretization of them might be equal, and the covariances to other areas will also be equal. The kriging matrix will in this case be singular. When singularSolve = TRUE
, rtopKrige
will remove one of the neighbours, and instead work with the mean of the two observations. An overview of removed neighbours can be seen in the resulting object, under the name removed
.
Kriging of time series is possible when observations
and predictionLocations
are spatiotemporal objects of type STSDF
. The interpolation is
still spatial, in the sense that the regularisation of the variograms are just done
using the spatial extent of the observations, not a possible temporal extent, such as
done by Skoien and Bloschl (2007). However, it is possible to make predictions based on observations
from different time steps, through the use of the lagvectors. These vectors describe a typical "delay"
for each observation and prediction location. This delay could for runoff related variables be similar
to travel time to each gauging location. For a certain prediction location, earlier time steps would be picked for neighbours with shorter travel time and later time steps for neighbours with slower travel times.
The lagExact parameter indicates whether to use a weighted average of two time steps, or just the time step which is closest to the difference in lag times.
The use of lag times should in theory increase the computation time, but might, due to different computation methods, even speed up the computation when the number of neighbours to be used (parameter nmax) is small compared to the number of observations. If computation is slow, it can be useful to test olags = rep(0, dim(observations)[1]) and similar for predictionLocations.
If called with SpatialPolygonsDataFrame
, the function returns a
SpatialPolygonsDataFrame
with predictions, either at the
locations defined in
predictionLocations
, or as leaveoneout
crossvalidation predicitons at the same locations as in object if
cv = TRUE
If called with an rtopobject, the function returns the same object with the predictions added to the object.
Jon Olav Skoien
Skoien J. O., R. Merz, and G. Bloschl. Topkriging  geostatistics on stream networks. Hydrology and Earth System Sciences, 10:277287, 2006.
Skoien, J. O. and G. Bloschl. SpatioTemporal TopKriging of Runoff Time Series. Water Resources Research 43:W09419, 2007.
Skoien, J. O., Bloschl, G., Laaha, G., Pebesma, E., Parajka, J., Viglione, A., 2014. Rtop: An R package for interpolation of data with a variable spatial support, with an example from river networks. Computers & Geosciences, 67.
# The following command will download the complete example data set
# downloadRtopExampleData()
# observations$obs = observations$QSUMMER_OB/observations$AREASQKM
rpath = system.file("extdata",package="rtop")
library(sf)
observations = st_read(rpath, "observations")
predictionLocations = st_read(rpath,"predictionLocations")
# Setting some parameters; nclus > 1 will start a cluster with nclus
# workers for parallel processing
params = list(gDist = TRUE, cloud = FALSE, nclus = 1, rresol = 25)
# Create a column with the specific runoff:
observations$obs = observations$QSUMMER_OB/observations$AREASQKM
# Build an object
rtopObj = createRtopObject(observations, predictionLocations,
params = params)
# Fit a variogram (function also creates it)
rtopObj = rtopFitVariogram(rtopObj)
# Predicting at prediction locations
rtopObj = rtopKrige(rtopObj)
# Crossvalidation
rtopObj = rtopKrige(rtopObj,cv=TRUE)
cor(rtopObj$predictions$observed,rtopObj$predictions$var1.pred)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.