Type: Package
Title: Applying Landscape Genomic Methods on 'SNP' and 'Silicodart' Data
Version: 1.0.3
Date: 2025-08-21
Description: Provides landscape genomic functions to analyse 'SNP' (single nuclear polymorphism) data, such as least cost path analysis and isolation by distance. Therefore each sample needs to have coordinate data attached (lat/lon) to be able to run most of the functions. 'dartR.spatial' is a package that belongs to the 'dartRverse' suit of packages and depends on 'dartR.base' and 'dartR.data'.
Revision: Attractive Abalone
Encoding: UTF-8
Depends: R (≥ 3.5), adegenet (≥ 2.0.0), dartR.base, dartR.data
Imports: methods, utils, crayon, StAMPP, raster, sp, tidyr, vegan, MASS, ggplot2, data.table, grDevices, dismo
Suggests: mmod, gdistance, gplots, rrBLUP, terra (≥ 1.7-39), sf, PopGenReport
License: GPL (≥ 3)
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-08-21 23:07:41 UTC; s425824
Author: Bernd Gruber [aut, cre], Arthur Georges [aut], Jose L. Mijangos [aut], Carlo Pacioni [aut], Peter J. Unmack [ctb], Oliver Berry [ctb]
URL: https://green-striped-gecko.github.io/dartR/
BugReports: https://groups.google.com/g/dartr?pli=1
Maintainer: Bernd Gruber <bernd.gruber@canberra.edu.au>
Repository: CRAN
Date/Publication: 2025-08-22 02:20:02 UTC

Calculates cost distances for a given landscape (resistance matrix)

Description

Calculates a cost distance matrix, to be used with run.popgensim.

Usage

gl.costdistances(landscape, locs, method, NN, verbose = NULL)

Arguments

landscape

A raster object coding the resistance of the landscape [required].

locs

Coordinates of the subpopulations. If a genlight object is provided coordinates are taken from @other$latlon and centers for population (pop(gl)) are calculated. In case you want to calculate costdistances between individuals redefine pop(gl) via: pop(gl)<- indNames(gl) [required].

method

Defines the type of cost distance, types are 'leastcost', 'rSPDistance' or 'commute' (Circuitscape type) [required].

NN

Number of next neighbours recommendation is 8 [required].

verbose

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

Value

A costdistance matrix between all pairs of locs.

Examples

data(possums.gl)
library(raster)  #needed for that example
landscape.sim <- readRDS(system.file('extdata','landscape.sim.rdata', 
package='dartR.data'))
#calculate mean centers of individuals per population
xy <- apply(possums.gl@other$xy, 2, function(x) tapply(x, pop(possums.gl),
 mean))
cd <- gl.costdistances(landscape.sim, xy, method='leastcost', NN=8)
round(cd,3)

Performs least-cost path analysis based on a friction matrix

Description

This function calculates pairwise distances (Euclidean, cost path distances and genetic distances) between populations or between individuals using a friction matrix and a spatial genlight object. The genlight object needs to have coordinates in the same projected coordinate system as the friction matrix. The friction matrix can be either a single raster or a stack of several layers. If a stack is provided the specified cost distance is calculated for each layer in the stack. The output of this function can be used with the functions wassermann from package PopGenReport and lgrMMRR from package PopGenReport to test for the significance of a layer on the genetic structure.

Genetic distances between individuals are 'kosman' and 'propShared'.

Usage

gl.genleastcost(
  x,
  fric.raster,
  gen.distance = "Gst.Nei",
  NN = 8,
  pathtype = "leastcost",
  plotpath = TRUE,
  theta = 1,
  plot.colors.pop = gl.colors("dis"),
  raster.colors = rev(terrain.colors(255)),
  verbose = NULL
)

Arguments

x

A spatial genlight object. [required].

fric.raster

A friction matrix [required].

gen.distance

Specification which genetic distance method should be used to calculate pairwise genetic distances between populations ( 'D', 'Gst.Nei', 'Gst.Hedrick') or individuals ('kosman', 'propShared') [default "Gst.Nei"].

NN

Number of neighbours used when calculating the cost distance (possible values 4, 8 or 16). NN=8 is most commonly used. Be aware that linear structures may cause artefacts in the least-cost paths, therefore inspect the actual least-cost paths in the provided output [default 8].

pathtype

Type of cost distance to be calculated (based on function in the gdistance package. Available distances are 'leastcost', 'commute' or 'rSPDistance'. See functions in the gdistance package for futher explanations. If the path type is set to 'leastcost' then paths and also pathlength are returned [default 'leastcost'].

plotpath

switch if least cost paths should be plotted (works only if pathtype='leastcost'. Be aware this slows down the computation, but it is recommended to do this to check least cost paths visually.

theta

value needed for rSPDistance function. See rSPDistance in package gdistance [default 1].

plot.colors.pop

A color palette for population plots or a list with as many colors as there are populations in the dataset [default gl.colors("dis")].

raster.colors

The color palette to use to color the raster values [default rev(terrain.colors(255))].

verbose

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

Details

Genetic distances between populations are 'D', 'Gst.Nei' and 'Gst.Hedrick'.

Value

Returns a list that consists of four pairwise distance matrices (Euclidean, Cost, length of path and genetic) and the actual paths as spatial line objects.

Author(s)

Bernd Gruber (bugs? Post to https://groups.google.com/d/forum/dartr)

References

Examples

#this example takes about 20 seconds to run...
data(possums.gl)
library(raster)  #needed for that example
landscape.sim <- readRDS(system.file('extdata','landscape.sim.rdata', 
package='dartR.data'))
#use only 3 population (first 90 individuals) due to speed
#glc <- gl.genleastcost(x=possums.gl,fric.raster=landscape.sim ,
#gen.distance = 'D', NN=8, pathtype = 'leastcost',plotpath = TRUE)
#### run tests as implemented in PopGenreport (maybe need to install)
#if (require("PopGenReport", quietly=TRUE)) {
#PopGenReport::wassermann(eucl.mat = glc$eucl.mat, cost.mat = glc$cost.mats, 
#gen.mat = glc$gen.mat)
#lgrMMRR(gen.mat = glc$gen.mat, cost.mats = glc$cost.mats,  
#eucl.mat = glc$eucl.mat)
#}

Calculates an identity by descent matrix

Description

This function calculates the mean probability of identity by state (IBS) across loci that would result from all the possible crosses of the individuals analyzed. IBD is calculated by an additive relationship matrix approach developed by Endelman and Jannink (2012) as implemented in the function A.mat (package rrBLUP).

Usage

gl.grm2(
  x,
  plotheatmap = TRUE,
  palette_discrete = NULL,
  palette_convergent = NULL,
  legendx = 0,
  legendy = 0.5,
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL,
  ...
)

Arguments

x

Name of the genlight object containing the SNP data [required].

plotheatmap

A switch if a heatmap should be shown [default TRUE].

palette_discrete

The color of populations [NULL].

palette_convergent

A convergent palette for the IBD values [default convergent_palette].

legendx

x coordinates for the legend[default 0].

legendy

y coordinates for the legend[default 1].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL]

plot.dir

Directory in which to save files [default = working directory]

verbose

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

...

Parameters passed to function A.mat from package rrBLUP.

Details

Two or more alleles are identical by descent (IBD) if they are identical copies of the same ancestral allele in a base population. The additive relationship matrix is a theoretical framework for estimating a relationship matrix that is consistent with an approach to estimate the probability that the alleles at a random locus are identical in state (IBS).

This function also plots a heatmap, and a dendrogram, of IBD values where each diagonal element has a mean that equals 1+f, where f is the inbreeding coefficient (i.e. the probability that the two alleles at a randomly chosen locus are IBD from the base population). As this probability lies between 0 and 1, the diagonal elements range from 1 to 2. Because the inbreeding coefficients are expressed relative to the current population, the mean of the off-diagonal elements is -(1+f)/n, where n is the number of loci. Individual names are shown in the margins of the heatmap and colors represent different populations.

Value

An identity by descent matrix

Author(s)

Custodian: Arthur Georges – Post to https://groups.google.com/d/forum/dartr

References

Examples

require(dartR.base)  
gl.grm2(platypus.gl[1:10,1:100])


Performs isolation by distance analysis

Description

This function performs an isolation by distance analysis based on a Mantel test and also produces an isolation by distance plot. If a genlight object with coordinates is provided, then an Euclidean and genetic distance matrices are calculated.'

Usage

gl.ibd(
  x = NULL,
  distance = "Fst",
  coordinates = "latlon",
  Dgen = NULL,
  Dgeo = NULL,
  Dgeo_trans = "Dgeo",
  Dgen_trans = "Dgen",
  permutations = 999,
  plot.out = TRUE,
  paircols = NULL,
  plot.theme = theme_dartR(),
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

x

Genlight object. If provided a standard analysis on Fst/1-Fst and log(distance) is performed [required].

distance

Type of distance that is calculated and used for the analysis. Can be either population based 'Fst' [stamppFst], 'D' [stamppNeisD] or individual based 'propShared', [gl.propShared], 'euclidean' [gl.dist.ind, method='Euclidean'], 'kosman' [gl.kosman] [default "Fst"].

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.

Dgen

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

Dgeo

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

Dgeo_trans

Transformation to be used on the Euclidean 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.]

permutations

Number of permutations in the Mantel test [default 999].

plot.out

Should an isolation by distance plot be returned [default TRUE].

paircols

Should pairwise dots colored by 'pop'ulation/'ind'ividual pairs [default 'pop']. You can color pairwise individuals by pairwise population colors.

plot.theme

Theme for the plot. See details for options [default theme_dartR()].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL]

plot.dir

Directory in which to save files [default = working directory]

verbose

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

Details

Currently pairwise Fst and D between populations and 1-propShared and Euclidean distance between individuals are implemented. Coordinates are expected as lat long and converted to Google Earth Mercator projection. If coordinates are already projected, provide them at the x@other$xy slot.

You can provide also your own genetic and Euclidean distance matrices. The function is based on the code provided by the adegenet tutorial (http://adegenet.r-forge.r-project.org/files/tutorial-basics.pdf), using the functions mantel (package vegan), stamppFst, stamppNeisD (package StAMPP) and gl.propShared or gl.dist.ind. For transformation you need to have the dismo package installed. As a new feature you can plot pairwise relationship using double colored points (paircols=TRUE). Pairwise relationship can be visualised via populations or individuals, depending which distance is calculated. Please note: Often a problem arises, if an individual based distance is calculated (e.g. propShared) and some individuals have identical coordinates as this results in distances of zero between those pairs of individuals.

If the standard transformation [log(Dgeo)] is used, this results in an infinite value, because of trying to calculate'log(0)'. To avoid this, the easiest fix is to change the transformation from log(Dgeo) to log(Dgeo+1) or you could add some "noise" to the coordinates of the individuals (e.g. +- 1m, but be aware if you use lat lon then you rather want to add +0.00001 degrees or so).

Value

Returns a list of the following components: Dgen (the genetic distance matrix), Dgeo (the Euclidean distance matrix), Mantel (the statistics of the Mantel test).

Author(s)

Bernd Gruber (bugs? Post to https://groups.google.com/d/forum/dartr)

References

Rousset, F. (1997). Genetic differentiation and estimation of gene flow from F-statistics under isolation by distance. Genetics, 145(4), 1219-1228.

See Also

mantel, stamppFst

Examples

 
#because of speed only the first 100 loci
ibd <- gl.ibd(bandicoot.gl[,1:100], Dgeo_trans='log(Dgeo)' ,
Dgen_trans='Dgen/(1-Dgen)')
#because of speed only the first 10 individuals)
ibd <- gl.ibd(bandicoot.gl[1:10,], distance='euclidean', paircols='pop', 
Dgeo_trans='Dgeo')

#only first 100 loci
ibd <- gl.ibd(bandicoot.gl[,1:100], paircols='pop')

Calculates a Kosman distance matrix for each pair of individuals

Description

This script calculates an individual based distance matrix.

Usage

gl.kosman(x, verbose = NULL)

Arguments

x

genlight/dartR object with a unique ploidy

verbose

verbosity of the function.

Value

returns a matrix of [dimensions nInd(x) x nInd(x)] of kosman distances between individuals,

Examples

#use only five individuals and seven loci
gg <- gl.kosman(possums.gl[1:5,14:21])
gg$kosman
gg$nloci

Runs the EEMS algorithm (Estimating Effective Migration Surfaces) on a genlight object.

Description

This function runs the EEMS algorithm on a genlight object. The EEMS algorithm is a spatially explicit model that estimates effective migration surfaces (EEMS) from genetic data. The EEMS algorithm is implemented in C++, hence it is necessary to have the binary downloaded and the function needs to point to this file via the path specified in eems.path. The binary is call runeems_snps[.exe] and can be downloaded from the github site of dartR.

Usage

gl.run.eems(
  x,
  eems.path = "./",
  buffer = 10000,
  nDemes = 500,
  diploid = TRUE,
  numMCMCIter = 10000,
  numBurnIter = 2000,
  numThinIter = 9,
  seed = NULL,
  dpi = 250,
  add_grid = FALSE,
  col_grid = "#BBBBBB",
  add_demes = FALSE,
  col_demes = "#000000",
  add_outline = FALSE,
  col_outline = "#FFFFFF",
  eems_colors = NULL,
  plot.colors.pop = gl.colors("dis"),
  out.dir = NULL,
  plot.dir = NULL,
  plot.file = NULL,
  verbose = NULL,
  cleanup = TRUE,
  ...
)

Arguments

x

Name of the genlight object containing the SNP data [required].

eems.path

Path to the folder containing the eems executable [default working directory ("./")].

buffer

Buffer distance for all the elements [default 10000].

nDemes

The approximate number of demes in the population graph [default 500].

diploid

Whether the organism is diploid [default TRUE].

numMCMCIter

Number of MCMC iterations [default 10000].

numBurnIter

Number of burn-in iterations to discard at the start [default 2000].

numThinIter

Number of iterations to thin between two writing steps [default 9].

seed

An integer used to seed the random number generator [default NULL].

dpi

Resolution of the contour raster [default 250].

add_grid

A logical value indicating whether to add the population grid or not [default FALSE].

col_grid

The color of the population grid [default gray ("#BBBBBB")].

add_demes

A logical value indicating whether to add the observed demes or not [default FALSE].

col_demes

The color of the demes [default black ("#000000")].

add_outline

A logical value indicating whether to add the habitat outline or not [default FALSE].

col_outline

The color of the habitat outline [default white ("#FFFFFF")].

eems_colors

The EEMS color scheme as a vector of colors, ordered from low to high [default NULL].

plot.colors.pop

A color palette for population plots or a list with as many colors as there are populations in the dataset [default gl.colors("dis")].

out.dir

Path where to save the output file. Use outpath=getwd() or out.dir='.' when calling this function to direct output files to your working or current directory [default tempdir(), mandated by CRAN].

plot.dir

Directory to save the plot RDS files [default as specified by the global working directory or tempdir()].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL].

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].

cleanup

Whether to delete intermediate files [default TRUE].

...

Extra parameters to add to function reemsplots2::make_eems_plots.

Details

Set the Number of MCMC iterations to 2 million for an initial run. If the posterior trace is still trending, lengthen the chain. Set the number of initial burnin iterations at 50 thin between writes so that total/thin is around 100–200; a 10000‑step thinning interval is a practical default.

Choose the number of demes to match geographic scale: 100–250 for local or island studies and 300–500 for continental datasets. Runtime grows cubically with number of demes, so anything above 1000 rarely pays off.

Draw the habitat polygon with a small buffer (in meters), so every sample sits at least one grid spacing inside the edge. A 5–10 sample bounding box (or a few kilometres for fine‑scale work) is usually adequate.

For plots, use a raster resolution of 600 dpi, this is publication‑quality. Drop to 300 dpi for quick diagnostics. Higher detail—higher resolution affects file size, not the inference itself.

Value

A list of contour plots of migration and diversity rates as well as several diagnostic plots. It is a good idea to examine all these figures, which is why they are generated by default. Please check the examples how to customise the figures.

mrates01

Effective migration surface. This contour plot visualises the estimated effective migration rates m, on the log10 scale after mean centering.

mrates02

Posterior probability contours P(log(m) > 0) = p and P(log(m) < 0) = p for the given probability level p. Since migration rates are visualised on the log10 scale after mean centering, 0 corresponds to the overall mean migration rate. This contour plot emphasizes regions with effective migration that is significantly higher/lower than the overall average.

qrates01

Effective diversity surface. This contour plot visualises the estimated effective diversity rates q, on the log10 scale after mean centering.

qrates02

Posterior probability contours P(log(q) > 0) = p and P(log(q) < 0) = p. Similar to mrates02 but applied to the effective diversity rates.

rdist01

Scatter plot of the observed vs the fitted between-deme component of genetic dissimilarity, where one point represents a pair of sampled demes.

rdist02

Scatter plot of the observed vs the fitted within-deme component of genetic dissimilarity, where one point represents a sampled deme.

rdist03

Scatter plot of observed genetic dissimilarities between demes vs observed geographic distances between demes.

pilogl01

Posterior probability trace

Author(s)

Bernd Gruber & Robyn (bugs? Post to https://groups.google.com/d/forum/dartr)

References

Examples

 ## Not run: 
 # This example needs a binary (runeems_snps[.exe]) specific to your 
 # operating system  to run
 eems <- gl.run.eems(bandicoot.gl, eems.path = "d:/downloads/eems/")
 print(eems[[1]])
 
## End(Not run)


Spatial autocorrelation following Smouse and Peakall 1999

Description

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,
  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 = theme_dartR(),
  plot.colors.pop = NULL,
  CI.color = "red",
  plot.out = TRUE,
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

x

Name of the genlight object containing the SNP data [required].

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 "latlon"].

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].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL] temporary directory (tempdir) [default FALSE].

plot.dir

Directory in which to save files [default = working directory]

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2,

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:

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

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

Plots and table are saved plot.file in plot.dir if specified. Bootstraps and permutations (if requested) are saved in a temporary directory

Author(s)

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

References

Examples


require("dartR.data")
res <- gl.spatial.autoCorr(platypus.gl, bins=seq(0,10000,2000))
# using one population, showing sample size
test <- gl.keep.pop(platypus.gl,pop.list = "TENTERFIELD")
res <- gl.spatial.autoCorr(test, bins=seq(0,10000,2000),CI.color = "green")

test <- gl.keep.pop(platypus.gl,pop.list = "TENTERFIELD")
res <- gl.spatial.autoCorr(test, bins=seq(0,10000,2000),CI.color = "green")

Converts a genlight object to ESRI shapefiles or kml files

Description

This function exports coordinates in a genlight object to a point shape file (including also individual meta data if available). Coordinates are provided under x@other$latlon and assumed to be in WGS84 coordinates, if not proj4 string is provided.

Usage

gl2shp(
  x,
  type = "shp",
  proj4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
  outfile = "gl",
  outpath = tempdir(),
  verbose = NULL
)

Arguments

x

Name of the genlight object containing the SNP data and location data, lat longs [required].

type

Type of output 'kml' or 'shp' [default 'shp'].

proj4

Proj4string of data set (see spatialreference.org for projections) [default WGS84].

outfile

Name (path) of the output shape file [default 'gl']. shp extension is added automatically.

outpath

Path where to save the output file [default tempdir(), mandated by CRAN]. Use outpath=getwd() or outpath='.' when calling this function to direct output files to your working directory.

verbose

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

Value

returns a SpatVector file

Author(s)

Bernd Guber (Post to https://groups.google.com/d/forum/dartr)

Examples

out <- gl2shp(testset.gl, outpath=tempdir())

Spatial autocorrelation coefficient calculations

Description

Carries out calculation for spatial autocorrelation coefficient starting from a genetic and geogaphic distance matrix.

Usage

utils.spautocor(
  GD,
  GGD,
  permutation = FALSE,
  bootstrap = FALSE,
  bins = 10,
  reps
)

Arguments

GD

Genetic distance matrix.

GGD

Geographic distance matrix.

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].

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].

Details

The code of this function is based one spautocorr from the package PopGenReport, which has been modified to fix a few bugs (as of PopGenReport v 3.0.4 and allow calculations of bootstraps estimates.

See details from gl.spatial.autoCorr for a detailed explanation.

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

if both bootstap and permutation are FALSE otherwise only r estimates are returned

Author(s)

Carlo Pacioni & Bernd Gruber

References

See Also

gl.spatial.autoCorr

Examples

# See gl.spatial.autoCorr

Setting up the package dartR.spatial

Description

Setting up dartR.spatial

Usage

zzz

Format

An object of class NULL of length 0.

mirror server hosted at Truenetwork, Russian Federation.