resist_general {wingen}R Documentation

General function for making resistance-based maps

Description

Generate a continuous raster map using resistance distances. While resist_gd is built specifically for making maps of genetic diversity from vcfs,resist_general can be used to make maps from different data inputs. Unlike resist_gd, resist_general will not convert your data into the correct format for calculations of different diversity metrics. See details for how to format data inputs for different statistics.

Usage

resist_general(
  x,
  coords,
  lyr,
  maxdist,
  distmat = NULL,
  stat,
  fact = 0,
  rarify = FALSE,
  rarify_n = 2,
  rarify_nit = 5,
  min_n = 2,
  fun = mean,
  L = "nvariants",
  rarify_alleles = TRUE,
  sig = 0.05,
  transitionFunction = mean,
  directions = 8,
  geoCorrection = TRUE,
  ...
)

Arguments

x

data to be summarized by the moving window (note: order matters! coords should be in the same order, there are currently no checks for this). The class of x required depends on the statistic being calculated (see the stat argument and the function description for more details)

coords

coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections)

lyr

SpatRaster or RasterLayer to slide the window across (see Details for important information about projections)

maxdist

maximum cost distance used to define neighborhood; any samples further than this cost distance will not be included (this can be thought of as the neighborhood radius, but in terms of cost distance). Can either be (1) a single numeric value or (2) a SpatRaster where each pixel is the maximum distance to be used for that cell on the landscape (must be the same spatial scale as lyr).

distmat

distance matrix output from get_resdist (optional; can be used to save time on distance calculations)

stat

moving window statistic to calculate (see details). stat can generally be set to any function that will take xas input and return a single numeric value (for example, x can be a vector and stat can be set equal to a summary statistic like mean, sum, or sd)

fact

aggregation factor to apply to lyr (defaults to 0; note: increasing this value reduces computational time)

rarify

if rarify = TRUE, rarefaction is performed (defaults to FALSE)

rarify_n

if rarify = TRUE, number of points to use for rarefaction (defaults to min_n)

rarify_nit

if rarify = TRUE, number of iterations to use for rarefaction (defaults to 5). Can also be set to "all" to use all possible combinations of samples of size rarify_n within the window.

min_n

minimum number of samples to use in calculations (any focal cell with a window containing less than this number of samples will be assigned a value of NA; defaults to 2)

fun

function to use to summarize rarefaction results (defaults to mean, must take na.rm = TRUE as an argument)

L

for calculating "pi", L argument in pi.dosage function. Return the average nucleotide diversity per nucleotide given the length L of the sequence. The wingen default is L = "nvariants", which sets L to the number of variants in the VCF. If L = NULL, returns the sum over SNPs of nucleotide diversity (note: L = NULL is the pi.dosage default which wingen does not use)

rarify_alleles

for calculating "biallelic_richness", whether to perform rarefaction of allele counts as in allelic.richness (defaults to TRUE)

sig

for calculating "hwe", significance threshold (i.e., alpha level) to use for hardy-weinberg equilibrium tests (defaults to 0.05)

transitionFunction

function to calculate transition values from grid values (defaults to mean)

directions

directions in which cells are connected (4, 8, 16, or other), see adjacent (defaults to 8)

geoCorrection

whether to apply correction to account for local distances (defaults to TRUE). Geographic correction is necessary for all objects of the class Transition that are either: (1) based on a grid in a geographic (lonlat) projection and covering a large area; (2) made with directions > 4 (see geoCorrection for more details).

...

if a function is provided for stat, additional arguments to pass to the stat function (e.g. if stat = mean, users may want to set na.rm = TRUE)

Details

To calculate genetic diversity statistics with the built in wingen functions, data must be formatted as such:

Otherwise, stat can be any function that takes a matrix or data frame and outputs a single numeric value (e.g., a function that produces a custom diversity index); however, this should be attempted with caution since this functionality has not have been tested extensively and may produce errors.

Value

SpatRaster that includes a raster layer of genetic diversity and a raster layer of the number of samples within the window for each cell


[Package wingen version 2.1.2 Index]