Draw allele frequencies for independent subpopulations
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.
draw_p_subpops(p_anc, inbr_subpops, m_loci = NA, k_subpops = NA)
p_anc |
The scalar or length- |
inbr_subpops |
The length- |
m_loci |
If |
k_subpops |
If |
The m_loci
-by-k_subpops
matrix of independent subpopulation allele frequencies
# 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 )
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.