allele_freqs {simtrait} | R Documentation |
Compute locus allele frequencies
Description
On a regular matrix, this is essentially a wrapper for colMeans()
or rowMeans()
depending on loci_on_cols
.
On a BEDMatrix object, the locus allele frequencies are computed keeping memory usage low.
Usage
allele_freqs(X, loci_on_cols = FALSE, fold = FALSE, m_chunk_max = 1000)
Arguments
X |
The genotype matrix (regular R matrix or BEDMatrix object). Missing values are ignored in averages. |
loci_on_cols |
If |
fold |
If |
m_chunk_max |
BEDMatrix-specific, sets the maximum number of loci to process at the time. If memory usage is excessive, set to a lower value than default (expected only for extremely large numbers of individuals). |
Value
The vector of allele frequencies, one per locus. Names are set to the locus names, if present.
Examples
# Construct toy data
X <- matrix(
c(0, 1, 2,
1, 0, 1,
1, NA, 2),
nrow = 3,
byrow = TRUE
)
# row means
allele_freqs(X)
c(1/2, 1/3, 3/4)
# row means, in minor allele frequencies
allele_freqs(X, fold = TRUE)
c(1/2, 1/3, 1/4)
# col means
allele_freqs(X, loci_on_cols = TRUE)
c(1/3, 1/4, 5/6)