Description Usage Arguments Value See Also Examples
View source: R/draw_p_subpops_tree.R
The allele frequency matrix P
for m_loci
loci (rows) and k_subpops
subpopulations (columns) are drawn from the Balding-Nichols distribution.
If the allele frequency in the parent node is p
and the FST parameter of the child node from the parent node is F
, then the allele frequency in the child node is drawn from
rbeta( 1, nu * p, nu * ( 1 - p ) )
,
where nu <- 1 / F - 1
.
This function iterates drawing allele frequencies through the tree structure, therefore allowing covariance between subpopulations that share branches.
1 | draw_p_subpops_tree(p_anc, tree_subpops, m_loci = NA, nodes = FALSE)
|
p_anc |
The scalar or length- |
tree_subpops |
The coancestry tree relating the |
m_loci |
If |
nodes |
If |
The m_loci
-by-k_subpops
matrix of independent subpopulation allele frequencies.
If nodes = FALSE
, columns include only tip subpopulations.
If nodes = TRUE
, internal node subpopulations are also included (in this case the input p_anc
is returned in the column corresponding to the root node).
In all cases subpopulations are ordered as indexes in the tree, which normally implies the tip nodes are listed first, followed by the internal nodes (as in tree_subpops$edge
matrix, see ape::read.tree()
for details).
The tree_subpops
tip and node names are copied to the column names of this output matrix (individual names may be blank if missing in tree (such as for internal nodes); column names are NULL
if all tree_subpops
tip labels were blank, regardless of internal node labels).
If p_anc
is length-m_loci
with names, these names are copied to the row names of this output matrix.
draw_p_subpops()
for version for independent subpopulations.
For "phylo" tree class, see ape::read.tree()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # for simulating a tree with `rtree`
library(ape)
# a typical, non-trivial example
# number of tip subpopulations
k_subpops <- 3
# number of loci
m_loci <- 10
# random vector of ancestral allele frequencies
p_anc <- draw_p_anc(m_loci)
# simulate tree
tree_subpops <- rtree( k_subpops )
# matrix of intermediate subpop allele freqs
p_subpops <- draw_p_subpops_tree(p_anc, tree_subpops)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.