draw_p_subpops_tree: Draw allele frequencies for subpopulations related by a tree

Description Usage Arguments Value See Also Examples

View source: R/draw_p_subpops_tree.R

Description

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.

Usage

1
draw_p_subpops_tree(p_anc, tree_subpops, m_loci = NA, nodes = FALSE)

Arguments

p_anc

The scalar or length-m_loci vector of ancestral allele frequencies per locus.

tree_subpops

The coancestry tree relating the k_subpops subpopulations. Must be a phylo object from the ape package (see ape::read.tree()). The edge lengths of this tree must be the FST parameters relating parent and child subpopulations.

m_loci

If p_anc is scalar, optionally provide the desired number of loci (lest only one locus be simulated). Stops if both length(p_anc) > 1 and m_loci is not NA and they disagree.

nodes

If FALSE (default), returns allele frequencies of "tip" subpopulations only; otherwise returns all allele frequencies, including internal nodes.

Value

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.

See Also

draw_p_subpops() for version for independent subpopulations.

For "phylo" tree class, see ape::read.tree()

Examples

 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)

bnpsd documentation built on Aug. 25, 2021, 5:07 p.m.