Generate a continuous raster map of genetic diversity using circle moving windows
circle_gd(
gen,
coords,
lyr,
maxdist,
distmat = NULL,
stat = "pi",
fact = 0,
rarify = FALSE,
rarify_n = 2,
rarify_nit = 5,
min_n = 2,
fun = mean,
L = "nvariants",
rarify_alleles = TRUE,
sig = 0.05
)SpatRaster that includes a raster layer of genetic diversity and a raster layer of the number of samples within the window for each cell
genetic data either as an object of type vcf or a path to a vcf file (note: order matters! The coordinate and genetic data should be in the same order; there are currently no checks for this)
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)
SpatRaster or RasterLayer to slide the window across (see Details for important information about projections)
maximum geographic distance used to define neighborhood; any samples further than this distance will not be included (this can be thought of as the neighborhood radius)
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).
distance matrix output from get_geodist (optional; can be used to save time on distance calculations)
genetic diversity statistic(s) to calculate (see Details, defaults to "pi"). Can be a single statistic or a vector of statistics
aggregation factor to apply to lyr (defaults to 0; note: increasing this value reduces computational time)
if rarify = TRUE, rarefaction is performed (defaults to FALSE)
if rarify = TRUE, number of points to use for rarefaction (defaults to min_n)
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.
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)
function to use to summarize rarefaction results (defaults to mean, must take na.rm = TRUE as an argument)
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)
for calculating "biallelic_richness", whether to perform rarefaction of allele counts as in allelic.richness (defaults to TRUE)
for calculating "hwe", significance threshold (i.e., alpha level) to use for hardy-weinberg equilibrium tests (defaults to 0.05)
Coordinates and rasters should be in a Euclidean coordinate system (i.e., UTM coordinates) such that raster cell width and height are equal distances. As such, longitude-latitude systems should be transformed before using dist_gd. Transformation can be performed using st_set_crs for coordinates or project for rasters (see vignette for more details).
# \donttest{
load_mini_ex()
cpi <- circle_gd(mini_vcf, mini_coords, mini_lyr, fact = 2, maxdist = 5)
# }
Run the code above in your browser using DataLab