Learn R Programming

bnpsd (version 1.0.4)

rgeno: Draw genotypes from the admixture model

Description

Given the Individual-specific Allele Frequency (IAF) \(\pi_{ij}\) for locus \(i\) and individual \(j\), genotypes are drawn binomially: $$x_{ij}|\pi_{ij} \sim \mbox{Binomial}(2, \pi_{ij}).$$ Below \(m\) is the number of loci, \(n\) the number of individuals, and \(k\) the number of intermediate subpopulations. If an admixture proportion matrix \(Q\) is provided as the second argument, the first argument \(P\) is treated as the intermediate subpopulation allele frequency matrix and the IAF matrix is given by $$P Q^T.$$ If \(Q\) is missing, then \(P\) is treated as the IAF matrix.

Usage

rgeno(P, Q = NULL, lowMem = FALSE)

Arguments

P

The \(m \times n\) IAF matrix (if \(Q\) is missing) or the \(m \times k\) intermediate subpopulation allele frequency matrix (if \(Q\) is present)

Q

The optional \(n \times k\) admixture proportion matrix

lowMem

If TRUE, the low-memory algorithm is used (Q must be present)

Value

The \(m \times n\) genotype matrix

Details

To reduce memory, set lowMem=TRUE to draw genotypes one locus at the time from \(P\) and \(Q\) (both must be present). This low-memory algorithm prevents the construction of the entire IAF matrix, but is considerably slower than the standard algorithm.

Examples

Run this code
# NOT RUN {
# dimensions
m <- 10 # number of loci
n <- 5 # number of individuals
k <- 2 # number of intermediate subpops

# define population structure
F <- c(0.1, 0.3) # FST values for k=2 subpops
sigma <- 1 # dispersion parameter of intermediate subpops
Q <- q1d(n, k, sigma) # non-trivial admixture proportions

# draw alelle frequencies
pAnc <- rpanc(m) # random vector of ancestral allele frequencies
B <- rpint(pAnc, F) # matrix of intermediate subpop allele freqs
P <- rpiaf(B,Q) # matrix of individual-specific allele frequencies

# draw genotypes from intermediate subpops (one individual each)
Xb <- rgeno(B)
# and genotypes for admixed individuals
Xp <- rgeno(P)

# }

Run the code above in your browser using DataLab