Learn R Programming

bnpsd (version 1.1.1)

draw_p_subpops: Draw allele frequencies for independent subpopulations

Description

Allele frequencies \(p_i^{S_u}\) for independent subpopulations \(S_u\) at locus \(i\) are drawn from the Balding-Nichols distribution with ancestral allele frequency \(p_i^T\) and \(F_{ST}\) parameter \(f^T_{S_u}\) as $$p_i^{S_u} \sim \mbox{Beta}(\nu_u p_i^T, \nu_u (1-p_i^T)),$$ where \(\nu_u = 1/f^T_{S_u} - 1\). Below \(m\) is the number of loci and \(k\) is the number of subpopulations.

Usage

draw_p_subpops(p_anc, inbr_subpops, m_loci = NA, k_subpops = NA)

Arguments

p_anc

The length-\(m\) vector of ancestral allele frequencies per locus.

inbr_subpops

The length-\(k\) vector of subpopulation \(F_{ST}\) values.

m_loci

Optional. The desired number of loci \(m\), to be used if p_anc is a scalar. Stops if both length(p_anc) > 1 and m_loci are set and they disagree.

k_subpops

Optional. The desired number of subpopulations \(k\), to be used if inbr_subpops is a scalar. Stops if both length(inbr_subpops) > 1 and k_subpops are set and they disagree.

Value

The \(m \times k\) matrix of independent subpopulation allele frequencies

Examples

Run this code
# NOT RUN {
# 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 )

# }

Run the code above in your browser using DataLab