View source: R/optimizeParams.R
| optimizeParams | R Documentation |
Given a dense depth dataset, determine what point spacing the data can be rarified to, and what DEM cell resolution to interpolate at, without meaningfully losing accuracy. Unlike samplingDensity(), this works directly with measuremed depth data: at every combination of candidate rarefaction spacing and candidate DEM resolution, the data are thinned with rarify() and scored with crossValidate(), building an RMSE surface across the full spacing x resolution grid.
optimizeParams(
outline,
df,
x,
y,
z,
spacings,
res_values,
k = 5,
zeros = FALSE,
separation = NULL,
method = "IDW",
nmax = 20,
idp = 2,
model = "Sph",
psill = NULL,
range = NULL,
nugget = NULL,
kappa = NULL,
trend_order = 1,
zero_threshold = 0.05,
tolerance = 0.1,
plot = TRUE,
seed = NULL
)
outline |
shapefile outline of a waterbody. Accepts a SpatVector, an sf object, or anything terra::vect() can read. |
df |
dataframe of coordinates and depths for a given waterbody. Coordinates are assumed to be in the same CRS as 'outline'. |
x |
character giving name of longitude column |
y |
character giving name of latitude column |
z |
character giving name of depth column |
spacings |
numeric vector of candidate rarify() target spacings to test, in meters. |
res_values |
numeric vector of candidate DEM cell resolutions to test, in meters. |
k |
numeric value describing the number of cross-validation folds to use at each grid point, default = 5 |
zeros |
logical describing if bounding zeros are needed (FALSE) or provided (TRUE), default = FALSE |
separation |
number describing distance between boundary points, in meters (required if zeros = FALSE) |
method |
character describing method of interpolation, "IDW", "OK", or "UK. Default = "IDW" |
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', 'Mat', 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 |
trend_order |
numeric value (1 or 2) giving the order of the polynomial trend surface fit for Universal Kriging. 1 = linear trend (z ~ x + y), 2 = quadratic trend. Default = 1. |
zero_threshold |
numeric proportion (0-1) of the waterbody's surface area that must interpolate to exactly 0 before the automatic zero re-interpolation pass runs, default = 0.05 (5%). A handful of scattered zero cells won't trigger it; a large contiguous block collapsing to zero (typically an interpolation artifact, often from the shoreline zero ring dominating a narrow bay or inlet) will. |
tolerance |
numeric value (proportion) used to pick the recommended (spacing, resolution) pair: among all grid points whose mean RMSE is within 'tolerance' of the single best (lowest-RMSE) grid point, the coarsest spacing is chosen (ties broken by coarsest resolution). Default = 0.1 (10%). |
plot |
logical: should a diagnostic heatmap of RMSE across the spacing x resolution grid be drawn? Default = TRUE. |
seed |
optional numeric value used to seed the random number generator (fold assignment in crossValidate() is stochastic), for reproducible results across runs. Default = NULL (not seeded). |
Runtime scales with length(spacings) x length(res_values) x k, since each grid point runs a full crossValidate() call (which itself fits k separate DEMs). Start with a small grid (e.g. 3x3) to confirm the analysis runs end-to-end before scaling up to a finer search.
a list with:
a data frame of spacing, res, mean RMSE, and the number of points remaining after rarefaction at each spacing
the recommended rarefaction spacing, in meters
the recommended DEM cell resolution, in meters
Tristan Blechinger, Department of Zoology & Physiology, University of Wyoming
outline <- terra::vect(system.file("extdata", "example_outline.shp", package = 'rLakeHabitat'))
data <- read.csv(system.file("extdata", "example_depths.csv", package = 'rLakeHabitat'))
optimizeParams(outline, data, "x", "y", "z", spacings = c(10, 25, 50),
res_values = c(5, 10, 20), seed = 123)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.