gl.dist.ind: Calculates a distance matrix for individuals defined in a...

View source: R/gl.dist.ind.r

gl.dist.indR Documentation

Calculates a distance matrix for individuals defined in a genlight object

Description

Calculates various distances between individuals based on allele frequencies or presence-absence data

Usage

gl.dist.ind(
  x,
  method = NULL,
  scale = FALSE,
  swap = FALSE,
  type = "dist",
  plot.display = TRUE,
  plot.theme = theme_dartR(),
  plot.colors = NULL,
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

x

Name of the genlight [required].

method

Specify distance measure [SNP: Euclidean; P/A: Simple].

scale

If TRUE and method='euclidean', the Euclidean distances are scaled to fall in the range [0,1]; scale is ignored for the other methods [default FALSE]

swap

If TRUE and working with presence-absence data, then presence (no disrupting mutation) is scored as 0 and absence (presence of a disrupting mutation) is scored as 1 [default FALSE].

type

Specify the type of output, "dist" or "matrix" [default "dist"]

plot.display

If TRUE, resultant plots are displayed in the plot window [default TRUE].

plot.theme

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

plot.colors

List of two color names for the borders and fill of the plots [default c("#2171B5","#6BAED6")].

plot.file

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

plot.dir

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

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

The distance measure for SNP genotypes can be one of:

  • Euclidean Distance [method = "Euclidean"]

  • Scaled Euclidean Distance [method="Euclidean", scale=TRUE]

  • Simple Mismatch Distance [method="Simple"]

  • Absolute Mismatch Distance [method="Absolute"]

  • Czekanowski (Manhattan) Distance [method="Manhattan"]

The distance measure for Sequence Tag Presence/Absence data (binary) can be one of:

  • Euclidean Distance [method = "Euclidean"]

  • Scaled Euclidean Distance [method = "Euclidean", scale = TRUE]

  • Simple Matching Distance [method = "Simple"]

  • Jaccard Distance [method = "Jaccard"]

  • Bray-Curtis Distance [method = "Bray-Curtis"]

  • Sorensen Distance [method = "Sorensen"] (identical by formula to Bray-Curtis for binary data)

Jaccard, Bray-Curtis and Sorensen are defined for presence/absence data only; requesting them for SNP data stops with an error.

For a file-backed (FBM) object the pairwise counts behind every SNP distance are added over blocks of loci read from the backing file, so the genotype matrix is never decoded as a whole; the distances are identical to those of the same data held in memory. The distance matrix itself (8 bytes per pair of individuals) is held in memory. Refer to the documentation of functions in https://doi.org/10.1101/2023.03.22.533737 for algorithms and definitions.

Value

An object of class 'matrix' or dist' giving distances between individuals

Author(s)

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

See Also

Other distance: gl.dist.pop(), gl.fst.pop(), gl.propShared(), utils.dist.ind.snp()

Examples


if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
D <- gl.dist.ind(testset.gl[1:20,1:100], method='manhattan')
D <- gl.dist.ind(testset.gs[1:20,1:100], method='Jaccard',swap=TRUE)
D <- gl.dist.ind(testset.gl[1:20,1:100], method='euclidean',scale=TRUE)


dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.