Skip to main content
QUICK REVIEW

[Paper Review] The CAST package for training and assessment of spatial prediction models in R

Hanna Meyer, Marvin Ludwig|arXiv (Cornell University)|Apr 10, 2024
demographic modeling and climate adaptationDecision Sciences5 citations
TL;DR

The CAST R package provides spatially aware machine learning workflow tools, including novel cross-validation (NNDM/kNNDM), area-of-applicability, feature selection, and pixel-level uncertainty, demonstrated on South American plant species richness.

ABSTRACT

One key task in environmental science is to map environmental variables continuously in space or even in space and time. Machine learning algorithms are frequently used to learn from local field observations to make spatial predictions by estimating the value of the variable of interest in places where it has not been measured. However, the application of machine learning strategies for spatial mapping involves additional challenges compared to "non-spatial" prediction tasks that often originate from spatial autocorrelation and from training data that are not independent and identically distributed. In the past few years, we developed a number of methods to support the application of machine learning for spatial data which involves the development of suitable cross-validation strategies for performance assessment and model selection, spatial feature selection, and methods to assess the area of applicability of the trained models. The intention of the CAST package is to support the application of machine learning strategies for predictive mapping by implementing such methods and making them available for easy integration into modelling workflows. Here we introduce the CAST package and its core functionalities. At the case study of mapping plant species richness, we will go through the different steps of the modelling workflow and show how CAST can be used to support more reliable spatial predictions.

Motivation & Objective

  • Motivate the challenges of applying machine learning to spatial prediction tasks due to spatial autocorrelation and non-i.i.d. training data.
  • Present CAST as a toolkit to integrate spatial cross-validation, feature selection, and applicability assessment into ML workflows in R.
  • Demonstrate a practical workflow for predicting plant species richness in South America using CAST functionalities.
  • Show how to quantify prediction uncertainty and delineate the area where model predictions are valid.

Proposed method

  • Introduce Nearest Neighbor Distance Matching (NNDM) and its k-fold variant (kNNDM) as prediction-oriented cross-validation strategies that mimic prediction conditions by matching the distribution of training-test nearest-neighbor distances to prediction-to-training distances.
  • Provide visualization tools (geodist) to compare geographic distances and to assess representativeness of cross-validation folds.
  • Implement spatial feature selection (forward feature selection) to reduce overfitting and improve spatial predictive performance (CAST::ffs).
  • Define and compute the area of applicability (AOA) using a dissimilarity index (DI) in predictor space, with optional local data point density (LPD) to flag extrapolation risk (CAST::aoa, CAST::trainDI).
  • Estimate pixel-wise prediction performance via error profiles (CAST::errorProfiles) informed by DI and AOA, enabling uncertainty mapping.
  • Demonstrate integration with common ML workflows (caret, ranger) and compatibility with terra and sf for raster/vector data.

Experimental results

Research questions

  • RQ1How do prediction-oriented cross-validation strategies (NNDM/kNNDM) affect realistic map accuracy estimates for spatial models?
  • RQ2Can spatial feature selection improve predictive mapping by reducing overfitting and maintaining or improving spatial accuracy?
  • RQ3How can we delineate and utilize the area of applicability to avoid making unreliable predictions in regions not covered by training data?
  • RQ4How can pixel-wise uncertainty be quantified and communicated using predictor-space dissimilarity and data density measures?

Key findings

  • kNNDM cross-validation yields more realistic, often worse, validation metrics than random k-fold CV because it tests harder, more distant predictions, reflecting real-world extrapolation conditions.
  • Forward feature selection under a suitable spatial CV strategy can reduce RMSE and improve R2 with fewer predictors than a full model.
  • The area of applicability (AOA) identifies regions where model predictions are reliable, based on a dissimilarity index to training data in predictor space; predictions outside AOA are masked.
  • Pixel-level performance estimation using error profiles links cross-validated performance to local predictor-space dissimilarity, enabling spatially explicit uncertainty mapping.
  • In the South America plant richness example, a simplified model with 5 predictors using kNNDM had RMSE 31.97 and R2 0.52, while the full model with random CV had RMSE 24.16 and R2 0.71 (n=table entries), illustrating the impact of CV choice on reported performance.
  • The CAST workflow integrates cross-validation, feature selection, AOA, and uncertainty assessment to produce more reliable spatial predictions.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.