Learn R Programming

bnpsd (version 1.0.4)

rbnpsd: Simulate random allele frequencies and genotypes from the BN-PSD admixture model

Description

This function returns simulated ancestral, intermediate, and individual-specific allele frequencies and genotypes given the admixture structure, as determined by the admixture proportions and the vector of intermediate subpopulation \(F_{ST}\) values. The function is a wrapper around rpanc, rpint, rpiaf, and rgeno. Below \(m\) is the number of loci, \(n\) is the number of individuals, and \(k\) is the number of intermediate subpopulations.

Usage

rbnpsd(Q, F, m, wantX = TRUE, wantP = TRUE, wantB = TRUE,
  wantPa = TRUE, lowMem = FALSE, verbose = FALSE, noFixed = FALSE)

Arguments

Q

The \(n \times k\) matrix of admixture proportions

F

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

m

The number of loci to draw

wantX

If TRUE (default), calculates and includes the random genotype matrix in the return list

wantP

If TRUE (default), includes the random IAF matrix in the return list

wantB

If TRUE (default), includes the random intermediate pop allele freq matrix in the return list

wantPa

If TRUE (default), includes the random ancestral allele freq matrix in the return list

lowMem

If TRUE, uses a low-memory algorithm to raw genotypes without storing or returning the corresponding IAF matrix.

verbose

If TRUE, prints messages for every stage in the algorithm

noFixed

If TRUE, returned matrix will not include any fixed loci (loci that happened to be fixed are drawn again, starting from the ancestral allele frequency, and checked iteratively until no fixed loci remain, so that the final number of loci is exactly \(m\) as specified).

Value

A named list that includes the following random matrices: X=genotypes, P=IAFs, B=intermediate pop allele freqs, Pa=vector of ancestral allele frequencies. Items may be omitted depending on the values of wantX, wantP, wantB, or wantPa above.

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 subpopulations
sigma <- 1 # dispersion parameter of intermediate subpops
Q <- q1d(n, k, sigma) # admixture proportions from 1D geography

# draw all random allele freqs and genotypes
out <- rbnpsd(Q, F, m)
X <- out$X # genotypes
P <- out$P # IAFs
B <- out$B # Intermediate AFs
pAnc <- out$Pa # Ancestral AFs

# }

Run the code above in your browser using DataLab