## Introduction

Spatial analysis of ecological data is central to most contemporary issues in applied ecology. Species distribution models provide key information regarding species–environment relationships, and particularly about how environmental stressors limit species distributions (Elith & Leathwick 2009). In the global context of increasing human impacts on ecosystems, predictions derived from such models can inform management plans for endangered species (Cabeza *et al.* 2004), and assessments of distributions under future land-use (Bomhard *et al.* 2005) and climate (Thuiller 2003) scenarios. Unfortunately, acquiring reliable inferences and predictions from statistical analysis of distributional data is not straightforward. One problem that must be addressed is spatial autocorrelation.

Analyses of species distributions are sensitive to spatial dependency in model residuals, or in other words, residual spatial autocorrelation (RSA; Latimer *et al.* 2006). RSA occurs when model residuals at nearby locations are not independent (Legendre 1993). RSA may arise from missing covariates that have or induce spatial structure, from incorrect specification of the functional relationship between a covariate and the response, or from neglecting to account for a spatially contagious process such as nonrandom dispersal of individuals. RSA is associated with biased Type-I error estimates owing to inflation of the effective sample size, which invalidates standard hypothesis tests (Legendre 1993). RSA may also reduce model performance (Latimer *et al.* 2006) and lead to underestimation of prediction errors (Gelfand *et al.* 2006). Hence, RSA should be avoided by correct model specification. In practice, though, important environmental covariates are often neglected because they have not been identified or are unmeasured.

Several statistical methods have emerged for modelling spatial data while accounting for RSA (e.g. see Dormann *et al.* 2007 for frequentist methods and Banerjee, Carlin & Gelfand 2003 for Bayesian methods). With freely available Monte Carlo Markov Chain (MCMC) methods, Bayesian implementation of spatially explicit models has received increasing attention from ecologists. The conditional autoregressive (CAR) model is one example of such models that is now routinely used in ecology for modelling spatial association in data sampled within areal units (Latimer *et al.* 2006), along roads (Thogmartin, Sauer & Knutson 2004) or transects (Aing *et al.* 2011) or at points (Haas *et al.* 2011). In the context of spatial regression, Beale *et al.* (2010) showed that Gaussian Bayesian CAR models fitted using MCMC yielded precise and unbiased parameter estimates with low Type-I and Type-II errors. While they are always possible to implement in principle, MCMC algorithms applied to complex hierarchical spatial models have a wide range of problems related to convergence and computation time: the fitting procedure is not guaranteed to converge or may converge very slowly. Moreover, implementation of the algorithms can prove problematic in itself, especially for users who are not expert in programming.

Integrated nested Laplace approximation (INLA) is a recent alternative to MCMC for fitting a large class of Bayesian models such as latent Gaussian models (Rue, Martino & Chopin 2009). Latent Gaussian models can account for hierarchical structure and non-Gaussian errors, as well as spatial and temporal autocorrelation (see INLA section). In fitting these models, INLA substitutes accurate, deterministic approximations to posterior marginal distributions in place of long MCMC simulations, thereby gaining in speed. The quality of such approximations is extremely high, as shown by comparisons with long MCMC runs (Rue, Martino & Chopin 2009). INLA has two main advantages over MCMC techniques. The first and most outstanding is computational: results can be obtained much faster than with a well-built MCMC-sampler. The INLA algorithm is naturally parallelized, thus making it possible to exploit the new computing trend of having multicore processors. The second advantage is that INLA permits a great deal of automation and, in practice, can be almost used as a black box to analyse latent Gaussian models. This second point is especially important in applied communities where programming expertise is limited. An R-INLA library with a user-friendly R interface (R Development Core Team 2011) is freely available at http://www.r-inla.org.

Although INLA is accurate, fast and freely available, it is still little known to ecologists. The first aim of this study is therefore to introduce this recent procedure for fitting spatially explicit hierarchical models to ecological data. To do so, we first compare results obtained with a Bayesian CAR model fitted with MCMC and INLA using spatial data on the distribution of woodland caribou in eastern Canada. Second, we present and compare the performance of an alternative hierarchical spatial model using a flexible approach with a Matérn correlation function (Minasny & McBratney 2005). Using the INLA-R library, we show how these models can be easily fitted, even by nonexpert programmers. We conclude with discussion of specific issues regarding spatial autocorrelation, the interpretation of latent spatial patterns, and the parameterization of spatial random effects in hierarchical models.