DeferredMatrix: The DeferredMatrix class

Description Usage Arguments Value Methods for DeferredMatrixSeed objects Methods for DeferredMatrix objects Author(s) See Also Examples

View source: R/DeferredMatrix.R

Description

Definitions of the DeferredMatrixSeed and DeferredMatrix classes and their associated methods. These classes are designed to support deferred centering and scaling of the columns prior to a principal components analysis.

Usage

1
2
3

Arguments

x

A matrix-like object.

This can alternatively be a DeferredMatrixSeed, in which case any values of center and scale are ignored.

center

A numeric vector of length equal to ncol(x), where each element is to be subtracted from the corresponding column of x. A NULL value indicates that no subtraction is to be performed.

scale

A numeric vector of length equal to ncol(x), where each element is to divide from the corresponding column of x (after subtraction). A NULL value indicates that no division is to be performed.

Value

The DeferredMatrixSeed constructor will return a DeferredMatrixSeed object.

The DeferredMatrix constructor will return a DeferredMatrix object equivalent to t((t(x) - center)/scale).

Methods for DeferredMatrixSeed objects

DeferredMatrixSeed objects are implemented as DelayedMatrix backends. They support standard operations like dim, dimnames and extract_array.

Passing a DeferredMatrixSeed object to the DelayedArray constructor will create a DeferredMatrix object.

It is possible for x to contain a DeferredMatrix, thus nesting one DeferredMatrix inside another. This can occasionally be useful in combination with transposition to achieve centering/scaling in both dimensions.

Methods for DeferredMatrix objects

DeferredMatrix objects are derived from DelayedMatrix objects and support all of valid operations on the latter. Several functions are specialized for greater efficiency when operating on DeferredMatrix instances, including:

All other operations applied to a DeferredMatrix will use the underlying DelayedArray machinery. Unary or binary operations will generally create a new DelayedMatrix instance containing a DeferredMatrixSeed.

Tranposition can effectively be used to allow centering/scaling on the rows if the input x is transposed.

Author(s)

Aaron Lun

See Also

?"BiocSingular-options" for comments about numerical precision with deferred centering and scaling.

Examples

1
2
3
4
5
6
7
8
library(Matrix)
y <- DeferredMatrix(rsparsematrix(10, 20, 0.1), 
    center=rnorm(20), scale=1+runif(20))
y

crossprod(y)
tcrossprod(y)
y %*% rnorm(20)

BiocSingular documentation built on Nov. 8, 2020, 10:59 p.m.