- Added
cv_knndm, a k-fold Nearest Neighbour Distance Matching method with"blocks","hierarchical", and"kmeans"clustering options. It supports geographical and feature-space matching viaspace, and accepts prediction points viar,pred_points, ormodel_domain; issue #63. - Added
cv_distance, a diagnostic for comparing an existingblockCVfold design with the nearest-neighbour distance distribution expected in the prediction domain. It returns acv_distanceobject carrying the per-fold test-to-nearest-train distance table in$distances, the Wasserstein-1 distances in$W, and the plot in$plot; aplotargument (defaultTRUE) controls only whether the plot is drawn. - Added
cv_summary, a one-call fold-quality diagnostic that gathers fold sizes and class prevalence, thecv_distanceandcv_similaritydiagnostics (when a raster or prediction domain is supplied), and a data.frame of warnings about degenerate folds (empty or single-class test folds, classes missing from training, tiny folds, severe class imbalance, and high leakage). - Added
cv_group, a leave-group-out cross-validation using an existing grouping column (e.g. site, plot, campaign, or individual) so records that share a group are never split across train and test.k = NULLgives one fold per group; a smallerkmerges the groups intokfolds, optionally balanced (balance = TRUE). - Added
balanceto make fold balancing explicit incv_spatial,cv_cluster, andcv_knndm.cv_cluster(balance = FALSE)keeps the previous single k-means behaviour;balance = TRUEuses the newk_multiplierargument to create candidate clusters for more even folds; issue #34. - Added presence-background balancing support so
cv_spatial,cv_cluster, andcv_knndmcan base fold balancing or matching on presences, preventing background points from dominating the split. - Added
spatial_weighttocv_clusterfor spatially-constrained environmental clustering. It adds a soft spatial compactness pressure by blending the (standardised) coordinates into the covariates before k-means, so the Euclidean distance becomes(1 - w) * d_env^2 + w * d_geo^2.spatial_weight = 0(default) keeps the previous pure-environmental behaviour exactly, larger values give environmentally coherent folds that are also geographically separated, and1clusters on the coordinates alone. - Added support for continuous or count
columnvalues incv_spatial,cv_cluster,cv_buffer,cv_nndm, andcv_knndm. Numeric columns are binned withnum_bins(default4) for fold balancing and records reports;num_bins = NULLrestores per-value handling. - Added
combine_foldsandfold_colorstocv_plotfor single-map fold plots incv_spatial,cv_cluster,cv_group, andcv_knndm. - Added
bg_alphatocv_plotto control the opacity of background points in presence-background fold plots; it is capped atpoints_alpha(with a warning) so the background is never drawn more prominent than the presences, and the "background shown faded" caption appears only when the background is actually more transparent. - Added
species_pb.csv, a presence-background example dataset used in thecv_buffer()andcv_cluster()examples. - Added a second tutorial covering
cv_summary,cv_similarity,cv_distance, and block-size selection withcv_spatial_autocorandcv_block_size. - Added a fourth tutorial showing how to use
blockCVfolds withcaret::trainControl()viaindexandindexOut; issue #48.
- The minimum R version is now 3.6.0.
- Renamed the
num_plotargument ofcv_similaritytonum_plots, for consistency withcv_plot(a breaking change for existing code that setnum_plot). - Removed the
spdependency (a retiring package) fromcv_spatial_autocor. Longlat inputs now pass an explicit great-circle cutoff toautomap::autofitVariograminstead of being converted to aspobject, soautomap (>= 1.1-20)is now required. - Reworked the fold-balancing search behind
cv_spatial(random selection) and nowcv_cluster(balance = TRUE). The objective is now scored on the test folds only and normalised per class (a Pearson chi-square against an equal split), and it minimises empty test cells for classes with at leastkrecords before minimising imbalance. This replaces the previous rule (raise the smallest cell, then lower the standard deviation of all train and test cells at once), which could keep a split that leaves a class missing from a test fold and let an abundant class dominate the score. Because a different candidate assignment now wins, folds for a givenseedmay differ from earlier versions. cv_similaritynow computes presence-background similarity from presences only, matchingcv_distance, and addsseedfor reproducible random baselines. L1/L2 distance-based scores now handle single-layer rasters, single-point folds, missing covariates, and constant predictors more robustly, and the MESS score now guards constant (zero-range) predictors.cv_similarityalso validates that the rows ofxline up with the fold indices incv, matchingcv_distance.- Reports, plots, and progress bars now run by default only in interactive sessions for
cv_spatial,cv_buffer,cv_cluster, andcv_nndm;cv_similarityprogress bars now do the same. Report flags now suppress printing only; fold record tables are still returned. Issue #57. - The
printmethods for the fold objects (cv_spatial,cv_buffer,cv_cluster,cv_group,cv_knndm,cv_nndm) and forcv_spatial_autocornow show an informative summary (method description, key settings, and the per-fold train/test record table) instead of only echoing the class name, matching the diagnosticprintmethods ofcv_distance,cv_similarity, andcv_summary. Each returns the object invisibly. Thecv_clusterprint distinguishes spatial, environmental (feature-space), and spatially-constrained environmental clustering, and the returned object now carries thespatial_weightused. Thecv_spatialobject now carries theblock_shape("hexagon","square", or"user-defined") and theselectionused, both shown in its print. Thecv_distanceandcv_similarityprints now note when the object is presence-background, making it clear the distance/similarity/novelty statistics are computed on presence points only (background samples excluded). - Functions that need a suggested package now stop with a clear installation message instead of an interactive install prompt, so they behave consistently in scripts and non-interactive sessions.
cv_clusternow rejects categorical (factor) layers inrwith a clear error instead of silently clustering their integer codes, since environmental clustering uses k-means (Euclidean distance) and supports only numeric covariates. It also warns when spatial (coordinate-based) clustering runs on geographic (lon/lat) coordinates, since k-means uses Euclidean distance; consider projectingx. It now also validateskagainst the number of available sample points (or sampled raster cells) before callingstats::kmeans, stopping with a clearer message instead of the cryptic "more cluster centers than distinct data points" error.- The
cv_*functions now raise a clear error whenxcannot be coerced to ansfobject, instead of silently continuing with the invalid input and failing later with an unrelated message. cv_nndmno longer requiresrwhenpred_pointsormodel_domainare supplied, now falls back to Euclidean distances with a warning whenxhas no CRS, and errors whenxandrhave mismatched coordinate reference systems; issue #58.cv_nndmnow returnsexclusion, a table with one row per fold giving the fold number, the row index of its test point inx(test_id), and theexclusion_distancematched to that point, so it is clear which record is held out at what distance. Unlikecv_buffer, whose exclusion distance is the constantsize, NNDM matches a distinct radius to each test point; the radius is not capped bysize, as points whose nearest neighbour already lies beyondsizeare left unthinned and keep their larger natural nearest-neighbour distance.cv_similaritynow returns acv_similarityobject (a list with the per-fold extrapolation summary in$extrapolation, the overall novelty rate in$overall, and the plot in$plot) instead of a ggplot with the summary attached as an attribute. It gains aplotargument (defaultTRUE) that controls only whether the plot is drawn; the plot object is always built and returned. The overall novelty rate is shown in the title and the novel region is shaded, and a newtype = "map"plots the sample points in space, colouring each test point by its similarity to show where extrapolation occurs.- Improved the fold-object
plot()methods, now includingcv_spatial, so they accept the original sample data and report missing data more clearly; issues #59 and #60. cv_spatialavoids duplicate block-to-point intersection work when subsetting and assigning blocks; issue #40.
- Removed the legacy v2.x functions:
buffering,envBlock,foldExplorer,rangeExplorer,spatialAutoRange, andspatialBlock; use thecv_*equivalents in new code.
- Fixed a train/test leakage bug in
cv_nndm(presence_bg = TRUE)where the test fold used the presence's position instead of its row index, holding out the wrong point and leaving it in both train and test. - Fixed
plot.cv_spatial_autocor()so single-layer autocorrelation objects plot correctly and multi-layer plots include the stored map panel. cv_plotandcv_similaritynow stop with a clear message when none of the requestednum_plotsfolds exist (e.g.num_plots = 99for a 5-fold object), instead of silently reducing the selection to nothing and failing later with a confusing "undefined columns selected" error; out-of-range values are still dropped when at least one requested fold is valid.
- Added two new distance-based similarity scores, L1 and L2, to the
cv_similarityfunction - Fixed a warning in
cv_similarityfor colour aesthetics with ggplot - Fixed the summary method and plotting for
cv_spatial_autocor
- Temporarily added
sppackage dependency to avoid CRAN error as required byautomappackage [#55].
- Resolved unclear error messages; issue #52 by A. Márcia Barbosa
- Resolved ggplot testing failure; issue #54 by Teun van den Brand
- Resolved background pattern artefacts in raster plotting; issue #50 by Camila Neder.
- Just the
biomod2example is updated in vignettes; and the link in help file
- the
biomod2andgstatpackages are added to the Suggests section - Some minor edits in messages
- The iteration in
cv_spatialandspatialBlockis increased to 100 to make the result matches with v2.1.4 - Removed the requirement of C++11
- Some warnings are added for the miss use of the
columnargument
- some internal fix.
- the
extendparameter is now added tospatialBlockand the function now usescv_spatialinternally. - the
user_blocksincv_spatialis restricted to random and predefined and systematic selection. - no
rasterpackage dependency
- the result of the
cv_spatialfunction for square blocks now matches the one of version 2 functionspatialBlock(i.e. fold assignment starts from top-right corner; this is not the case for hexagon blocks) - square spatial blocks can be expanded to ensure no points fall outside the border of the blocks. This can be controlled by
extendparameter now.
- fixing a bug in counting records in the reporting of
cv_spatial
- fixing fold numbering of
cv_spatialto reproducibility of earlier versions
- Massive performance improvement in the C++ code of
cv_nndmfunction for large datasets
- Dependency to
rgdalandrgeosare removed, and overall less dependency - Function names have been changed, with all functions now starting with
cv_ - The old functions (v2.x) still work to allow appropriate time for adapting the new code
- The CV blocking functions are now:
cv_spatial,cv_cluster,cv_buffer, andcv_nndm - Spatial blocks now support hexagonal (default), rectangular, and user-defined blocks
- A fast C++ implementation of Nearest Neighbour Distance Matching (NNDM) algorithm (Milà et al. 2022) is now added
- The NNDM algorithm can handle species presence-background data and other types of data
- The
cv_clusterfunction generates blocks based on kmeans clustering. It now works on both environmental rasters and the spatial coordinates of sample points - The
cv_spatial_autocorfunction now calculates the spatial autocorrelation range for both the response (i.e. the binary or continuous data) and a set of continuous raster covariates - The new
cv_plotfunction allows for visualization of folds from all blocking strategies using ggplot facets - The
terrapackage is now used for all raster processing and supports bothstarsandrasterobjects, as well as files on disk. - The new
cv_similarityprovides measures on possible extrapolation to testing folds
- fixed CRAN error for ggplot guide
- added rgdal as a suggest
- changed the crs of raster data in the package to avoid datum warnings
- fix the warning for spatialBlock function on geographic coordinate system
- predefined folds from user-defined blocks are noe accepted
- add seed argument to spatialBlock to have consistent results where needed
- snowfall package for parallel processing is replaces by future.apply package; #7
- future.apply, shiny, shinydashboard, geosphere and ggplot2 packages moved to SUGGESTION packages. These are not install by default and the user is asked if needed. #7
- RStoolbox is no longer used for clustering
- an argument is added to envBlock function for sampling from raster layers
- no dependency on sp package any more
- doParallel = FALSE by default in spatialAutoRange function
- print() and cat() are removed from the functions and verbose argument is added instead
- most of the underlying functions are migrated to
sffunctions; - the parallel processing changed from
foreachtosnowfall; - the
speciesargument inspatialBlockfunction accepts multi-class responses to find evenly distributed records in train and test folds;
- change
spatialAutoRangefunction to accepts rasters with low number of pixels; #2 - the
maskBySpecies = FALSEinspatialBlockfunction is no longer supported; - the
numLimitargument inspatialBlockfunction is only accepts numeric values, and 0 means searching for evenly distributed folds;
- add
speciesDatatospatialAutoRangefunction;