Skip to contents

Global spatial autocorrelation is a multivariate approach combining all loci into a single analysis. The autocorrelation coefficient "r" is calculated for each pair of individuals in each specified distance class. For more information see Smouse and Peakall 1999, Peakall et al. 2003 and Smouse et al. 2008.

Usage

gl.spatial.autoCorr(
  x = NULL,
  Dgeo = NULL,
  Dgen = NULL,
  coordinates = "latlon",
  Dgen_method = "Euclidean",
  Dgeo_trans = "Dgeo",
  Dgen_trans = "Dgen",
  bins = 5,
  reps = 100,
  plot.pops.together = FALSE,
  permutation = TRUE,
  bootstrap = TRUE,
  plot_theme = NULL,
  plot_colors_pop = NULL,
  CI_color = "red",
  plot.out = TRUE,
  save2tmp = FALSE,
  verbose = NULL
)

Arguments

x

Genlight object [default NULL].

Dgeo

Geographic distance matrix if no genlight object is provided. This is typically an Euclidean distance but it can be any meaningful (geographical) distance metrics [default NULL].

Dgen

Genetic distance matrix if no genlight object is provided [default NULL].

coordinates

Can be either 'latlon', 'xy' or a two column data.frame with column names 'lat','lon', 'x', 'y') Coordinates are provided via gl@other$latlon ['latlon'] or via gl@other$xy ['xy']. If latlon data will be projected to meters using Mercator system [google maps] or if xy then distance is directly calculated on the coordinates [default .

Dgen_method

Method to calculate genetic distances. See details [default "Euclidean"].

Dgeo_trans

Transformation to be used on the geographic distances. See Dgen_trans [default "Dgeo"].

Dgen_trans

You can provide a formula to transform the genetic distance. The transformation can be applied as a formula using Dgen as the variable to be transformed. For example: Dgen_trans = 'Dgen/(1-Dgen)'. Any valid R expression can be used here [default 'Dgen', which is the identity function.]

bins

The number of bins for the distance classes (i.e. length(bins) == 1) or a vectors with the break points. See details [default 5].

reps

The number to be used for permutation and bootstrap analyses [default 100].

plot.pops.together

Plot all the populations in one plot. Confidence intervals from permutations are not shown [default FALSE].

permutation

Whether permutation calculations for the null hypothesis of no spatial structure should be carried out [default TRUE].

bootstrap

Whether bootstrap calculations to compute the 95% confidence intervals around r should be carried out [default TRUE].

plot_theme

Theme for the plot. See details [default NULL].

plot_colors_pop

A color palette for populations or a list with as many colors as there are populations in the dataset [default NULL].

CI_color

Color for the shade of the 95% confidence intervals around the r estimates [default "red"].

plot.out

Specify if plot is to be produced [default TRUE].

save2tmp

If TRUE, saves any ggplots and listings to the session temporary directory (tempdir) [default FALSE].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log ; 3, progress and results summary; 5, full report [default NULL, unless specified using gl.set.verbosity].

Value

Returns a data frame with the following columns:

  1. Bin The distance classes

  2. N The number of pairwise comparisons within each distance class

  3. r.uc The uncorrected autocorrelation coefficient

  4. Correction the correction

  5. r The corrected autocorrelation coefficient

  6. L.r The corrected autocorrelation coefficient lower limit (if bootstap = TRUE)

  7. U.r The corrected autocorrelation coefficient upper limit (if bootstap = TRUE)

  8. L.r.null.uc The uncorrected lower limit for the null hypothesis of no spatial autocorrelation (if permutation = TRUE)

  9. U.r.null.uc The uncorrected upper limit for the null hypothesis of no spatial autocorrelation (if permutation = TRUE)

  10. L.r.null The corrected lower limit for the null hypothesis of no spatial autocorrelation (if permutation = TRUE)

  11. U.r.null The corrected upper limit for the null hypothesis of no spatial autocorrelation (if permutation = TRUE)

  12. p.one.tail The p value of the one tail statistical test

Details

This function executes a modified version of spautocorr from the package PopGenReport. Differently from PopGenReport, this function also computes the 95% confidence intervals around the r via bootstraps, the 95 null hypothesis of no spatial structure and the one-tail test via permutation, and the correction factor described by Peakall et al 2003.

The input can be i) a genlight object (which has to have the latlon slot populated), ii) a pair of Dgeo and Dgen, which have to be either matrix or dist objects, or iii) a list of the matrix or dist objects if the analysis needs to be carried out for multiple populations (in this case, all the elements of the list have to be of the same class (i.e. matrix or dist) and the population order in the two lists has to be the same.

If the input is a genlight object, the function calculates the linear distance for Dgeo and the relevant Dgen matrix (see Dgen_method) for each population. When the method selected is a genetic similarity matrix (e.g. "simple" distance), the matrix is internally transformed with 1 - Dgen so that positive values of autocorrelation coefficients indicates more related individuals similarly as implemented in GenAlEx. If the user provide the distance matrices, care must be taken in interpreting the results because similarity matrix will generate negative values for closely related individuals.

If max(Dgeo)>1000 (e.g. the geographic distances are in thousands of metres), values are divided by 1000 (in the example before these would then become km) to facilitate readability of the plots.

If bins is of length = 1 it is interpreted as the number of (even) bins to use. In this case the starting point is always the minimum value in the distance matrix, and the last is the maximum. If it is a numeric vector of length>1, it is interpreted as the breaking points. In this case, the first has to be the lowest value, and the last has to be the highest. There are no internal checks for this and it is user responsibility to ensure that distance classes are properly set up. If that is not the case, data that fall outside the range provided will be dropped. The number of bins will be length(bins) - 1.

The permutation constructs the 95% confidence intervals around the null hypothesis of no spatial structure (this is a two-tail test). The same data are also used to calculate the probability of the one-tail test (See references below for details).

Bootstrap calculations are skipped and NA is returned when the number of possible combinations given the sample size of any given distance class is < reps.

Methods available to calculate genetic distances for SNP data:

Methods available to calculate genetic distances for SilicoDArT data:

Plots and table are saved to the temporal directory (tempdir) and can be accessed with the function gl.print.reports and listed with the function gl.list.reports. Note that they can be accessed only in the current R session because tempdir is cleared each time that the R session is closed.

Examples of other themes that can be used can be consulted in

References

  • Smouse PE, Peakall R. 1999. Spatial autocorrelation analysis of individual multiallele and multilocus genetic structure. Heredity 82: 561-573.

  • Double, MC, et al. 2005. Dispersal, philopatry and infidelity: dissecting local genetic structure in superb fairy-wrens (Malurus cyaneus). Evolution 59, 625-635.

  • Peakall, R, et al. 2003. Spatial autocorrelation analysis offers new insights into gene flow in the Australian bush rat, Rattus fuscipes. Evolution 57, 1182-1195.

  • Smouse, PE, et al. 2008. A heterogeneity test for fine-scale genetic structure. Molecular Ecology 17, 3389-3400.

  • Gonzales, E, et al. 2010. The impact of landscape disturbance on spatial genetic structure in the Guanacaste tree, Enterolobium cyclocarpum (Fabaceae). Journal of Heredity 101, 133-143.

  • Beck, N, et al. 2008. Social constraint and an absence of sex-biased dispersal drive fine-scale genetic structure in white-winged choughs. Molecular Ecology 17, 4346-4358.

Author

Carlo Pacioni, Bernd Gruber & Luis Mijangos (Post to https://groups.google.com/d/forum/dartr)

Examples

# \donttest{
require("dartR.data")
res <- gl.spatial.autoCorr(platypus.gl, bins=seq(0,10000,2000))
#> Starting gl.spatial.autoCorr 
#>   Analysis performed on the genlight object.
#> 

#>   Coordinates used from: x@other$latlon (Mercator transformed) 
#>   Transformation of Dgeo: Dgeo 
#>   Genetic distance: Euclidean 
#>   Tranformation of Dgen:  Dgen 
#> $SEVERN_ABOVE
#>     Bin  N        r.uc Correction             r          L.r          U.r
#> 1  2000 76 -0.02564315 0.04545455  0.0198113993  0.002186888  0.042801625
#> 2  4000 32 -0.07220725 0.04545455 -0.0267527002 -0.037957563 -0.015770390
#> 3  6000 13 -0.04414587 0.04545455  0.0013086741 -0.007002320  0.009418026
#> 4  8000  8 -0.06046684 0.04545455 -0.0150122948 -0.047718665  0.012329992
#> 5 10000 23 -0.04622188 0.04545455 -0.0007673346 -0.020133414  0.022471028
#>   L.r.null.uc U.r.null.uc    L.r.null   U.r.null p.one.tail
#> 1 -0.05498292 -0.03215896 -0.00952837 0.01329559       0.01
#> 2 -0.06613841 -0.02434717 -0.02068387 0.02110738       0.00
#> 3 -0.06651506 -0.01096856 -0.02106051 0.03448598       0.57
#> 4 -0.07887799 -0.01511102 -0.03342345 0.03034353       0.22
#> 5 -0.06514824 -0.02724258 -0.01969370 0.01821196       0.43
#> 
#> $SEVERN_BELOW
#>     Bin  N        r.uc Correction             r           L.r         U.r
#> 1  2000 17 -0.05393927     0.0625  0.0085607267 -0.0086902590 0.031007604
#> 2  4000 24 -0.04707985     0.0625  0.0154201481 -0.0000196379 0.028993794
#> 3  6000  9 -0.06664774     0.0625 -0.0041477406 -0.0342505737 0.019405257
#> 4  8000 30 -0.06997976     0.0625 -0.0074797574 -0.0177938696 0.003185218
#> 5 10000 21 -0.06198526     0.0625  0.0005147397 -0.0121786361 0.018082288
#>   L.r.null.uc U.r.null.uc     L.r.null   U.r.null p.one.tail
#> 1 -0.08255125 -0.04558095 -0.020051254 0.01691905       0.14
#> 2 -0.07507161 -0.04823637 -0.012571606 0.01426363       0.01
#> 3 -0.08038917 -0.04559409 -0.017889170 0.01690591       0.33
#> 4 -0.07170738 -0.05072362 -0.009207384 0.01177638       0.04
#> 5 -0.07497562 -0.04815008 -0.012475616 0.01434992       0.44
#> 
#> $TENTERFIELD
#>     Bin   N         r.uc Correction             r          L.r         U.r
#> 1  2000 110 -0.001971616      0.025  2.302838e-02  0.008980646 0.042430807
#> 2  4000  54 -0.031927379      0.025 -6.927379e-03 -0.017704510 0.003485523
#> 3  6000  67 -0.025089835      0.025 -8.983472e-05 -0.008458303 0.008413280
#> 4  8000  20 -0.019438357      0.025  5.561643e-03 -0.010372635 0.019333636
#> 5 10000  37 -0.024745610      0.025  2.543903e-04 -0.011459280 0.017521843
#>   L.r.null.uc  U.r.null.uc     L.r.null   U.r.null p.one.tail
#> 1 -0.03320862 -0.014659282 -0.008208619 0.01034072       0.00
#> 2 -0.03755126 -0.009700107 -0.012551262 0.01529989       0.18
#> 3 -0.03532374 -0.013177642 -0.010323741 0.01182236       0.64
#> 4 -0.04079043  0.013196920 -0.015790431 0.03819692       0.19
#> 5 -0.03952234 -0.010117703 -0.014522339 0.01488230       0.44
#> 
#> Completed: gl.spatial.autoCorr 
#> 
# using one population, showing sample size
test <- gl.keep.pop(platypus.gl,pop.list = "TENTERFIELD")
#> Starting gl.keep.pop 
#>   Processing genlight object with SNP data
#>   Warning: data include loci that are scored NA across all individuals.
#>   Consider filtering using gl <- gl.filter.allna(gl)
#>   Checking for presence of nominated populations
#>   Retaining only populations TENTERFIELD 
#>   Warning: Resultant dataset may contain monomorphic loci
#>   Locus metrics not recalculated
#> Completed: gl.keep.pop 
#> 
res <- gl.spatial.autoCorr(test, bins=seq(0,10000,2000),CI_color = "green")
#> Starting gl.spatial.autoCorr 
#>   Analysis performed on the genlight object.
#> 
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.

#>   Coordinates used from: x@other$latlon (Mercator transformed) 
#>   Transformation of Dgeo: Dgeo 
#>   Genetic distance: Euclidean 
#>   Tranformation of Dgen:  Dgen 
#> $TENTERFIELD
#>     Bin   N         r.uc Correction             r          L.r         U.r
#> 1  2000 110 -0.001971616      0.025  2.302838e-02  0.006177584 0.046089658
#> 2  4000  54 -0.031927379      0.025 -6.927379e-03 -0.016069334 0.003954427
#> 3  6000  67 -0.025089835      0.025 -8.983472e-05 -0.008797311 0.008154147
#> 4  8000  20 -0.019438357      0.025  5.561643e-03 -0.015974007 0.016444506
#> 5 10000  37 -0.024745610      0.025  2.543903e-04 -0.010420643 0.015527516
#>   L.r.null.uc  U.r.null.uc     L.r.null   U.r.null p.one.tail
#> 1 -0.03336787 -0.014358586 -0.008367874 0.01064141       0.00
#> 2 -0.03627298 -0.007285241 -0.011272975 0.01771476       0.08
#> 3 -0.03451288 -0.008479086 -0.009512876 0.01652091       0.39
#> 4 -0.04320952  0.009828255 -0.018209519 0.03482825       0.23
#> 5 -0.03915205 -0.008647385 -0.014152045 0.01635262       0.40
#> 
#> Completed: gl.spatial.autoCorr 
#> 
# }
test <- gl.keep.pop(platypus.gl,pop.list = "TENTERFIELD")
#> Starting gl.keep.pop 
#>   Processing genlight object with SNP data
#>   Warning: data include loci that are scored NA across all individuals.
#>   Consider filtering using gl <- gl.filter.allna(gl)
#>   Checking for presence of nominated populations
#>   Retaining only populations TENTERFIELD 
#>   Warning: Resultant dataset may contain monomorphic loci
#>   Locus metrics not recalculated
#> Completed: gl.keep.pop 
#> 
res <- gl.spatial.autoCorr(test, bins=seq(0,10000,2000),CI_color = "green")
#> Starting gl.spatial.autoCorr 
#>   Analysis performed on the genlight object.
#> 
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.

#>   Coordinates used from: x@other$latlon (Mercator transformed) 
#>   Transformation of Dgeo: Dgeo 
#>   Genetic distance: Euclidean 
#>   Tranformation of Dgen:  Dgen 
#> $TENTERFIELD
#>     Bin   N         r.uc Correction             r          L.r         U.r
#> 1  2000 110 -0.001971616      0.025  2.302838e-02  0.005981018 0.050318428
#> 2  4000  54 -0.031927379      0.025 -6.927379e-03 -0.015702721 0.002032892
#> 3  6000  67 -0.025089835      0.025 -8.983472e-05 -0.007213233 0.006633325
#> 4  8000  20 -0.019438357      0.025  5.561643e-03 -0.007675353 0.020588165
#> 5 10000  37 -0.024745610      0.025  2.543903e-04 -0.013046058 0.017942032
#>   L.r.null.uc  U.r.null.uc     L.r.null    U.r.null p.one.tail
#> 1 -0.03335178 -0.016516067 -0.008351782 0.008483933       0.00
#> 2 -0.03609696 -0.012860555 -0.011096960 0.012139445       0.19
#> 3 -0.03726668 -0.009925303 -0.012266678 0.015074697       0.49
#> 4 -0.04197121  0.008491727 -0.016971206 0.033491727       0.17
#> 5 -0.03923018  0.000276256 -0.014230176 0.025276256       0.41
#> 
#> Completed: gl.spatial.autoCorr 
#>