View source: R/crossValidate.R
crossValidate | R Documentation |
Obtain residual mean square error (RMSE) from K-fold cross validation of bathymetry interpolation.
crossValidate(
outline,
df,
x,
y,
z,
zeros = FALSE,
separation = NULL,
k = 5,
crsUnits = "dd",
res = 5,
method = "IDW",
fact = NULL,
nmax = 20,
idp = 2,
model = "Sph",
psill = NULL,
range = NULL,
nugget = 0,
kappa = NULL
)
outline |
shapefile outline of a waterbody |
df |
dataframe of coordinates and depths for a given waterbody |
x |
character giving name of longitude column |
y |
character giving name of latitude column |
z |
character giving name of depth column |
zeros |
logical describing if bounding zeros are needed (FALSE) or provided (TRUE), default = FALSE |
separation |
number describing distance between points, units from CRS |
k |
numeric value describing the number of folds to test, default = 5 |
crsUnits |
character describing CRS units of input outline, either "dd" (decimal degrees) or "m" (meters), default = "dd" |
res |
number describing desired cell resolution in meters, default = 5 |
method |
character describing method of interpolation, options include Inverse Distance Weighted ("IDW") or Ordinary Kriging ("OK"). Default = "IDW" |
fact |
numeric value describing the factor by which raster resolution should be increased, default = NULL. If 'crsUnits' and 'res' are defined, fact = NULL |
nmax |
numeric value describing number of neighbors used in interpolation, default = 20 |
idp |
numeric value describing inverse distance power value for IDW interpolation |
model |
character describing type of model used in Ordinary Kriging, options include 'Sph', 'Exp', 'Gau', 'Sta', default = 'Sph' |
psill |
numeric value describing the partial sill value for OK interpolation, default = NULL |
range |
numeric describing distance beyond which there is no spatial correlation in Ordinary Kriging models, default = NULL |
nugget |
numeric describing variance at zero distance in Ordinary Kriging models, default = 0 |
kappa |
numeric value describing model smoothness, default = NULL |
If both 'crsUnit' and 'res' = NULL, the output raster will be in the same CRS and units as the input 'outline' and the resolution will be increased by 'fact' (default = 10). If both 'crsUnit' and 'res' are defined, fact = NULL and the output raster will be projected to the most appropriate UTM zone at the specified resolution.
For the model argument there are four different methods included here that are supported by gstat::vgm ("Sph", "Exp", "Gau", "Mat"). "Sph" = The default gstat::vgm method. Spherical model characterized by a curve that rises steeply to defined range then flattens, indicates no spatial correlation between points beyond that range. "Exp" = Exponential model characterized by spatial correlation decaying with distance. "Gau" = Gaussian model similar to spatial model but with stronger decay at shorter distances. "Mat" = Matern model Three parameters (psill, range, kappa) are incorporated from a fitted variogram (default = NULL). If specified in function input, chosen values will overwrite variogram values.
mean RMSE value across k number of folds
Tristan Blechinger, Department of Zoology & Physiology, University of Wyoming
#load example outline
outline <- terra::vect(system.file("extdata", "example_outline.shp", package = 'rLakeHabitat'))
#load example xyz data
data <- read.csv(system.file("extdata", "example_depths.csv", package = 'rLakeHabitat'))
#run function
crossValidate(outline, data, "x", "y", "z", zeros = FALSE, separation = 10, k = 5, crsUnit = "dd",
res = 50, method = "IDW", nmax = 4, idp = 1.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.