rarefy_cols: Transform a counts matrix.

rarefy_colsR Documentation

Transform a counts matrix.

Description

Rarefaction subset counts so that all samples have the same number of observations. Rescaling rows or cols scales the matrix values so that row sums or column sums equal 1.

Usage

rarefy_cols(mtx, depth = 0.1, n = NULL, seed = 0)

rescale_cols(mtx)

rescale_rows(mtx)

Arguments

mtx

A matrix-like object.

depth

How many observations to keep per sample. When ⁠0 < depth < 1⁠, it is taken as the minimum percentage of the dataset's observations to keep. Ignored when n is specified. Default: 0.1

n

The number of samples to keep. When ⁠0 < n < 1⁠, it is taken as the percentage of samples to keep. If negative, that number or percentage of samples is dropped. If 0, all samples are kept. If NULL, depth is used instead. Default: NULL

seed

An integer to use for seeding the random number generator. If you need to create different random rarefactions of the same matrix, set this seed value to a different number each time.

Value

The rarefied or rescaled matrix.

See Also

Other rarefaction: rare_corrplot(), rare_multiplot(), rare_stacked(), rarefy(), sample_sums()

Other transformations: mutate(), rarefy(), slice(), subset(), with()

Examples

    library(rbiom)
    
    # rarefy_cols --------------------------------------
    biom <- hmp50$clone()
    sample_sums(biom) %>% head(10)

    biom$counts %<>% rarefy_cols(depth=1000)
    sample_sums(biom) %>% head(10)
    
    
    # rescaling ----------------------------------------
    mtx <- matrix(sample(1:20), nrow=4)
    mtx
    
    rowSums(mtx)
    rowSums(rescale_rows(mtx))
    
    colSums(mtx)
    colSums(rescale_cols(mtx))


cmmr/rbiom documentation built on April 28, 2024, 6:38 a.m.