In spatial genetic correlative analyses, as soon as pairwise aggregates are associated with more than one distance measure, that is when computing inter-individual genetic distances with more than one sampled genotype per aggregate (*n* > 1) rather than interpopulation genetic distances based of allelic frequencies, Mantel tests are to be performed with restricted permutations, as pseudo-replication issues may arise when clumped genotypes are considered independent ([3] *Prunier et al. 2013*): in this case, permuted objects are the *p* blocks of *n* individuals, rather than the *n* individuals.

The following Matlab script can be used to perform simple and partial Mantel tests with standard or restricted permutations, depending on input data :

*This is the version 2.0 of the script. You now have to specify whether you intend to perform a Mantel test with classical ('c') or with restricted ('r') permutations. It prevents issues due to the spatial alignment of sampling points when using classical permutations. You can also choose to perform one-tailed or two-tailed Mantel tests.*

*Please, contact me by email for any trouble, remarks or suggestions !*

This is the R-version of *Tool #1*, now allowing MRDM (Multiple Regression on Distance Matrices) rather than (partial) Mantel test only :

*Please, contact me by email for any trouble, remarks or suggestions !*

Non-directional Mantel autocorrelograms may provide an insightful description of spatial patterns of genetic similarity among aggregates, especially when many aggregates are sampled across the study area ([3] *Prunier et al. 2013*). With only a few sampled individuals per aggregate (but many prospected aggregates), Mantel correlograms are to be performed with restricted permutations.

The following Matlab script can be used to perform spatial autocorrelation analyses through non-directional Mantel correlograms with standard or restricted permutations (depending on input data) :

*This is the version 2.0 of the script. You now have to specify whether you intend to perform a Mantel test with classical ('c') or with restricted ('r') permutations. It prevents issues due to the spatial alignment of sampling points when using classical permutations. *

*Please, contact me by email for any trouble, remarks or suggestions ! Many thanks to Dr J. Galarza for feedback on this script !*

The following figure shows an example of plots you may get when using this script (here, spatial autocorrelation analysis in 40 aggregates of 5 individuals each). Genetic data were simulated in CDPOP (Landguth & Cushman 2010)

Non-directional Mantel autocorrelograms with restricted permutations and boostrap resampling. Error bars bound the 95% confidence interval about r (y-axis) as determined by bootstrap resampling. Upper and lower confidence limits (dotted line) bound the 95% confidence interval about r under the null hypothesis of no spatial structure. Black circles indicate a significant Mantel correlation value at alpha=5%.

CDpop (Landguth & Cushman 2010) is a well-known spatially explicit, individual-based population genetics tool that simulates birth, death, mating and dispersal of individuals in complex landscape as probabilistic functions of movement costs among sampling locations.

Depending on input parameters, a thorough understanding of simulated processes and resulting gene flow is of crude importance for an accurate use of CDpop.

The following R and Matlab scripts are based on provided individual ID in CDpop format output grids. It computes the mean number of interpopulation individual exchanges per generation and provides a summary matrix in .txt format.

The matrix allows a quick and informative overview of effective connectivity among populations for each CDpop run. Diagonal elements stand for internal recruitment, e.g. the mean number of non-immigrant individuals per generation.

Matlab script : CDpopinterpopExchange.m. *This is the version 3.0 of the script, compatible with CDPOP v.1.2.18, and easily implemented in a loop.*

R script : CDpopinterpopExchange.R

*Please, contact me by email for any trouble, remarks or suggestions !*

An output matrix providing the mean number of individual exchanges among 15 populations (N=30) per generation. Diagonal elements (in orange) correspond to the mean internal recruitment per population and per generation.

Commonality analysis (CA) is a detailed variance-partitioning procedure that can be used to deal with
nonindependence among spatial predictors. By decomposing model ﬁt indices into unique and common (or shared) variance components, CA allows identifying the location and magnitude of multicollinearity, revealing spurious correlations and thus thoroughly improving the interpretation of multivariate regressions (*Prunier et al. 2015*)

The following R and Rstudio scripts can be used to perform CA in both Multivariate Regression on Distance Matrices (MRDM) and Logistic Regressions on Distance Matrices (LRDM). These scripts allow visually investigating the normality of the dependent variable, choosing between MRDM and LRDM accordingly, performing adequate bootstrapping (taking into account the non-independence of pairwise data), and getting insightful numerical and graphical outputs. Note that both scripts are identical except for the preparation of graphs, the procedure being slightly different depending on the platform you use.

* CAonDM* stands for

You will find below some graphical outputs you can get with these scripts (Here, using dataset 1 from *Prunier et al. 2015*).

This new version (v0.4) of scripts provides additional graphical and numerical outputs (notably, structures coefficients and normality tests of residuals) ! Furthermore, input data can be either an R-list of pairwise matrices or a dataframe of linearized matrices !

*Please, contact me by email for any trouble, remarks or suggestions !*

a) Distribution of the dependent variable, histogram and normal Q–Q plot of studentized residuals resulting from MRDM on quantitative datas.

b) Plot of β weights with 95% confidence intervals computed on the basis of 1000 replicates with a random removal of 10% of all 64 considered populations.

c) Plot of commonalities with 95% confidence intervals computed on the basis of 1000 replicates with a random removal of 10% of all 64 considered populations.

The following R and Rstudio scripts can be used to perform classical CA in both Linear and Logistic regressions, that is, using point data in a R-dataframe (in which each column stands for a specific vector), rather than pairwise matrices in a R-list (see Tools #5). They provide exactly the same outputs as Tools #5.

* CAonV* stands for

This new version (v0.5) of scripts provides additional graphical and numerical outputs (notably, structures coefficients and normality tests of residuals) !

*Please, contact me by email for any trouble, remarks or suggestions !*

The following R functions allow the application of the permutation-based d-sep test, clustering-based path analysis, permutation-based path analysis and a parametric bootstrap procedure dedicated to the handling of pairwise matrices in path analysis, as described in *Fourtune et al. 2018* .

* PAonDM* stands for

*Please, contact me or Lisa Fourtune by email for any trouble, remarks or suggestions !*

Macdonald et al. (Ecol. Lett., 21, 2018, 207–216; doi: 10.1111/ele.12883) proposed an analytical framework for identifying evolutionary processes underlying trait-environment relationships (TER) observed in natural populations. It is based on the visual inspection of the graphical distribution of two summary statistics (β-weights *Benv* and *Bint*; see Figure 1 in Macdonald et al. 2018) that are also used to compute another summary statistic (*L*) described as an index of local adaptation. We proposed an expanded and refined framework based on simulations and bootstrap-based approaches.To make the interpretation of *L*, *Benv* and *Bint* more objective, we designed a bootstrap procedure to estimate 95% conﬁdence intervals (CIs), and hence to take into account the uncertainty associated with each statistic. This refined approach, described in *Prunier and Blanchet (2018)*, allows directly inferring processes underlying each TER independently, even when a single trait and single environmental variable are considered.

The R script *BenvBintBootstrap.R* can be used to implement the expanded Macdonald's framework. It may be used to compute *Benv* and *Bint* β weights, RSint structure coefficients, as well 95% CI about *Benv* and *Bint* as obtained from bootstrap.

The R script *BenvBintBootstrapPlot.R* can be used to plot outputs from the *BenvBintBoostrap.R* function as in *Prunier and Blanchet (2018)*.

The R script *InteractionPlot.R* can be used to get both a fan-representation and a surface-representation of any first-order interaction.

You will find below some graphical outputs you can get with these scripts, here using the Macdonald’s empirical dataset revisited.

*Please, contact me by email for any trouble, remarks or suggestions !*

Scatterplot showing the results of 99 linear nested mixed effect models run to assess the putative driver of each TER in Macdonald et al. Symbols indicate whether a TER was found to be null (circles), driven by plasticity (squares) or driven by local adaptation (triangles) while taking uncertainty in the model estimates into account. Situations where

Scatterplot showing the distortion in

Panels a and b represent the