window_general {wingen} | R Documentation |
General function for making moving window maps
Description
Generate a continuous raster map using moving windows. While window_gd is
built specifically for making moving window maps of genetic diversity from vcfs,
window_general
can be used to make moving window maps from different data inputs.
See details for how to format data inputs for different statistics.
Usage
window_general(
x,
coords,
lyr,
stat,
wdim = 3,
fact = 0,
rarify = FALSE,
rarify_n = NULL,
rarify_nit = 5,
min_n = 2,
fun = mean,
L = "nvariants",
rarify_alleles = TRUE,
sig = 0.05,
crop_edges = FALSE,
...
)
Arguments
x |
data to be summarized by the moving window (note: order matters! |
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) |
stat |
moving window statistic to calculate (can either be |
wdim |
dimensions (height x width) of window; if only one value is provided, a square window is created (defaults to 3 x 3 window) |
fact |
aggregation factor to apply to |
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 |
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 |
L |
for calculating |
rarify_alleles |
for calculating |
sig |
for calculating |
crop_edges |
whether to remove cells on the edge of the raster where the window is incomplete (defaults to FALSE) |
... |
if a function is provided for |
Details
To calculate genetic diversity statistics with the built in wingen functions, data must be formatted as such:
for
"pi"
or"biallelic_richness"
,x
must be a dosage matrix with values of 0, 1, or 2for
"Ho"
,x
must be a heterozygosity matrix where values of 0 = homozygosity and values of 1 = heterozygosityfor
"allelic_richness"
or"hwe
,x
must be agenind
type objectfor
"basic_stats"
,x
must be ahierfstat
type object
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