scieee AI-readable full text Open interactive document viewer

Nearest neighbour distance matching Leave-One-Out Cross-Validation for map validation

Milà, Carles; Mateu, Jorge; Pebesma, Edzer; Meyer, Hanna

Abstract

1. Several spatial and non-spatial Cross-Validation (CV) methods have been used to perform map validation when additional sampling for validation purposes is not possible, yet it is unclear in which situations one CV method might be preferred over the other. Three factors have been identified as determinants of the performance of CV methods for map validation: the prediction area (geographical interpolation vs. extrapolation), the sampling pattern and the landscape spatial autocorrelation. In this study, we propose a new CV strategy that takes the geographical prediction space into account, and test how the new method compares with other established CV methods under different configurations of these three factors. 2. We propose a variation of Leave-One-Out (LOO) CV for map validation, called Nearest Neighbour Distance Matching (NNDM) LOO CV, in which the nearest neighbour distance distribution function between the test and training data during the CV process is matched to the nearest neighbour distance distribution function between the target prediction and training points. Using random forest as a machine learning algorithm, we then examine the suitability of NNDM LOO CV as well as the established LOO (non-spatial) and buffered-LOO (bLOO, spatial) CV methods in two simulations with varying prediction areas, landscape autocorrelation and sampling distributions. 3. LOO CV provided good map accuracy estimates in landscapes with short autocorrelation ranges, or when estimating geographical interpolation map accuracy with randomly distributed samples. bLOO CV yielded realistic error estimates when estimating map accuracy in new prediction areas, but generally overestimated geographical interpolation errors. NNDM LOO CV returned reliable estimates in all scenarios we considered. 4. While LOO and bLOO CV provided reliable map accuracy estimates only in certain situations, our newly proposed NNDM LOO CV method returned robust estimates and generalised to LOO and bLOO CV whenever these methods were the most appropriate approach. Our work recognises the necessity of considering the geographical prediction space when designing CV-based methods for map validation.

Full text

1304 | Methods Ecol Evol. 2022;13:1304–1316.wileyonlinelibrary.com/journal/mee3 Received: 20 September 2021 | Accepted: 8 March 2022 DOI: 10.1111/2041-210X.13851 RESEARCH ARTICLE Nearest neighbour distance matching Leave- One- Out Cross- Validation for map validation Carles Milà1 | Jorge Mateu2 | Edzer Pebesma3 | Hanna Meyer4 1Barcelona Institute for Global Health (ISGlobal), Universitat Pompeu Fabra, CIBER Epidemiología y Salud Pública, Barcelona, Spain 2Universitat Jaume I, Castellón, Spain 3Institute of Geoinformatics, Westfälische Wilhelms- Universität Münster, Münster, Germany 4Institute of Landscape Ecology, Westfälische Wilhelms- Universität Münster, Münster, Germany Correspondence Carles Milà Email: [email protected] Funding information C.M. was supported by a PhD fellowship of the Severo Ochoa Centre of Excellence program awarded to ISGlobal. The work was further supported by the Federal Ministry of Economic Affairs and Energy of Germany (project number 50EE2009). Handling Editor: Phil J Bouchet Abstract 1. Several spatial and nonspatial Cross- Validation (CV) methods have been used to perform map validation when additional sampling for validation purposes is not possible, yet it is unclear in which situations one CV method might be preferred over the other. Three factors have been identified as determinants of the performance of CV methods for map validation: the prediction area (geographical interpolation vs. extrapolation), the sampling pattern and the landscape spatial autocorrelation. In this study, we propose a new CV strategy that takes the geographical prediction space into account, and test how the new method compares with other established CV methods under different configurations of these three factors. 2. We propose a variation of Leave- One- Out (LOO) CV for map validation, called Nearest Neighbour Distance Matching (NNDM) LOO CV, in which the nearest neighbour distance distribution function between the test and training data during the CV process is matched to the nearest neighbour distance distribution function between the target prediction and training points. Using random forest as a machine learning algorithm, we then examine the suitability of NNDM LOO CV as well as the established LOO (nonspatial) and buffered- LOO (bLOO, spatial) CV methods in two simulations with varying prediction areas, landscape autocorrelation and sampling distributions. 3. LOO CV provided good map accuracy estimates in landscapes with short autocorrelation ranges, or when estimating geographical interpolation map accuracy with randomly distributed samples. bLOO CV yielded realistic error estimates when estimating map accuracy in new prediction areas, but generally overestimated geographical interpolation errors. NNDM LOO CV returned reliable estimates in all scenarios we considered. 4. While LOO and bLOO CV provided reliable map accuracy estimates only in certain situations, our newly proposed NNDM LOO CV method returned robust estimates and generalised to LOO and bLOO CV whenever these methods were the most appropriate approach. Our work recognises the necessity of considering the geographical prediction space when designing CV- based methods for map validation. This is an open access article under the terms of the Creative Commons Attribution License, which permits use, distribution and reproduction in any medium, provided the original work is properly cited. © 2022 The Authors. Methods in Ecology and Evolution published by John Wiley & Sons Ltd on behalf of British Ecological Society. | 1305 Methods in Ecology and Evoluon MILÀ et aL. 1 | INTRODUCTION Prediction of spatially structured variables at unsampled locations is crucial in ecology and the environmental sciences (Schmidt- Traub, 2021), where sampling methods are often complex and costly (e.g. forest inventories, Ploton et al., 2020; fixed meteorological stations, Meyer et al., 2016). An important step in a predictive mapping workflow is map validation, where the quality of the spatial predictions generated by the trained model is estimated. Although unbiased map accuracy estimates can be obtained via probability sampling and designbased inference (Wadoux et al., 2021), in many instances additional sampling for validation purposes is not possible. Furthermore, in the majority of ecological studies, field surveys are often conducted in opportunistic locations (Yates et al., 2018), might be subject to access restrictions, and are often biased towards populated or protected areas (Martin et al., 2012). This makes designbased inference hardly possible. Instead, model validation measures are frequently used as a proxy for map accuracy. Model validation strategies commonly used include (repeated) train/test data splits or resampling techniques such as bootstrapping and Cross- Validation (CV) (Lyons et al., 2018). All of these methods rely on the key assumption of independence between train and test data to assess model generalisation to new, unobserved observations (Hastie et al., 2009). However, in the presence of spatial autocorrelation, independence between train and test data points may not hold. Nonetheless, standard CV (e.g. Leave- One- Out [LOO] and random kfold CV) methods that ignore the locations of the training samples have been largely applied to spatial prediction problems, although the risk of obtaining invalid results has been frequently discussed (Misiuk et al., 2019; Ploton et al., 2020; Pohjankukka et al., 2017; Roberts et al., 2017; Telford & Birks, 2009; Wenger & Olden, 2012). To overcome this issue, variations of traditional CV techniques have been proposed to minimise the spatial dependence between training and test points. One of them is spatial block kfold CV, a variation on kfold CV where folds are defined as contiguous blocks in geographical space (Wenger & Olden, 2012) using many possible configurations (Roberts et al., 2017; Valavi et al., 2019). Another method is buffered Leave- One- Out (bLOO) CV, which was introduced in the ecological literature (Telford & Birks, 2009) as an extension of LOO CV. Briefly, when holding out each of the points, observations within a given geographical radius of that point are also excluded from the training data (Le Rest et al., 2014). Radii have been suggested to be defined based on the estimated semivariogram range of the model residuals (Le Rest et al., 2014; Telford & Birks, 2009), outcome (Roberts et al., 2017) or predictors (Valavi et al., 2019); or otherwise based on Moran's I correlogram (Karasiak et al., 2021). Though frequently used, the use of CV strategies for map validation purposes remains controversial. Recent studies have made an important distinction between model and map validation (Stehman et al., 2021; Wadoux et al., 2021): while the former concerns itself with model transferability to new, unobserved observations, the latter aims to estimate the accuracy of the predictions of a model for a fixed and clearly defined area (e.g. a defined population of pixels) which may or may not be independent from the existing training samples. While existing CV approaches can be useful for model validation, their use for map validation may be inappropriate since they ignore the prediction space. Furthermore, the election of the most appropriate CV method for map validation has been found to be complex and dependent on several factors: the prediction area, the spatial autocorrelation of the landscape (set of outcome and predictors) and the sampling pattern. Regarding the prediction area, it is important to distinguish the case where the sampling and prediction areas overlap (i.e. geographical interpolation) and the case where they do not (i.e. geographical extrapolation). Provided no covariate shifts are found between the training and prediction areas, spatial CV methods that impose independence between train and test data may be suitable to estimate map accuracy of a new prediction area where all prediction points will also be independent from the training data. However, they may not be adequate for interpolation in the geographical space, where at least a subset of the prediction locations in the vicinity of sampling points will not be independent from the training data (Misiuk et al., 2019; Roberts et al., 2017). In relation to spatial autocorrelation, it has been suggested that standard CV methods tend to overestimate model transferability in landscapes with long autocorrelation ranges, while yielding reasonable estimates when ranges are short (Rocha et al., 2018). While most spatial modellers focus on residual spatial autocorrelation as a possible source of bias during CV and design spatial CV strategies to remove it (Le Rest et al., 2014; Ploton et al., 2020; Telford & Birks, 2009), recent studies suggest that spatial overfitting with noncausal, spatially structured predictors can also lead to a decreased model transfer ability (Fourcade et al., 2018) and erroneous CV analyses (Roberts et al., 2017), and hence recommend considering the outcome (Roberts et al., 2017) and predictor (Valavi et al., 2019) autocorrelation as well. The importance of the sampling pattern has been examined in the recent study by Wadoux et al. (2021), where the authors showed that random kfold CV is able to reasonably estimate the error of machine learninginterpolated surfaces with regular and randomly distributed training samples, but not if training samples are clustered. Indeed, several authors have pointed out that spatially clustered samples may lead to an overestimation of map accuracy when using standard CV methods for spatial interpolation problems, and recommend using spatial CV variants in that case (Hengl et al., 2018; Meyer et al., 2019; Misiuk et al., 2019). This is the case of many largescale prediction tasks, where samples come from composite databases, often lack a common sampling design and are frequently clustered in KEYWORDS Cross- Validation, map accuracy estimation, map validation, spatial point patterns, spatial prediction 1306 | Methods in Ecology and Evoluon MILÀ et aL. the geographical space (e.g. Van Den Hoogen et al., 2019). However, Wadoux et al. (2021) warned that even with clustered samples, spatial CV may still overestimate errors. Finally, we argue that in order to obtain reliable map accuracy estimates for a given spatial prediction task, not only must these three factors (prediction area, spatial autocorrelation and sampling pattern) be taken into account, but also the geographical prediction space, which is currently ignored by both spatial and nonspatial CV methods, needs to be considered. Under spatial autocorrelation, the prediction error at a given location has been repetitively observed to follow an increasing function of the distance to its nearest training point (Brenning, 2021; Park et al., 2020; Ploton et al., 2020; Pohjankukka et al., 2017; Roberts et al., 2017; Telford & Birks, 2009). Thus, and similarly to time series CV methods where the prediction horizon is taken into account (Hyndman & Athanasopoulos, 2018), distances from the prediction locations to its nearest training sample should be matched during the CV process to obtain realistic map accuracy estimates for a given prediction task. This is illustrated in Figure 1, where nearest neighbour distances between test and training data during LOO CV (i.e. nearest neighbour distances of sampling points) are much shorter than distances from the prediction points to the nearest training point, which may trigger an overestimation of LOO CV accuracy if the landscape is subject to significant spatial autocorrelation. In this study, we propose a new CV strategy suited for map validation that takes the geographical space of the target of the prediction task into account, and test how it compares to other established nonspatial and spatial CV strategies under different scenarios of prediction areas, landscape autocorrelation and sampling distributions. 2 | MATERIALS AND METHODS 2.1 | Nearest neighbour distance matching Leave- One- Out Cross- Validation We propose a variation of LOO CV for map validation, called Nearest Neighbour Distance Matching (NNDM) LOO CV, in which the nearest neighbour distance distribution function (see below) between the test and training data during the CV process is matched to the nearest neighbour distance distribution function between the prediction and training points. This is done for those distances in which spatial autocorrelation is present, that is, distances shorter than the autocorrelation range (similar accuracy is expected for prediction points beyond it). To characterise the distribution of nearest neighbour distances, we use concepts from the spatial point pattern field. First, to characterise the distribution of nearest neighbour distances between target x ( i) (Figure 2b) and sampling x ( j) points (Figure 2a) that is found during prediction, we use the empirical multitype nearest neighbour distance distribution function  Gij (r ) (Baddeley et al., 2015), which expresses the proportion of prediction points that have a sampling point at a distance equal or lower than r , and is defined as: where r is a distance, ni is the total number of prediction points and dij =min ∥x (i) i −x(j) ∥ . Here, no edge correction or stationarity assumptions are needed since  Gij (r ) is simply used as a means to describe the nearest neighbour distance distribution of a set of fixed locations, rather than to perform an inferential spatial point pattern analysis of a realisation of a random point process. Moreover, for the common case where prediction points consist of a regular grid spanning all the sampling area independently of the locations of the training samples,  Gij (r ) will be roughly equivalent to  Fj (r ) , that is, the empirical empty space function of the sampling points. In our example in Figure 2c,  Gij (r ) can be interpreted as follows: 50% of the prediction points have at least one training point at a distance equal or lower than 19.8 units. Second, to characterise the distribution of the nearest neighbour distances during LOO CV where each of the points is held out sequentially, we can resort to the  Gj (r ) empirical nearest neighbour distance distribution function, which expresses the proportion of sampling points that have another sampling point at a distance equal or lower than r , and can be calculated as:  G ij(r)= 1 ni∑ i 1{dij ≤r} , FIGURE 1 (a) 2,500 prediction points structured in a 50 × 50 regular grid, and 50 clustered sampling points. (b) Mismatch between the distribution of nearest neighbour distances between test and training data during LOO CV (i.e. nearest neighbour distances of sampling points) and prediction (i.e. distances from each prediction point to its nearest sampling point) | 1307 Methods in Ecology and Evoluon MILÀ et aL. where r is a distance, nj is the total number of sampling points and d j=mink≠j∥x (j) j −x (j) k∥ . In our example in Figure 2c,  Gj (r ) can be interpreted as follows: 50% of the training points have at least another training point at a distance equal or lower than 7.9 units. Note that, in this example, there is a relevant mismatch between the nearest neighbour distance distribution function encountered during the prediction, that is,  Gij (r ) , and the one found during LOO CV, that is,  Gj (r ) . Our proposed NNDM LOO CV method retains the idea of LOO CV to validate each of the points in the training sample sequentially by holding them out one by one, but, similarly to bLOO CV, may exclude additional samples from the training set in each CV iteration. Let L = { l1,l2,…,lnj } be a list of sets lj containing the indices of the samples to fit the model to when holding out observation j during LOO CV. We can now define  G∗ j (r,L ) as the modified empirical nearest neighbour distance distribution function: where d ∗ j =mink∈l j ∥x (j) j −x (j) k∥ . Note that the only difference between dj and d∗ j is that while the former considers all training points but j when computing the minimum distances, the latter considers the set of points included in lj . However, if ∀ j,l j = { 1, 2, …,j−1, j+1, …,n j} , that is, lj contains all training samples except the hold out point j , d j= d∗ j , and hence  G∗ j (r,L)= Gj(r ) . In Figure 2d, one can see how L = { l 1 ,l 2 ,l 2 ,l 3 ,l 4 ,l 5 ,l 6 ,l 7 ,l 8 ,l 9 ,l 10} has been defined in this example, for example, l3={1,2,4,6,7,8,9} , that is, in the third iteration of NNDM LOO CV, we will fit a model with training samples 1,2,4,6,7,8,9 which will be used to assess out- of- sample accuracy of sample 3. To determine L , we propose a simple greedy algorithm called Nearest Neighbour Distance Matching (NNDM) that, starting from LOO CV, excludes observations from lj whenever by doing so  G∗ j (r,L ) matches better  Gij (r ) , for those r where autocorrelation is present (Algorithm 1). The inputs of the NNDM algorithm are the prediction points x ( i) and training points x ( j) , and the autocorrelation range 𝜙 , which can be estimated as the range of the semivariogram computed from the model residuals, or alternatively as the outcome range if the model is likely to be subject to spatial overfitting (Roberts et al., 2017).  G j(r)= 1 nj∑ j 1{dj≤r} ,  G∗ j(r,L)= 1 nj∑ j 1{d∗ j≤r} , 1308 | Methods in Ecology and Evoluon MILÀ et aL. The NNDM algorithm starts by computing the distances dij between each prediction point and its nearest training point. It initially defines the set of training points to be used in each iteration of NNDM LOO CV, L , as all but the hold out point (i.e. LOO CV). Then, it calculates the nearest neighbour distances d∗ j between each CV hold out sample and their respective CV training data lj , identifies the minimum among them r min = mind∗ j , as well as the hold out point jmin and training sample k min ∈ l j min where it is found. Then, we check if after removing kmin from l j min ,  G∗ j( rmin,L ) is greater or equal than  Gij( r min) . If it is, the point kmin is removed from l j min and d∗ j , rmin , jmin , and kmin are updated; otherwise, we look for the next rmin , update jmin , kmin and keep iterating while rmin is smaller than or equal to the autocorrelation range 𝜙 . Some points are worth noting: (a) If ∀r≤𝜙 ,  Gj (r)≤  G ij (r ) (e.g. regularly distributed samples), no point will be excluded from lj and NNDM LOO CV will be equivalent to LOO CV; (b) if the autocorrelation range is very short or null 𝜙≈0 , NNDM LOO CV will also be equivalent to LOO CV; and (c) if the minimum nearest neighbour distance between any of the prediction and training points, that is, mindij is larger than 𝜙 (e.g. the model is transferred to a new area), all points within a distance 𝜙 of each hold out point will be excluded as ∀r<=𝜙 ,  Gij (r)= 0 , that is, NNDM LOO CV will be equivalent to bLOO CV with a radius equal to 𝜙 . To illustrate these concepts, we simulated three sets of points with different distributions in a 100 × 100 prediction grid (i.e. 10,000 regular points) and estimated and compared the  Gij (r ) ,  Gj (r ) and  G∗ j (r,L ) functions (Figure 3). Here, we assume that 𝜙 is known and equal to 20. A visual comparison of  Gj (r ) and  Gij (r ) reveals that for random sampling patterns, the distribution of the nearest neighbour distances when performing LOO CV, that is,  Gj (r ) , and when predicting the continuous surface, that is,  Gij (r ) , is very similar, which is not surprising as  Gij (r)≈  F j (r ) in this case, and G(r) and F(r) are known to be equivalent under complete spatial randomness (Baddeley et al., 2015). On the other hand, we see that nearest neighbour distances during prediction are shorter than those in LOO CV for regularly distributed samples, while the opposite happens for clustered samples. Our proposed NNDM LOO CV method produces a distribution of nearest neighbour distances  G∗ j (r,L ) identical or very similar to LOO CV for random and regular sampling patterns and well matched to  Gij (r ) in the clustered scenario. 2.2 | Simulation 1: Random fields The first simulation compared the performance of LOO, bLOO and NNDM LOO CV for geographical interpolation and extrapolation map validation in simulated landscapes with varying autocorrelation range, and sampling patterns with different number of points and distributions (Figure 4). The input parameter of the simulation was the landscape autocorrelation range, which we set to a value of 1, 10, 20, 30 and 40 units. For each these values, we run 100 iterations of the simulation (i.e. 500 simulations iterations in total). In each simulation iteration, we defined a 300 × 100 twodimensional grid with a sampling area [0,100] × [0,100] and FIGURE 2 Simplified example of NNDM LOO CV: (a) 10 training samples, (b) 10,000 prediction points structured in a 100 × 100 grid, (c)  Gij (r ) (i.e. nearest neighbour distance distribution function during prediction),  G∗ j (r,L ) (i.e. nearest neighbour distance distribution function during NNDM LOO CV),  Gj (r ) (i.e. nearest neighbour distance distribution function during LOO CV) functions and (d) view of NNDM LOO CV iterations. Here we assume the autocorrelation range parameter 𝜙 to be known and equal to 40 | 1309 Methods in Ecology and Evoluon MILÀ et aL. two distinct prediction areas: geographical interpolation [0,100] × [0,100], which coincided with the sampling area, and extrapolation [200,300] × [0,100]. We then simulated 20 independent covariate fields, defined as twodimensional stationary and isotropic Gaussian random fields with a constant mean of 0 and subject to spatial autocorrelation with spherical semivariogram with a sill of 1, a null nugget, and a range equal to the landscape autocorrelation range simulation parameter (Figure S1). Note that by assuming a constant mean in all the study area, we implicitly assumed that no significant covariate shifts were present. To compute the outcome, we used the equation of simulation framework 2 from Van der Laan et al. (2007): Y =X 1 X 2 +X 2 10 −X 3 X 17 −X 15 X 4 +X 9 X 5 +X 19 −X 2 20 +X 9 X 8 + 𝜀 and defined a noise with a random and a spatially autocorrelated component 𝜀=𝜀1+𝜀2 where 𝜀1∼N(0, 1) and 𝜀2 simulated using the same semivariogram as the covariates. Random field simulations were carried out using the unconditional sequential Gaussian simulation algorithm (Gebbers & de Bruin, 2010). Next, we simulated sampling points with three different sample sizes ( N=100,200,300 ) and five different sampling distributions (weak and strong regular, random, and weak and strong clustered), that is, 15 different sets of training points per simulation iteration, within the sampling area. Random samples were drawn by uniform random sampling; regular samples were obtained by jittering regular grids by 2 units (strong regular) or 5 units (weak regular); clustered samples were simulated by first drawing 10 (strong clustering) or 25 (weak clustering) nparents points randomly, and then n−nparents n parents points in the 5- unit radius buffer of each parent point. Landscape data (outcome and 20 covariate fields) at the sampling points' locations were extracted. With the extracted data at each of the 15 sampling patterns simulated in the previous step, a Random Forest (RF) model (Liaw & Wiener, 2002) was fit (mtry parameter fixed to 7) and used to predict the interpolation and extrapolation areas. We chose a RF model as it is one of the most popular ML models for spatial prediction (Wylie et al., 2019), and a large body of research on predictive mapping uses it (Hengl et al., 2018; Meyer et al., 2019; Meyer & Pebesma, 2021; Misiuk et al., 2019; Wadoux et al., 2021). Since the actual values of the outcome were known for the entire study area, we computed the Root Mean Square Error (RMSE), Mean Absolute Error (MAE) and R2 between all the gridded predicted and actual outcome values in the interpolation and extrapolation areas, separately (true map accuracy). Furthermore, we estimated map accuracy by computing the same three statistics when using (a) LOO CV, (b) bLOO CV, (c) NNDM LOO CV using the interpolation grid as prediction points and (d) NNDM LOO CV with the extrapolation grid as prediction points. Since in this simulation the landscape autocorrelation parameter was known, we used it as the buffer radius and 𝜙 parameter in bLOO and NNDM LOO CV, respectively. To analyse the simulation results, we plotted the distribution of the RMSE, MAE and R2 by validation method, sample size and distribution, landscape autocorrelation range, and prediction area across the 100 simulations iterations available for each combination of factors. To further assess whether CV methods were able to estimate the true map accuracy, we also subtracted the true from the CV RMSE, MAE and R2 and plotted the distribution of these differences. FIGURE 3 Three simulated sets of 100 points in a 100 × 100 grid (top) and their respective  Gij (r ) (i.e. nearest neighbour distance distribution function during prediction),  G∗ ij (r,L ) (i.e. nearest neighbour distance distribution function during NNDM LOO CV) and  Gj (r ) (i.e. nearest neighbour distance distribution function during LOO CV) functions (bottom). Note that  G∗ j (r,L)= Gj(r ) in the regular case 1310 | Methods in Ecology and Evoluon MILÀ et aL. 2.3 | Simulation 2: Virtual species We performed a second simulation study of a spatial prediction problem where this time covariate fields were observed rather than simulated, and bLOO and NDMM LOO CV autocorrelation range parameters were unknown and therefore needed to be estimated. The simulation used WorldClim bioclimatic variables (www.world clim. org/data/biocl im.html) and the R package virtualspecies (Leroy et al., 2015) to create a virtual species suitability surface for the Iberian peninsula. Briefly, we downloaded grids for the 19 Worldclim bioclimatic variables at 2.5 min spatial resolution and cropped the data to the Iberian peninsula (defined as the area covered by continental Spain and Portugal, Figure 5a). We first generated a species suitability surface by taking the first and second dimensions of a principal component analysis on bioclimatic variables 1 (annual mean temperature), 2 (mean diurnal range), 4 (temperature seasonality), 5 (maximum temperature of warmest month), 6 (minimum temperature of the coldest month), 12 (annual precipitation), 13 (precipitation of the wettest month), 14 (precipitation of the driest month) and 15 (precipitation seasonality). Then, we assigned virtual species suitability values (scaled between 0 and 1) according to the product of two Gaussian probability density functions following a N(0, 2) distribution in each axis (Figure S2). Data were projected into the ETRS89 UTM 30N coordinate reference system (EPSG: 25830). The resulting species suitability surface was treated as the outcome to be modelled. Next, we simulated five sets of sampling points ( N=100 ) with different distributions (weak and strong regular, random, and weak and strong clustered; Figure 5b) with the same methods as in simulation 1 but changing the distance parameters for regular jittering (40 km for weak regular and 80 km for strong regular) and clustered sampling (80 km buffer radius). In all, 100 replications of the sampling process were done. For each of the training points sets, we extracted the climate and suitability data and fitted a RF model to the habitat suitability outcome using all 19 bioclimatic covariates (mtry parameter fixed to 6), which was used to predict the suitability in the whole surface. Unlike simulation 1, since in this case the autocorrelation range parameters needed for both bLOO and NNDM LOO CV were not known, we estimated them by automatically fitting a spherical semivariogram model to the FIGURE 4 Simulation 1: Example of the workflow of one simulation iteration given a landscape autocorrelation of 20. bLOO: buffered LOO; CV, Cross- Validation; LOO: leaveone- out; MAE, Mean Absolute Error; NNDM, nearest neighbour distance matching; RMSE, Root Mean Square Error | 1311 Methods in Ecology and Evoluon MILÀ et aL. raw outcome and model residuals at the sample locations in each iteration, and then extracting the estimated ranges. Predictions were validated (a) comparing the actual vs. predicted suitability surfaces (i.e. true accuracy), (b) using LOO CV, and using (c) bLOO and (d) NNDM LOO CV with the estimated outcome and residual autocorrelation range as a parameter, that is, two different bLOO and NNDM LOO CV estimates were obtained. RMSE, MAE and R2 were used as validation statistics. To analyse the results, we subtracted the true from the CV RMSE, MAE and R2 and plotted the distribution of these differences by CV method and sample size and distribution. 2.4 | Implementation All methods and simulation analyses were developed in R version 4.0 using several packages: doParallel (Corporation & Weston, 2019) for parallel computing, randomForest and caret (Kuhn, 2020; Liaw & Wiener, 2002) for RF model fitting, sf (Pebesma, 2018) and raster (Hijmans, 2019) for vector and raster data management, gstat (Pebesma, 2004) for random field simulation and semivariogram fitting, and tidyverse (Wickham, 2017) for data management and graphics. Additional packages were used to execute other minor tasks. NNDM LOO and bLOO CV functions and classes have been implemented in an R package named NNDM, which is available at www. github.com/carle smila/ NNDM together with a worked example. The code used in the simulations included in this work, as well as the simulation data, are available at www.github.com/carle smila/ NNDMp aper. 3 | RESULTS 3.1 | Simulation 1: Random fields Mean RMSEs across simulation scenarios (Figure 6, N=200 ) showed that, while for short autocorrelation ranges most map validation strategies resulted in the same RMSE, as the range increased, RMSEs started to diverge, with increasing true extrapolation RMSEs and decreasing true interpolation RMSEs. bLOO and NNDM LOO CV (extrapolation area) had overlapping profiles and were considerably well aligned with the true extrapolation RMSE in all the scenarios, whereas LOO CV and NNDM LOO CV (interpolation area) were only equivalent for regular and random patterns but not clustered, where NNDM LOO CV approximated much better the true interpolation RMSE. Results for sample sizes equal to 100 and 300 points (Figures S3 and S4) and for the MAE and R2 statistic (Figures S5 and S6) yielded similar conclusions. Examination of the differences between the CV and the true RMSEs highlighted the fact that, for landscapes with almost null spatial autocorrelation, all CV methods were able to successfully estimate map accuracies (Figure 7). However, for longer autocorrelation ranges, distinct patterns were found in interpolation vs. extrapolation areas. In the interpolation area, LOO CV provided good estimates of the true RMSE under randomly distributed samples regardless of the range, yet slightly overestimated RMSEs for regularly distributed samples and strongly underestimated RMSEs for clustered samples; this pattern was more severe as the range FIGURE 5 Simulation 2: (a) bioclimatic covariates and outcome species suitability (all linearly stretched to [0,1] for visualisation purposes); and (b) example of one iteration of the sample simulation 1312 | Methods in Ecology and Evoluon MILÀ et aL. increased (mean (SD) differences for range = 30 were 0.27 (0.13), 0.01 (0.16) and −1.51 (0.32) for strong regular, random and strong clustered samples, respectively). bLOO CV overestimated RMSEs with larger variability in all sampling patterns (mean (SD) difference for range = 30 was 0.82 (0.34) for the random sampling pattern). NNDM LOO CV (interpolation area) gave identical or very similar results to LOO CV for regular and random patterns, yet corrected the error underestimation for clustered samples observed in LOO CV (NNDM LOO CV mean (SD) difference for range = 30 was −0.03 (0.63) for the strong clustered pattern). In the extrapolation area, LOO CV underestimated the true RMSE for medium and long autocorrelation ranges regardless of the sample distribution. Both bLOO and NNDM LOO CV (extrapolation area) yielded identical and approximately correct RMSE estimates on average (mean (SD) differences for range = 30 and a weak clustered pattern were −1.35 (0.23), 0.13 (0.72) and 0.13 (0.72) for LOO CV, bLOO and NNDM LOO CV, respectively). Results were similar for samples sizes equal to 100 and 300 points (Figures S7 and S8), as well as when considering the MAE and R2 statistic (Figures S9 and S10). 3.2 | Simulation 2: Virtual species Results for LOO CV in simulation 2 (Figure 8) generally agreed with findings of simulation 1 for geographical interpolation: while LOO CV slightly overestimated the true RMSE in regular sampling patterns, it provided good estimates of the error in random patterns but considerably underestimated RMSEs for clustered samples (mean (SD) differences 0.01 (0.01), 0 (0.01), −0.07 (0.03), for strong regular, random and strong clustered sampling patterns, respectively). bLOO CV with radius equal to the outcome autocorrelation range yielded larger differences than bLOO CV with radius equal to the residual range (mean (SD) difference in weak clustered samples was 0.07 (0.04) for outcome range vs. 0.04 (0.04) for residual range), since estimated residual ranges were generally shorter than outcome ranges (median outcome range was 217 km vs. 127 km residual range). Nevertheless, both bLOO strategies generally overestimated true RMSEs. Differences for NNDM LOO CV using either outcome or residual autocorrelation range were similar to each other and to LOO CV for regular and random samplings (mean (SD) difference in random samples was 0 (0.1) for both outcome and residual range). For weak clustered samplings, both provided reasonable estimates of the error while having smaller variability than their bLOO counterparts (NNDM LOO CV mean (SD) difference was −0.01 (0.02) for both outcome and residual range). In the strong clustered sampling patterns, slightly larger differences between the two could be observed (mean (SD) difference was −0.01 (0.04) for outcome range vs. −0.02 (0.04) in residual range). Similar findings were found for MAE and R2 statistics (Figures S11 and S12). 4 | DISCUSSION Our proposed NNDM LOO CV method takes the geographical prediction space into account by matching the distribution of nearest neighbour distances between test and training points during LOO CV to the distribution of nearest neighbour distances between the target and sampling points during prediction. In our two simulations with different prediction areas, landscape autocorrelation ranges and sampling distributions, our newly proposed NNDM LOO CV FIGURE 6 Simulation 1: Mean (Q 1 , Q 3 ) RMSE by validation method, sampling distribution and landscape spatial autocorrelation range ( N=200 ). bLOO and LOO CV do not depend on the prediction area as they do not consider the geographical prediction space. Statistics have been calculated based on 100 simulation iterations. NNDM LOO CVextrap and bLOO CV have the same profile and overlap in the graph