Repository navigation
Conversation
blockCV::cv_cluster() fails ("The input raster layer does not cover all
the column points") when an occurrence point falls on a cell without
predictor values, for example on a coast. New sdmApp_cluster_folds()
clusters the points that have values and gives the others no fold
(NA), which models ignore; folds_list still refers to rows of the
occurrences. It also seeds the clustering, as cv_cluster() ignores its
seed for point data. The interface, the R-Code tab and the workflow
vignette use it; with complete data the folds are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Building environmental cross-validation folds (Spatial Analysis > Cross-validation folds > Environmental clusters) failed when any occurrence point fell on a cell without predictor values, for example on a coastline or at the edge of the rasters:
Such points are common with GBIF data at continental scale. I found the bug while modelling Faidherbia albida across Africa for the sdmApp manuscript's case study. Spatial blocks weren't affected, and
sdmApp_fit()already silently drops points without values, so only environmental folds were broken.Fix
A new exported function,
sdmApp_cluster_folds(occ, env, column, k = 5, seed = 1994):blockCV::cv_cluster()on the points that have predictor values only.occ.folds_idshas one entry per point,NAfor points without values, whichsdmApp_fit()andsdmApp_tune()ignore.folds_listrefers to rows ofocc, socv_plot(), the fold explorer and fold summaries keep working.set.seed(), becausecv_cluster()doesn't use itsseedargument for point data (see Cross-validate on environmental clusters #18). It returns the number of points left out in$dropped.Callers:
blocks <- sdmApp_cluster_folds(occ, env, "...", k = ...)instead ofset.seed()plusblockCV::cv_cluster().With complete data the folds are identical to before, so existing results and scripts don't change.
Testing
test-sdmApp_cluster_folds.R:folds_idsandfolds_listare identical toset.seed(1994); blockCV::cv_cluster(...), and reproducible;NA,droppedis 1, andfolds_listrefers to rows of the occurrences without that point, consistent withfolds_ids. A GLM fits on the folds (3 folds evaluated) and the fold explorer draws them;sdmApp_cluster_folds(). It still reproduces the samefolds_idsand fold metrics.devtools::test(): 109 tests, 552 expectations, 0 failed, 0 skipped.lintr: no lints.spelling: no errors.🤖 Generated with Claude Code