safeColScale: Safe Centering and Scaling of Columns

View source: R/safeColScale.R

safeColScaleR Documentation

Safe Centering and Scaling of Columns

Description

safeColScale is a safe utility for centering and scaling an input matrix X. It is intended to avoid the drawback of using scale on data with constant variance by inducing adding a small perturbation to truncate the values in such columns. It also takes the opportunity to be faster than scale through relying on matrixStats or DelayedMatrixStats, depending on the type of matrix being processed, for a key internal computation.

Usage

safeColScale(
  X,
  center = TRUE,
  scale = TRUE,
  tol = .Machine$double.eps,
  eps = 0.01,
  scaled_matrix = FALSE
)

Arguments

X

An input matrix to be centered and/or scaled. If X is not of class matrix or DelayedMatrix, then it must be coercible to a matrix.

center

A logical indicating whether to re-center the columns of the input X.

scale

A logical indicating whether to re-scale the columns of the input X.

tol

A tolerance level for the lowest column variance (or standard deviation) value to be tolerated when scaling is desired. The default is set to double.eps of machine precision .Machine.

eps

The desired lower bound of the estimated variance for a given column. When the lowest estimate falls below tol, it is truncated to the value specified in this argument. The default is 0.01.

scaled_matrix

A logical indicating whether to output a ScaledMatrix object. The centering and scaling procedure is delayed until later, permitting more efficient matrix multiplication and row or column sums downstream. However, this comes at the at the cost of numerical precision. Defaults to FALSE.

Value

A centered and/or scaled version of the input data.


PhilBoileau/scPCA documentation built on Feb. 6, 2024, 3:33 p.m.