| bootstrap_pop_sfs | R Documentation |
Compute bootstrap replicates of the site frequency spectra of
pop_sfs(), pairwise_pop_sfs() and nwise_pop_sfs(), by resampling
blocks of loci with replacement. Replicates are used to estimate the
uncertainty of statistics computed from the spectra, or of the parameters
of demographic models fitted with dadi, moments or fastsimcoal2
(see write_sfs() to write the replicates in their formats).
bootstrap_pop_sfs(.x, ...)
## S3 method for class 'gen_tbl'
bootstrap_pop_sfs(
.x,
n_bootstrap = 100,
block_size,
size_unit = c("snp", "cM", "bp"),
n_proj = NULL,
folded = TRUE,
ancestral = NULL,
type = c("tidy", "array"),
n_cores = bigstatsr::nb_cores(),
...
)
bootstrap_pairwise_pop_sfs(.x, ...)
## S3 method for class 'gen_tbl'
bootstrap_pairwise_pop_sfs(
.x,
n_bootstrap = 100,
block_size,
size_unit = c("snp", "cM", "bp"),
n_proj = NULL,
folded = TRUE,
ancestral = NULL,
type = c("tidy", "array"),
fastest = c("last", "first"),
n_cores = bigstatsr::nb_cores(),
...
)
bootstrap_nwise_pop_sfs(.x, ...)
## S3 method for class 'gen_tbl'
bootstrap_nwise_pop_sfs(
.x,
n_bootstrap = 100,
block_size,
size_unit = c("snp", "cM", "bp"),
n_proj = NULL,
folded = TRUE,
ancestral = NULL,
type = c("tidy", "array"),
fastest = c("last", "first"),
max_cells = 1e+07,
n_cores = bigstatsr::nb_cores(),
...
)
.x |
a |
... |
other arguments passed to specific methods, currently unused. |
n_bootstrap |
the number of bootstrap replicates. |
block_size |
the size of the blocks of loci that are resampled. |
size_unit |
the unit of |
n_proj |
the number of allele copies to project each population to:
either a single value used for all populations, a vector with one value
per population (in the order of the groups), or a vector named with the
group labels. If |
folded |
boolean, whether to fold the spectrum (the default, as the
ancestral allele is not usually known). If |
ancestral |
the ancestral allele of each locus, used to polarise
unfolded spectra: either the name of a column of the loci table (see
|
type |
the type of object to return, either "tidy" (the default) or "array". |
n_cores |
number of cores to be used, it defaults to
|
fastest |
the order of the cells of each spectrum in the tidy
output: "last" (the default) keeps the order of the populations, so
that the rows are sorted by the number of allele copies in the first
population, then in the second (the number of copies in the second
population changes fastest, as in the files written by |
max_cells |
the maximum number of cells of all the replicates (the
number of cells of the joint spectrum times |
The loci are divided into non-overlapping blocks that never span more
than one chromosome, defined as in the jackknife_* functions (e.g.
jackknife_pop_tajimas_d()): blocks of block_size SNPs, base pairs or
centiMorgans (the latter requires the genetic_dist column of the loci
table). Blocks should be larger than the extent of linkage
disequilibrium, so that they are approximately independent. Each
replicate draws, with replacement, as many blocks as there are (as the
bootstrap of dadi, Misc.bootstraps_from_dd_chunks()). With
block_size = 1 and size_unit = "snp", single SNPs are resampled (as the
--resample-vcf option of easySFS), which ignores linkage.
A spectrum is a sum over loci, so the spectrum of a replicate is the sum
of the spectra of the blocks it drew (counting each block as many times as
it was drawn). The genotypes are therefore read only once, to compute the
spectrum of each block. Missing data are dealt with by projection, as in
pop_sfs(), with the same projections (n_proj) for all replicates: if
n_proj is NULL, they are chosen from all the loci with
pop_sfs_preview(). The blocks are drawn with the random number
generator of R, so use set.seed() to make the replicates reproducible.
If type = "tidy", a tibble with the columns of the tidy output
of pop_sfs(), pairwise_pop_sfs() or nwise_pop_sfs(), and a column
replicate (after the group columns) with the number of the replicate.
If type = "array", a list with one element per replicate, each of
which is what pop_sfs(), pairwise_pop_sfs() or nwise_pop_sfs()
return with type = "array" (lists of sfs objects, or an sfs object).
In both cases, the attribute bootstrap_blocks is a matrix with the
number of times each block (columns, numbered in the order in which they
appear in the loci table) was drawn in each replicate (rows), and the
tibble also has the attributes n_proj and folded.
pop_sfs(), write_sfs(), jackknife_stats_generic()
example_gt <- load_example_gt("grouped_gen_tbl")
set.seed(1)
# resample blocks of 2 SNPs
boot <- example_gt %>%
bootstrap_pop_sfs(n_bootstrap = 10, block_size = 2, n_proj = 2)
boot
# the 95% interval of the number of sites in each cell
boot %>%
dplyr::group_by(group, allele_count) %>%
dplyr::summarise(
lower = stats::quantile(n_sites, 0.025),
upper = stats::quantile(n_sites, 0.975)
)
# the joint spectra of each pair, as arrays
boot_2d <- example_gt %>%
bootstrap_pairwise_pop_sfs(
n_bootstrap = 5, block_size = 2, n_proj = 2,
type = "array"
)
boot_2d[[1]]$pop1.pop2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.