rtopKrige: Spatial interpolation of data with spatial support

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/zzz.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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

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 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 standard 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.

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, setting this larger than one will start a cluster with nclus workers, if the parallel-package has been installed.

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.

See Also

rtop-package

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Not run: 
library(rgdal)
# The following command will download  the complete example data set
# downloadRtopExampleData() 
# observations$obs = observations$QSUMMER_OB/observations$AREASQKM

rpath = system.file("extdata",package="rtop")
observations = readOGR(rpath,"observations")
predictionLocations = readOGR(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)

## End(Not run)

Example output

Loading required package: sp
rgdal: version: 1.5-18, (SVN revision 1082)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: /usr/share/gdal
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: /usr/share/proj
Linking to sp version:1.4-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
OGR data source with driver: ESRI Shapefile 
Source: "/usr/lib/R/site-library/rtop/extdata", layer: "observations"
with 57 features
It has 7 fields
Integer64 fields read as strings:  ID EZGID 
Warning message:
In OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS = dumpSRS,  :
  Discarded datum D_unknown in CRS definition: +proj=lcc +lat_0=47.5 +lon_0=13.3333333333333 +lat_1=46 +lat_2=49 +x_0=400000 +y_0=400000 +ellps=bessel +units=m +no_defs
OGR data source with driver: ESRI Shapefile 
Source: "/usr/lib/R/site-library/rtop/extdata", layer: "predictionLocations"
with 235 features
It has 5 fields
Integer64 fields read as strings:  ID EZGID 
Warning message:
In OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS = dumpSRS,  :
  Discarded datum D_unknown in CRS definition: +proj=lcc +lat_0=47.5 +lon_0=13.3333333333333 +lat_1=46 +lat_2=49 +x_0=400000 +y_0=400000 +ellps=bessel +units=m +no_defs
There were 11 warnings (use warnings() to see them)
53 best 0.12 function convergence 200 parameter convergence 5613.188 
84 best 0.12 function convergence 200 parameter convergence 4265.434 
116 best 0.12 function convergence 200 parameter convergence 3449.938 
150 best 0.0992 function convergence 200 parameter convergence 2385.954 
185 best 0.0992 function convergence 200 parameter convergence 1755.65 
222 best 0.0976 function convergence 20.9 parameter convergence 1419.799 
264 best 0.0976 function convergence 20.9 parameter convergence 1090.699 
301 best 0.0975 function convergence 21 parameter convergence 709.7869 
337 best 0.0975 function convergence 1.7 parameter convergence 578.9492 
367 best 0.0975 function convergence 1.71 parameter convergence 371.6484 
403 best 0.0975 function convergence 0.0805 parameter convergence 312.9164 
431 best 0.0975 function convergence 0.0853 parameter convergence 274.4559 
459 best 0.0975 function convergence 0.0366 parameter convergence 229.985 
496 best 0.0975 function convergence 0.0455 parameter convergence 203.72 
528 best 0.0975 function convergence 0.0427 parameter convergence 186.8422 
555 best 0.0975 function convergence 0.0285 parameter convergence 110.3841 
580 best 0.0975 function convergence 0.0273 parameter convergence 86.28346 
605 best 0.0975 function convergence 0.0281 parameter convergence 81.99628 
632 best 0.0975 function convergence 0.0209 parameter convergence 51.42643 
659 best 0.0975 function convergence 0.0139 parameter convergence 39.7901 
686 best 0.0975 function convergence 0.00776 parameter convergence 23.88903 
711 best 0.0975 function convergence 0.00452 parameter convergence 14.34123 
736 best 0.0975 function convergence 0.00396 parameter convergence 13.54027 
761 best 0.0975 function convergence 0.00241 parameter convergence 11.81679 
786 best 0.0975 function convergence 0.00166 parameter convergence 10.92466 
812 best 0.0975 function convergence 0.000984 parameter convergence 9.069246 
837 best 0.0975 function convergence 0.00063 parameter convergence 7.525643 
862 best 0.0975 function convergence 0.000396 parameter convergence 9.061367 
887 best 0.0975 function convergence 0.000141 parameter convergence 9.944235 
912 best 0.0975 function convergence 7.98e-05 parameter convergence 6.58298 
938 best 0.0975 function convergence 7.05e-05 parameter convergence 5.917562 
964 best 0.0975 function convergence 5.99e-05 parameter convergence 4.794886 
989 best 0.0975 function convergence 5.19e-05 parameter convergence 3.289279 
1014 best 0.0975 function convergence 4.59e-05 parameter convergence 2.513841 
1040 best 0.0975 function convergence 2.98e-05 parameter convergence 1.701609 
1065 best 0.0975 function convergence 1.75e-05 parameter convergence 1.398814 
1090 best 0.0975 function convergence 1.1e-05 parameter convergence 1.421838 
1116 best 0.0975 function convergence 5.57e-06 parameter convergence 1.159297 
1143 best 0.0975 function convergence 2.83e-06 parameter convergence 0.7486387 
[1] "Sampling points from  57 areas"
[1] "Sampled on average 57.86 points from 57 areas"
[1] "Sampling points from  235 areas"
[1] "Sampled on average 52.68 points from 235 areas"
[1] "Creating prediction semivariance matrix. This can take some time."
[1] "interpolating  235 areas"
[1] "cross-validating 57 areas"
[1] 0.7507919

rtop documentation built on May 2, 2019, 6:48 p.m.