sScale: Convenience Functions for Assay Data Element Sweep Operations

View source: R/utils.R

sThreshR Documentation

Convenience Functions for Assay Data Element Sweep Operations

Description

Convenience functions for matrix thresholding, centering, and scaling based upon margin statistics.

Usage

# Loop over features
fThresh(x, STATS)
fCenter(x, STATS)
fScale(x, STATS)

## Round results to integers
fIntThresh(x, STATS)
fIntCenter(x, STATS)
fIntScale(x, STATS)

## Comparisons
fAbove(x, STATS)
fBelow(x, STATS)
fAtLeast(x, STATS)
fAtMost(x, STATS)


# Loop over samples
sThresh(x, STATS)
sCenter(x, STATS)
sScale(x, STATS)

# Round results to integers
sIntThresh(x, STATS)
sIntCenter(x, STATS)
sIntScale(x, STATS)

## Comparisons
sAbove(x, STATS)
sBelow(x, STATS)
sAtLeast(x, STATS)
sAtMost(x, STATS)

Arguments

x

a numeric array.

STATS

the summary statistic for thresholding, centering, or scaling.

Details

These functions are convenience wrappers for the following code:

fThresh:

sweep(x, 1L, STATS, FUN = "pmax")

fCenter:

sweep(x, 1L, STATS, FUN = "-")

fScale:

sweep(x, 1L, STATS, FUN = "/")

fIntThresh:

round(sweep(x, 1L, STATS, FUN = "pmax"))

fIntCenter:

round(sweep(x, 1L, STATS, FUN = "-"))

fIntScale:

round(sweep(x, 1L, STATS, FUN = "/"))

fAbove:

sweep(x, 1L, STATS, FUN = ">")

fBelow:

sweep(x, 1L, STATS, FUN = "<")

fAtLeast:

sweep(x, 1L, STATS, FUN = ">=")

fAtMost:

sweep(x, 1L, STATS, FUN = "<=")

sThresh:

sweep(x, 2L, STATS, FUN = "pmax")

sCenter:

sweep(x, 2L, STATS, FUN = "-")

sScale:

sweep(x, 2L, STATS, FUN = "/")

sIntThresh:

round(sweep(x, 2L, STATS, FUN = "pmax"))

sIntCenter:

round(sweep(x, 2L, STATS, FUN = "-"))

sIntScale:

round(sweep(x, 2L, STATS, FUN = "/"))

sAbove:

sweep(x, 2L, STATS, FUN = ">")

sBelow:

sweep(x, 2L, STATS, FUN = "<")

sAtLeast:

sweep(x, 2L, STATS, FUN = ">=")

sAtMost:

sweep(x, 2L, STATS, FUN = "<=")

Value

An array with the same shape as x that has been modified by thresholding, centering, or scaling.

Author(s)

Patrick Aboyoun

See Also

sweep

Examples

# Find reasonable column minimums
thresh <- apply(stack.x, 2L, quantile, 0.05)

# Threshold column values
identical(sThresh(stack.x, thresh),
          sweep(stack.x, 2L, thresh, FUN = "pmax"))

# Substract column values
identical(sCenter(stack.x, thresh),
          sweep(stack.x, 2L, thresh))

# Scale to common mean
identical(sScale(stack.x, colMeans(stack.x) / mean(colMeans(stack.x))),
          sweep(stack.x, 2L, colMeans(stack.x) / mean(colMeans(stack.x)),
                FUN = "/"))

# Scale to common mean, rounded to the nearest integer
sIntScale(stack.x, colMeans(stack.x) / mean(colMeans(stack.x)))

Nanostring-Biostats/NanoStringNCTools documentation built on April 19, 2024, 8:21 p.m.