rtopKrige: Spatial interpolation of data with spatial support

View source: R/zzz.R

rtopKrigeR Documentation

Spatial interpolation of data with spatial support

Description

rtopKrige perform spatial interpolation or cross validation of data with areal support.

Usage

## 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, ...) 



Arguments

object

object of class rtop or SpatialPolygonsDataFrame or STSDF

varMatUpdate

logical; if TRUE, also existing variance matrices will be recomputed, if FALSE, only missing variance matrices will be computed, see also varMat

predictionLocations

SpatialPolygons or SpatialPolygonsDataFrame or STSDF with prediction locations. NULL if cross validation is to be performed.

varMatObs

covariance matrix of observations, where diagonal must consist of internal variance, typically generated from call to varMat

varMatPredObs

covariance matrix between observation locations and prediction locations, typically generated from call to varMat

varMat

list covariance matrices including the two above

params

a set of parameters, used to modify the default parameters for the rtop package, set in getRtopParams. Additionally, it is possible overrule some of the parameters in object$params by passing them as separate arguments.

formulaString

formula that defines the dependent variable as a linear model of independent variables, see e.g. createRtopObject for more details.

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 rtopKrige.rtop, arguments to be passed to rtopKrige.default. In rtopKrige.default, parameters for modification of the object parameters or default parameters. Of particular interest are cv, a logical for doing cross-validation, nmax, and maxdist for maximum number of neighbours and maximum distance to neighbours, respectively, and wlim, the limit for the absolute values of the weights. It can also be useful to set singularSolve if some of the areas are almost similar, see also details below.

Details

This function is the interpolation routine of the rtop-package. The simplest way of calling the function is with an rtop-object that contains the fitted variogram model and all the other necessary data (see createRtopObject or rtop-package).

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 lag-vectors. 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.

Value

If called with SpatialPolygonsDataFrame, the function returns a
SpatialPolygonsDataFrame with predictions, either at the locations defined in
predictionLocations, or as leave-one-out cross-validation predicitons at the same locations as in object if cv = TRUE

If called with an rtop-object, the function returns the same object with the predictions added to the object.

Author(s)

Jon Olav Skoien

References

Skoien J. O., R. Merz, and G. Bloschl. Top-kriging - geostatistics on stream networks. Hydrology and Earth System Sciences, 10:277-287, 2006.

Skoien, J. O. and G. Bloschl. Spatio-Temporal Top-Kriging 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.

Examples


# 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)

# Cross-validation
rtopObj = rtopKrige(rtopObj,cv=TRUE)
cor(rtopObj$predictions$observed,rtopObj$predictions$var1.pred)


rtop documentation built on Nov. 2, 2023, 5:07 p.m.