gl.test.heterozygosity: Tests the difference in heterozygosity between populations...

View source: R/gl.test.heterozygosity.r

gl.test.heterozygosityR Documentation

Tests the difference in heterozygosity between populations taken pairwise

Description

Tests whether the unbiased expected heterozygosity (uHe) differs between populations, for every pair of populations in a genlight object. The uHe of each population is bootstrapped (resampling individuals or loci, see Details), and for each pair the function returns the observed difference (pop1 - pop2), a bootstrap confidence interval, a significance label and a two-sided p value (raw and Benjamini-Hochberg adjusted across pairs). uHe is corrected for sample size following equation 2 of Nei (1978).

Usage

gl.test.heterozygosity(
  x,
  nreps = 1000,
  boot.method = "ind",
  alpha1 = 0.05,
  alpha2 = 0.01,
  conf = 0.95,
  plot.out = TRUE,
  max_plots = 6,
  plot.theme = theme_dartR(),
  plot.colors = gl.select.colors(ncolors = 2, verbose = 0),
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

x

A genlight object containing the SNP genotypes [required].

nreps

Number of bootstrap replicates used to build the sampling distribution of each pairwise difference [default 1,000].

boot.method

Resample across individuals ("ind") or across loci ("loc") when bootstrapping the heterozygosity of each population [default "ind"].

alpha1

First significance level for the two-sided test of diff=0, used for the significance label and the plot [default 0.05].

alpha2

Second significance level for the two-sided test of diff=0, used for the significance label and the plot [default 0.01].

conf

Confidence level for the bootstrap confidence interval of each pairwise difference [default 0.95].

plot.out

If TRUE, plots a sampling distribution of the differences for each comparison [default TRUE].

max_plots

Maximum number of plots to print per page [default 6].

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 gl.select.colors(ncolors = 2, verbose = 0)].

plot.file

Base name (no extension) for the RDS files that save each page of plots and the result table; see Details [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, brief progress messages; 3, progress and results summary; 5, full report [default 2, unless specified using gl.set.verbosity].

Details

Choosing the resampling unit (boot.method)

The uHe of each population is bootstrapped with the same engine as gl.report.heterozygosity, and boot.method sets what is resampled. The two units answer different questions and can yield different confidence intervals and p values for the same data:

  • "ind" (default) resamples individuals. It treats the sampled individuals as a sample of each population and tests whether the two populations differ in heterozygosity. This is the usual question.

  • "loc" resamples loci, with the individuals held fixed. It tests whether the genome-wide difference is consistent across loci rather than driven by a few of them, and does not generalise to the populations the individuals came from. Use it only when the individuals are effectively a census of each group (for example a fully sampled captive lineage or a complete cohort), where there is no individual-sampling variance to account for; with a sample of individuals from each population, use "ind".

For "loc" the loci are resampled independently within each population and treated as independent, so the interval ignores linkage and is approximate.

Interpreting the plot

With plot.out = TRUE one histogram is drawn per pair of populations. The histogram is the bootstrap distribution of the difference in uHe (pop1 - pop2), with four vertical lines:

  • green: the observed difference.

  • blue: zero (no difference).

  • two dark red lines: the significance limits at level alpha1 (default 0.05).

  • two bright red lines: the limits at level alpha2 (default 0.01).

The red lines are the alpha/2 and 1 - alpha/2 quantiles of the bootstrap distribution, so they bound a two-sided test at each level. Read significance from the blue zero line, not the green one. If zero lies outside the red lines of a given level, the difference is significant at that level; if it lies inside the alpha1 lines, the difference is not significant. The significance label and the p value in the table are computed the same way and agree with each other, except that the p value cannot fall below 2 / (nreps + 1): with few replicates a pair can carry the stricter label while its p value stays at that floor, so use nreps of 1000 or more when the p values matter. The green observed line sits near the centre of its own bootstrap distribution by construction, so its position is not the test. Each panel subtitle gives the significance label and the p value.

Saving the plot

If plot.file is given, each page of plots is saved as an RDS file named <plot.file>_<first pair>_to_<last pair>.RDS, and the result table as table_<plot.file>.RDS; both can be reloaded with readRDS(). They are written to plot.dir if given, otherwise to tempdir(). Other ggplot themes can be consulted at https://ggplot2.tidyverse.org/reference/ggtheme.html and https://yutannihilation.github.io/allYourFigureAreBelongToUs/ggthemes/.

Value

A dataframe with one row per population pair containing the two population labels, the observed difference in unbiased expected heterozygosity (pop1 - pop2), the lower and upper bounds of its bootstrap confidence interval, the significance label and the two-sided bootstrap p value (raw and Benjamini-Hochberg adjusted).

Author(s)

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

References

Nei, M. (1978). Estimation of average heterozygosity and genetic distance from a small number of individuals. Genetics, 89(3), 583-590.

Examples

if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
out <- gl.test.heterozygosity(platypus.gl, nreps=100, verbose=3, plot.out=TRUE)

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