This function interpolates values in the data table of a "points" GVector to a GRaster using splines with Tykhonov regularization to avoid overfitting.
Usage
# S4 method for class 'GVector,GRaster'
interpSplines(
x,
y,
field,
method = "bilinear",
lambda = NULL,
solver = "Cholesky",
xlength = NULL,
ylength = NULL,
interpolate = TRUE,
verbose = is.null(lambda)
)Arguments
- x
A "points"
GVector.- y
A
GRaster: The output will have the same extent and resolution as this raster.- field
Character or integer or numeric integer: Name or index of the column in
xwith values to interpolate. IfNULLand ifxis a 3-dimensional "points"GVector, then the interpolation will act on the z-coordinate of each point.- method
Character: The method to use for interpolation can be either
"bilinear"(default) or"bicubic". Partial matching is used.- lambda
Either
NULL(default) or numeric value > 0: The Tykhonov regularization parameter. IfNULL, cross-validation will be used to determine the optimal parameter value. Cross-validation can take quite a while. If you use cross-validation, the output will either be aGRasteror adata.frame, depending on the value ofinterpolate.- solver
Character: Type of solver to use. Can be either of
"Cholesky"or"cg". Partial matching is used and case is ignored.- xlength, ylength
Either
NULL(default), or numeric > 0: Length of the spline step in the x- and y-directions. IfNULL, these will be set to 4 times the length of the extent in the respective direction.- interpolate
Logical: If
TRUE(default), then create aGRasterwith interpolated values. IfFALSE, return a table withlambdavalues from cross-validation. This argument is ignored iflambdais a numeric value.- verbose
Logical: if
TRUE, display progress.
Value
Output depends on values of lambda and interpolate:
lambdaisNULLandinterpolateisTRUE: AGRasterwith an attribute namedlambdas. This is adata.framewith values oflambdathat were assessed, plusmean(mean residual value) andrms(root mean square error). You can see the table usingattr(output_raster, "lambdas", exact = TRUE).lambdaisNULLandinterpolateisFALSE: Adata.framewith values oflambdasthat were assessed, plusmean(mean residual value) andrms(root mean square error). You can see the table usingattr(output_raster, "lambdas", exact = TRUE).lambdais a number (interpolateis ignored): AGRaster.
Details
If you receive the error, "No data within this subregion. Consider increasing spline step values, try increasing the values of xlength and ylength.
If cross-validation takes too long, or other warnings/errors persist, you can randomly subsample x to ~100 points to get an optimum value of lambda (using interpolate = FALSE), then use this value in the same function again without cross-validation (setting lambda equal to this value and interpolate = TRUE).
See also
interpIDW(), fillNAs(), GRASS tool v.surf.bspline (see grassHelp("v.surf.bspline"))
