Description Usage Arguments Value See Also Examples
View source: R/draw_p_subpops.R
The allele frequency matrix P
for m_loci
loci (rows) and k_subpops
independent subpopulations (columns) are drawn from the Balding-Nichols distribution with ancestral allele frequencies p_anc
and FST parameters inbr_subpops
equivalent to
P[ i, j ] <- rbeta( 1, nu_j * p_anc[i], nu_j * ( 1 - p_anc[i] ) )
,
where nu_j <- 1 / inbr_subpops[j] - 1
.
The actual function is more efficient than the above code.
1 | draw_p_subpops(p_anc, inbr_subpops, m_loci = NA, k_subpops = NA)
|
p_anc |
The scalar or length- |
inbr_subpops |
The scalar or length- |
m_loci |
If |
k_subpops |
If |
The m_loci
-by-k_subpops
matrix of independent subpopulation allele frequencies.
If p_anc
is length-m_loci
with names, these are copied to the row names of this output matrix.
If inbr_subpops
is length-k_subpops
with names, these are copied to the column names of this output matrix.
draw_p_subpops_tree()
for version for subpopulations related by a tree, which can therefore be non-independent.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # a typical, non-trivial example
# number of loci
m_loci <- 10
# random vector of ancestral allele frequencies
p_anc <- draw_p_anc(m_loci)
# FST values for two subpops
inbr_subpops <- c(0.1, 0.3)
# matrix of intermediate subpop allele freqs
p_subpops <- draw_p_subpops(p_anc, inbr_subpops)
# special case of scalar p_anc
p_subpops <- draw_p_subpops(p_anc = 0.5, inbr_subpops, m_loci = m_loci)
stopifnot ( nrow( p_subpops ) == m_loci )
# special case of scalar inbr_subpops
k_subpops <- 2
p_subpops <- draw_p_subpops(p_anc, inbr_subpops = 0.2, k_subpops = k_subpops)
stopifnot ( ncol( p_subpops ) == k_subpops )
# both main parameters scalars but return value still matrix
p_subpops <- draw_p_subpops(p_anc = 0.5, inbr_subpops = 0.2, m_loci = m_loci, k_subpops = k_subpops)
stopifnot ( nrow( p_subpops ) == m_loci )
stopifnot ( ncol( p_subpops ) == k_subpops )
# passing scalar parameters without setting dimensions separately results in a 1x1 matrix
p_subpops <- draw_p_subpops(p_anc = 0.5, inbr_subpops = 0.2)
stopifnot ( nrow( p_subpops ) == 1 )
stopifnot ( ncol( p_subpops ) == 1 )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.