| cv_to_waywiser | R Documentation |
sdmTMB_cv() objects to sf format for spatial assessment with waywiser
Converts cross-validation results to an
sf::sf() object for use with
spatial model assessment tools such as those in the waywiser package.
This enables multi-scale spatial assessment of model predictions.
cv_to_waywiser(
object,
ll_names = c("longitude", "latitude"),
ll_crs = 4326,
utm_crs = get_crs(object$data, ll_names)
)
object |
An object of class |
ll_names |
Column names for longitude and latitude in the original data. Note the order: longitude first, then latitude. |
ll_crs |
The coordinate reference system (CRS) for the |
utm_crs |
The projected coordinate reference system (CRS) for the output
sf object. By default (if you're feeling lucky!) automatically detected
using |
This function is particularly useful for assessing spatial models at multiple
scales using the waywiser package. After converting to sf format, you
can use functions like waywiser::ww_multi_scale() to evaluate how model
performance changes when predictions are aggregated to different spatial
scales.
For delta/hurdle models, the combined predictions are returned (e.g., the product of the encounter probability and positive catch rate).
An sf::sf() object with POINT geometry containing:
The observed response values
The cross-validated predictions
Spatial point locations
sdmTMB_cv(), get_crs(), https://sdmTMB.github.io/sdmTMB/articles/cross-validation.html
mesh <- make_mesh(pcod_2011, c("X", "Y"), cutoff = 12)
# Run cross-validation
set.seed(123)
m_cv <- sdmTMB_cv(
density ~ depth_scaled,
data = pcod_2011,
mesh = mesh,
family = tweedie(),
k_folds = 2
)
# Convert with default auto-detected CRS based on lon/lat columns:
cv_sf <- cv_to_waywiser(m_cv, ll_names = c("lon", "lat"))
# Or manually specify the desired UTM CRS:
cv_sf <- cv_to_waywiser(m_cv, ll_names = c("lon", "lat"), utm_crs = 32609)
# Use with waywiser for multi-scale assessment
waywiser::ww_multi_scale(
cv_sf,
truth, # column name (unquoted)
estimate, # column name (unquoted)
n = list(c(5, 5), c(2, 2)) # 5x5 and 2x2 grid blocks
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.