Learn R Programming

rbiom (version 3.1.0)

biom_rescale: Rescale Counts to a Specific Range

Description

This function performs a min-max scaling on each sample independently.

It is useful for normalization techniques that require data to be within a specific bounded range, or for visualization purposes where maintaining the relative distances between values is important but the absolute magnitude needs adjustment.

Usage

biom_rescale(biom, range = c(0, 1), clone = TRUE)

Value

An rbiom object.

Arguments

biom

An rbiom object, or any value accepted by as_rbiom().

range

Numeric vector of length 2. Target min and max. Default: c(0, 1).

clone

Create a copy of biom before modifying. If FALSE, biom is modified in place as a side-effect. See speed ups for use cases. Default: TRUE

Mathematical Transformation

The rescaling is performed in two steps:

  1. Normalize: Divide values by the maximum value in that sample, scaling them to a [0, 1] range relative to the sample's peak.

  2. Scale and Shift: Apply the target range using the formula: $$x_{new} = x_{norm} \times (max - min) + min$$

Details

Linearly rescale each sample's values to lie between a specified minimum and maximum.

See Also

Other transformations: biom_inflate(), biom_relativize(), modify_metadata, rarefy(), slice_metadata, subset(), with()

Examples

Run this code
    library(rbiom)
    
    biom <- hmp50[1:5]
    
    # Original range
    range(as.matrix(biom))
    
    # Rescaled to 0-1
    biom_01 <- biom_rescale(biom)
    range(as.matrix(biom_01))
    
    # Rescaled to 0-100 (Percentages)
    biom_100 <- biom_rescale(biom, range = c(0, 100))
    range(as.matrix(biom_100))
    

Run the code above in your browser using DataLab