DeferredMatrix {BiocSingular} | R Documentation

## The DeferredMatrix class

### 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

    DeferredMatrixSeed(x, center=NULL, scale=NULL)

    DeferredMatrix(x, center=NULL, scale=NULL)

### 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:

- Subsetting, transposition and replacement of row/column names. These will return a new DeferredMatrix rather than a DelayedMatrix.

- Matrix multiplication via `%*%`, `crossprod` and `tcrossprod`. These functions will return a DelayedMatrix. Also see `?"BiocSingular-options"`.

- Calculation of row and column sums and means by `colSums`, `rowSums`, etc.

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

    library(Matrix)
    y <- DeferredMatrix(rsparsematrix(10, 20, 0.1),
        center=rnorm(20), scale=1+runif(20))
    y

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

[Package BiocSingular version 1.0.0 Index]