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
x
with values to interpolate. IfNULL
and ifx
is 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 aGRaster
or 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 aGRaster
with interpolated values. IfFALSE
, return a table withlambda
values from cross-validation. This argument is ignored iflambda
is a numeric value.- verbose
Logical: if
TRUE
, display progress.
Value
Output depends on values of lambda
and interpolate
:
lambda
isNULL
andinterpolate
isTRUE
: AGRaster
with an attribute namedlambdas
. This is adata.frame
with values oflambda
that were assessed, plusmean
(mean residual value) andrms
(root mean square error). You can see the table usingattr(output_raster, "lambdas", exact = TRUE)
.lambda
isNULL
andinterpolate
isFALSE
: Adata.frame
with values oflambdas
that were assessed, plusmean
(mean residual value) andrms
(root mean square error). You can see the table usingattr(output_raster, "lambdas", exact = TRUE)
.lambda
is a number (interpolate
is 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 module v.surf.bspline
(see grassHelp("v.surf.bspline")
)