dsmextra: Extrapolation assessment tools for density surface models

Forecasting the responses of biodiversity to global change has never been more important. However, many ecologists faced with limited sample sizes and shoestring budgets often resort to extrapolating predictive models beyond the range of their data to support management actions in data‐deficient contexts. This can lead to error‐prone inference that has the potential to misdirect conservation interventions and undermine decision‐making. Despite the perils associated with extrapolation, little guidance exists on the best way to identify it when it occurs, leaving users questioning how much credence they should place in model outputs. To address this, we present dsmextra, a new R package for measuring, summarizing and visualizing extrapolation in multivariate environmental space. dsmextra automates the process of conducting quantitative, spatially explicit assessments of extrapolation on the basis of two established metrics: the Extrapolation Detection (ExDet) tool and the percentage of data nearby (%N). The package provides user‐friendly functions to (a) calculate these metrics, (b) create tabular and graphical summaries, (c) explore combinations of covariate sets as a means of informing covariate selection and (d) produce visual displays in the form of interactive html maps. dsmextra implements a model‐agnostic approach to extrapolation detection that is applicable across taxonomic groups, modelling techniques and datasets. We present a case study fitting a density surface model to visual detections of pantropical spotted dolphins Stenella attenuata in the Gulf of Mexico. Predictive modelling seeks to deliver actionable information about the states and trajectories of ecological systems, yet model performance can be strongly impaired out of sample. By assessing conditions under which models are likely to fail or succeed in extrapolating, ecologists may gain a better understanding of biological patterns and their underlying drivers. Critical to this is a concerted effort to standardize best practice in model evaluation, with an emphasis on extrapolative capacity.


| INTRODUC TI ON
The expanding footprint of human activities is rapidly creating novel challenges for the conservation of biodiversity. Maps of wildlife density patterns are fundamental to mitigating the impacts of anthropogenic pressures, but reliable estimates remain elusive for many animal populations inhabiting areas subject to limited sampling effort (e.g. Kaschner, Quick, Jewell, Williams, & Harris, 2012).
Density surface modelling (DSM) (Hedley & Buckland, 2004;Miller, Burt, Rexstad, & Thomas, 2013) is a popular framework for estimating species abundance, particularly in support of spatial planning and decision-making (Becker et al., 2018;Mannocci, Roberts, Miller, & Halpin, 2017;Redfern et al., 2017). However, demands for solutions to large-scale management problems mean that predictions are increasingly being made far beyond the boundaries of the study regions where the data used to fit DSMs were originally collected (e.g. Mannocci, Monestiez, Spitz, & Ridoux, 2015). Statisticians usually issue strong warnings against such practice, as extrapolating relies heavily on assumptions that are unlikely to hold outside the range of sampled conditions (Conn, Johnson, & Boveng, 2015).
Consequently, most extrapolations are considered prone to errors, the magnitude of which can vary substantially across taxonomic groups, habitats, study systems and/or modelling techniques .
Despite these difficulties, untested predictions derived from the best available science are still viewed by many as more desirable than proceeding blindly. In particular, projecting models into novel contexts (e.g. new geographical areas and/or future time periods) remains a practical necessity in many risk assessments, making the ability to evaluate the extent and magnitude of extrapolation a pivotal component of research agendas in applied ecology . Although several extrapolation metrics have been proposed to address this (Table S1), there is little consensus on which works best for a given ecological scenario, and scant consideration of how results are sensitive to metric choice (Grenier, Parent, Huard, Anctil, & Chaumont, 2013). Standard protocols for supporting consistent assessments of extrapolation are therefore lacking Yates et al., 2018), leaving end users deprived of both the guidelines and the tools they require to objectively audit models projected into novel and/or data-deficient contexts.
We introduce the dsmextra R package, a user-friendly toolkit for quantitatively assessing extrapolation. The package was built as a companion to dsm, a sibling package focused on the analysis of distance sampling survey data using generalized additive models (Miller et al., 2013). However, dsmextra only requires knowledge of covariate values at sampled and prediction locations, meaning that it is not restricted to line/strip-transect data and that its functions are readily applicable to a wide variety of datasets, irrespective of how they were collected or of the statistical frameworks in which they are analysed. Here, we describe the package, explain the concepts underpinning its use and illustrate some of its features using a survey dataset on pantropical spotted dolphins Stenella attenuata in the Gulf of Mexico.

| SOF T WARE AND E X AMPLE
dsmextra provides functions (Table S2)  these functions are adapted from existing-but scattered-code released on CRAN (https://cran.r-proje ct.org/) or available as ad hoc scripts in the supplemental materials of peer-reviewed articles (e.g. Mannocci et al., 2018). dsmextra represents the first attempt to consolidate these methods while extending their usability and functionality.
Attempts at characterizing extrapolation are typically made following model calibration, as a test of model adequacy, realism and predictive performance (Robinson, Nelson, Costello, Sutherland, & Lundquist, 2017). We argue that this is unproductive, in part because model fitting can be time-consuming (especially for large datasets), meaning that there is little to gain from spending hours (or more) building a model that is unlikely to return credible outputs in the first place. Additionally, a number of comparative studies have demonstrated mixed extrapolation success among different models (or model types) fitted to the same datasets (e.g. Shabani, Kumar, & Ahmadi, 2016), suggesting that idiosyncrasies in model structures and parameterizations may result in inconsistent out-of-sample behaviour that may compromise the interpretation of model outputs.
Lastly, the independent data required for rigorous model validation are often lacking, precluding any opportunities to objectively measure the quality of model predictions under novel conditions . For these reasons, we instead suggest that extrapolation assessments take place a priori, ensuring that models that do perform poorly due to extrapolative issues outside the sampled covariate space can be identified early on and avoided ( Figure 1). Doing so requires that we determine the degree to which the sampled environmental conditions are comparable to those prevailing in the system to which the model is being projected (Guisan, Thuiller, & Zimmermann, 2017). In the past, many ecologists have typically taken a largely qualitative approach to drawing this comparison, adopting a binary view of extrapolation that only considers the ranges of each individual covariate ( Figure S1). With the compute family of functions, dsmextra improves on this by making available two quantitative metrics that capture complementary dimensions of extrapolation related to environmental analogy (i.e. conditions existing in one system but not the other) and availability (combinations of conditions and their frequency of occurrence; Guisan et al., 2017).
Together, these yield a more nuanced picture of departures from sampled conditions. compute_extrapolation is an R implementation of the Extrapolation Detection (ExDet) tool proposed by Mesgaran, Cousens, and Webber (2014), which uses Euclidean and Mahalanobis distances to characterize both univariate and combinatorial extrapolation (Bouchet et al., 2019). Detecting the latter is especially important for identifying changes in collinearity patterns among covariates, which may undermine model transferability (Rödder & Engler, 2012). dsmextra also makes it possible to identify the covariates making the largest contributions to extrapolation (the 'most influential covariates' or MIC) (Mesgaran et al., 2014). compute_nearby returns the percentage of data nearby (%N), as described by King and Zeng F I G U R E 2 Graphical comparison of the magnitude of univariate and combinatorial extrapolation associated with different sets of six input covariates. Results are summarised for (a) sets of increasing size (all combinations of one to six covariates), and (b) covariate type, and expressed as the proportion of locations (i.e. grid cells) subject to extrapolation in the prediction area. In (a, b) Nc respectively indicates the number of possible covariate combinations and the number of combinations in which each covariate is found (2007). %N relies on the Gower's distance to calculate the proportion of reference data lying within a given radius of any prediction point, with the expectation that extrapolations made in proximity to a larger amount of sample data will be better 'informed'-and thus more reliable-all else being equal ( Figure S1). As a rule, this radius is set to the mean Gower's distance between all pairs of reference points (King & Zeng, 2007); however, the nearby argument allows users to change this value. Both functions require a minimum of four inputs, some of which are similar to dsm: (a) a samples data.frame object containing the survey data used for model building; (b) a prediction.grid data. stenella.nearby <-compute_nearby(samples = survey.segs, covariate. nnames = stenella.covariates, prediction.grid = pred.grid, nearby = 1, coordinate.system = GulfMexico_proj) Extrapolated predictions should always be checked for biological plausibility, yet model users are frequently tempted to include a kaleidoscope of predictors with the expectation that the true ecological drivers among them will naturally transpire . Covariate selection thus remains a prominent issue in statistical ecology, particularly as several model formulations may fit the sample data equally well but lead to vastly diverging predictions (Dormann et al., 2012). Furthermore, the more covariates are considered, the more combinations of their values there can be and the higher the risk of extrapolation (Mahony, Cannon, Wang, & Aitken, 2017). Failure to filter variables may thus lead to unreasonable predictions of species' responses to novel conditions (Petitpierre, Broennimann, Kueffer, Daehler, & Guisan, 2017). com-pare_covariates is a wrapper around compute_extrapolation designed to run iteratively for all combinations of n.covariates, helping F I G U R E 3 Visualisation of extrapolation using the map_extrapolation function in dsmextra. Maps display the extent of extrapolation in the multivariate space defined by six input covariates, and respectively measured by (a) the Extrapolation Detection tool (ExDet) and (b) the percentage of data nearby (%N). Panel (c) shows the distribution of the most influential covariates (MIC), i.e. those making the largest contributions to univariate and combinatorial extrapolation to guide this process. The function returns graphical and tabular overviews of the covariates sets that minimize and maximize univariate and combinatorial extrapolation, measured as the number of prediction.grid cells subject to either (Figure 2). n.covariates can be supplied as any vector of integers from 1 to p, where p is the total number of covariates available. For instance, Figure 2

| D ISCUSS I ON
There is still much to learn about extrapolation and its implications for predictive inference. By extrapolating, we are without a doubt using models in risky ways and making implicit assumptions about the generality of ecological processes, which we often have no data to validate empirically. The potential for errors is therefore non-negligible, with growing evidence that predictive performance may be impaired when a model is transferred to novel contexts, especially when relationships vary geographically and/or temporally (Mannocci, Roberts, Pedersen, & Halpin, 2020) ( Figure S2). Worryingly, general understanding of extrapolation and its consequences seems to be lacking in many disciplines, often misleading practitioners and policy-makers into taking extrapolated predictions at face value, irrespective of their uncertainties and biases. Developing more rigorous extrapolation practice thus hinges on raising awareness of possible shortcomings as well as harmonizing strategies for its detection and reporting. dsmextra was conceived with this goal in mind, and offers an intuitive, model-agnostic toolkit for diagnosing extrapolation that accounts for various types of departures from reference conditions, and enables the geographic and temporal distribution of extrapolation to be easily displayed on a map. The latter is especially important for alleviating pervasive scepticism in conservation decisions, and guiding survey design by delineating areas where future sampling would likely improve model predictions.

ACK N OWLED G EM ENTS
We would like to thank Natalie Kelly and one anonymous reviewer for their thoughtful feedback on earlier versions of this manuscript. This work was funded by OPNAV N45 and the SURTASS LFA Settlement Agreement, managed by the U.S. Navy's Living Marine Resources program under Contract No. N39430-17-C-1982. The icons used in Figure 1 were made by macrovector from www.Freep ik.com and Vectors market from www.flati con.com.

AUTH O R S ' CO NTR I B UTI O N S
P.J.B. and D.L.M. conceived and designed the package. All authors contributed to developing R functions. P.J.B. led the writing of the manuscript, with critical inputs from all authors.

PE E R R E V I E W
The peer review history for this article is available at https://publo ns.com/publo n/10.1111/2041-210X.13469.

DATA AVA I L A B I L I T Y S TAT E M E N T
The package website (https://densi tymod elling.github.io/dsmex tra/) provides full documentation, including a comprehensive tutorial for novice users. Package files and code are hosted on Github at https:// github.com/densi tymod ellin g/dsmextra and archived on Zenodo at https://doi.org/10.5281/zenodo.3529465 .
The dolphin dataset used in the case study is shipped with dsm and described at http://seamap.env.duke.edu/datas et/25.