bioconductor v3.9.0 DelayedMatrixStats

A port of the 'matrixStats' API for use with DelayedMatrix objects

Link to this section Summary

Functions

DelayedMatrixStats: Functions that apply to rows and columns of DelayedMatrix objects.

Checks if a value exists / does not exist in each row (column) of a matrix

Checks if there are any missing values in an object or not

Applies a row-by-row (column-by-column) averaging function to equally-sized subsets of matrix columns (rows)

Extracts one cell per row (column) from a matrix

Counts the number of occurrences of a specific value

Cumulative sums, products, minima and maxima for each row (column) in a matrix

Calculates difference for each row (column) in a matrix

Estimation of scale based on sequential-order differences

Estimates of the interquartile range for each row (column) in a matrix

Accurately computes the logarithm of the sum of exponentials across rows or columns

Standard deviation estimates for each row (column) in a matrix

Calculates the mean for each row (column) in a matrix

Calculates the median for each row (column) in a matrix

Gets an order statistic for each row (column) in a matrix

Calculates the product for each row (column) in a matrix

Estimates quantiles for each row (column) in a matrix

Gets the rank of each row (column) of a matrix

Calculates the sum for each row (column) in a matrix

Tabulates the values in a matrix by row (column)

Variance estimates for each row (column) in a matrix

Weighted Median Absolute Deviation (MAD)

Calculates the weighted means for each row (column) in a matrix

Calculates the weighted medians for each row (column) in a matrix

Weighted variance and weighted standard deviation

Coerce DelayedArray to its 'simple seed' form

Adapted from DelayedArray:::colblock_APPLY()

Get the class of the seed of a DelayedArray

subset_by_Nindex

Link to this section Functions

Link to this function

DelayedMatrixStats()

DelayedMatrixStats: Functions that apply to rows and columns of DelayedMatrix objects.

Description

DelayedMatrixStats is a port of the matrixStats API to work with DelayedMatrix objects from the DelayedArray package. High-performing functions operating on rows and columns of DelayedMatrix objects, e.g. colMedians() / rowMedians() , colRanks() / rowRanks() , and colSds() / rowSds() . Functions optimized per data type and for subsetted calculations such that both memory usage and processing time is minimized.

Checks if a value exists / does not exist in each row (column) of a matrix

Description

Checks if a value exists / does not exist in each row (column) of a matrix.

Usage

colAlls(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
colAnys(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
rowAlls(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
rowAnys(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
list(list("colAlls"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("colAnys"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowAlls"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowAnys"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
valueA value to search for.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

These functions takes either a matrix or a vector as input. If a vector, then argument dim. must be specified and fulfill prod(dim.) == . The result will be identical to the results obtained when passing matrix(x, nrow = dim.[1L], ncol = dim.[2L]) , but avoids having to temporarily create/allocate a matrix, if only such is needed only for these calculations.

Value

rowAlls() ( colAlls() ) returns an logical vector of length N (K). Analogously for rowAnys() ( rowAlls() ).

Seealso

rowCounts

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'SolidRleArraySeed' seed
dm_Rle <- RleArray(Rle(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L))),
dim = c(5, 3))

colAlls(dm_matrix, value = 1)
colAnys(dm_matrix, value = 2)
rowAlls(dm_Rle, value = 1)
rowAnys(dm_Rle, value = 2)

Checks if there are any missing values in an object or not

Description

Checks if there are any missing values in an object or not. list("Please use ", list("base::anyNA()"), " instead of ", list("anyMissing()"), ", ", list("colAnyNAs()"), " instead of ", list("colAnyMissings()"), ", and ", list("rowAnyNAs()"), " instead of ", list("rowAnyMissings()"), ".")

Usage

colAnyMissings(x, rows = NULL, cols = NULL, ...)
colAnyNAs(x, rows = NULL, cols = NULL, ...)
rowAnyMissings(x, rows = NULL, cols = NULL, ...)
rowAnyNAs(x, rows = NULL, cols = NULL, ...)
list(list("colAnyMissings"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  force_block_processing = FALSE, ...)
list(list("colAnyNAs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  force_block_processing = FALSE, ...)
list(list("rowAnyMissings"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  force_block_processing = FALSE, ...)
list(list("rowAnyNAs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementation of this method is optimized for both speed and memory. The method will return TRUE as soon as a missing value is detected.

Value

Returns TRUE if a missing value was detected, otherwise FALSE .

Seealso

Starting with R v3.1.0, there is anyNA() in the base , which provides the same functionality as anyMissing() .

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'HDF5ArraySeed' seed
# NOTE: Requires that the HDF5Array package is installed
library(HDF5Array)
dm_HDF5 <- writeHDF5Array(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

dm_matrix[dm_matrix > 3] <- NA
colAnyNAs(dm_matrix)
dm_HDF5[dm_HDF5 > 3] <- NA
rowAnyNAs(dm_HDF5)
Link to this function

colAvgsPerRowSet()

Applies a row-by-row (column-by-column) averaging function to equally-sized subsets of matrix columns (rows)

Description

Applies a row-by-row (column-by-column) averaging function to equally-sized subsets of matrix columns (rows). Each subset is averaged independently of the others.

Usage

colAvgsPerRowSet(X, W = NULL, cols = NULL, S, FUN = colMeans, ...,
  tFUN = FALSE)
rowAvgsPerColSet(X, W = NULL, rows = NULL, S, FUN = rowMeans, ...,
  tFUN = FALSE)
list(list("colAvgsPerRowSet"), list("DelayedMatrix"))(X, W = NULL, cols = NULL, S,
  FUN = colMeans, ..., force_block_processing = FALSE, tFUN = FALSE)
list(list("rowAvgsPerColSet"), list("DelayedMatrix"))(X, W = NULL, rows = NULL, S,
  FUN = rowMeans, ..., force_block_processing = FALSE, tFUN = FALSE)

Arguments

ArgumentDescription
XA NxM DelayedMatrix .
WAn optional numeric NxM matrix of weights.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
SAn integer KxJ matrix specifying the J subsets. Each column holds K column (row) indices for the corresponding subset.
FUNThe row-by-row (column-by-column) function used to average over each subset of X . This function must accept a numeric NxK (KxM) matrix and the logical argument na.rm (which is automatically set), and return a numeric vector of length N (M).
...Additional arguments passed to specific methods.
tFUNIf TRUE , the NxK (KxM) matrix passed to FUN() is transposed first.
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

If argument S is a single column vector with indices 1:N , then rowAvgsPerColSet(X, S = S, FUN = rowMeans) gives the same result as rowMeans(X) . Analogously, for colAvgsPerRowSet() .

Value

Returns a numeric JxN (MxJ) matrix , where row names equal rownames(X) ( colnames(S) ) and column names colnames(S) ( colnames(X) ).

Examples

# A DelayedMatrix with a 'DataFrame' seed
dm_DF <- DelayedArray(S4Vectors::DataFrame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))
colAvgsPerRowSet(dm_DF, S = matrix(1:2, ncol = 2))

rowAvgsPerColSet(dm_DF, S = matrix(1:2, ncol = 1))

Extracts one cell per row (column) from a matrix

Description

Extracts one cell per row (column) from a matrix. The implementation is optimized for memory and speed.

Usage

colCollapse(x, idxs, cols = NULL, dim. = dim(x), ...)
rowCollapse(x, idxs, rows = NULL, dim. = dim(x), ...)
list(list("colCollapse"), list("DelayedMatrix"))(x, idxs, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowCollapse"), list("DelayedMatrix"))(x, idxs, rows = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
idxsAn index vector of (maximum) length N (K) specifying the columns (rows) to be extracted.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a vector of length N (K).

Seealso

Matrix indexing to index elements in matrices and arrays, cf. [[](#[) ().

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'HDF5ArraySeed' seed
# NOTE: Requires that the HDF5Array package is installed
library(HDF5Array)
dm_HDF5 <- writeHDF5Array(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

# Extract the 4th row as a vector
# NOTE: An ordinary vector is returned regardless of the backend of
#       the DelayedMatrix object
colCollapse(dm_matrix, 4)
colCollapse(dm_HDF5, 4)

# Extract the 2nd column as a vector
# NOTE: An ordinary vector is returned regardless of the backend of
#       the DelayedMatrix object
rowCollapse(dm_matrix, 2)
rowCollapse(dm_HDF5, 2)

Counts the number of occurrences of a specific value

Description

The row- and column-wise functions take either a matrix or a vector as input. If a vector, then argument dim. must be specified and fulfill prod(dim.) == length(x) . The result will be identical to the results obtained when passing matrix(x, nrow = dim.[1L], ncol = dim.[2L]) , but avoids having to temporarily create/allocate a matrix, if only such is needed only for these calculations.

Usage

colCounts(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
rowCounts(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
  dim. = dim(x), ...)
list(list("colCounts"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowCounts"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  value = TRUE, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
valueA value to search for.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

rowCounts() ( colCounts() ) returns an integer vector of length N (K). count() returns a scalar of type integer if the count is less than 2^31-1 (= .Machine$integer.max ) otherwise a scalar of type double .

Seealso

rowAlls

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'DataFrame' seed
dm_DF <- DelayedArray(S4Vectors::DataFrame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))

colCounts(dm_matrix, value = 1)
# Only count those in the first 4 rows
colCounts(dm_matrix, rows = 1:4, value = 1)

rowCounts(dm_DF, value = 5)
# Only count those in the odd-numbered rows of the 2nd column
rowCounts(dm_DF, rows = seq(1, nrow(dm_DF), 2), cols = 2, value = 5)

Cumulative sums, products, minima and maxima for each row (column) in a matrix

Description

Cumulative sums, products, minima and maxima for each row (column) in a matrix.

Usage

colCummaxs(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
colCummins(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
colCumprods(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
colCumsums(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
rowCummaxs(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
rowCummins(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
rowCumprods(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
rowCumsums(x, rows = NULL, cols = NULL, dim. = dim(x), ...)
list(list("colCummaxs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("colCummins"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("colCumprods"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("colCumsums"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowCummaxs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowCummins"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowCumprods"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowCumsums"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  dim. = dim(x), force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric NxK matrix of the same mode as x .

Seealso

See cumsum (), cumprod (), cummin (), and cummax ().

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colCummaxs(dm_matrix)

colCummins(dm_matrix)

colCumprods(dm_matrix)

colCumsums(dm_matrix)

# Only use rows 2-4
rowCummaxs(dm_Matrix, rows = 2:4)

# Only use rows 2-4
rowCummins(dm_Matrix, rows = 2:4)

# Only use rows 2-4
rowCumprods(dm_Matrix, rows = 2:4)

# Only use rows 2-4
rowCumsums(dm_Matrix, rows = 2:4)

Calculates difference for each row (column) in a matrix

Description

Calculates difference for each row (column) in a matrix.

Usage

colDiffs(x, rows = NULL, cols = NULL, lag = 1L, differences = 1L,
  dim. = dim(x), ...)
rowDiffs(x, rows = NULL, cols = NULL, lag = 1L, differences = 1L,
  dim. = dim(x), ...)
list(list("colDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  lag = 1L, differences = 1L, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  lag = 1L, differences = 1L, dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
lagAn integer specifying the lag.
differencesAn integer specifying the order of difference.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric Nx(K-1) or (N-1)xK matrix .

Seealso

See also diff2 ().

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'HDF5ArraySeed' seed
# NOTE: Requires that the HDF5Array package is installed
library(HDF5Array)
dm_HDF5 <- writeHDF5Array(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colDiffs(dm_matrix)

rowDiffs(dm_HDF5)
# In reverse column order
rowDiffs(dm_HDF5, cols = seq(ncol(dm_HDF5), 1, -1))

Estimation of scale based on sequential-order differences

Description

Estimation of scale based on sequential-order differences, corresponding to the scale estimates provided by var , sd , mad and IQR .

Usage

colIQRDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
colMadDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
colSdDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
colVarDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
rowIQRDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
rowMadDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
rowSdDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
rowVarDiffs(x, rows = NULL, cols = NULL, na.rm = FALSE, diff = 1L,
  trim = 0, ...)
list(list("colIQRDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("colMadDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("colSdDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("colVarDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("rowIQRDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("rowMadDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("rowSdDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)
list(list("rowVarDiffs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, diff = 1L, trim = 0,
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , NA s are excluded, otherwise not.
diffThe positional distance of elements for which the difference should be calculated.
trimA double in [0,1/2] specifying the fraction of observations to be trimmed from each end of (sorted) x before estimation.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

Note that n-order difference MAD estimates, just like the ordinary MAD estimate by mad , apply a correction factor such that the estimates are consistent with the standard deviation under Gaussian distributions.

The interquartile range (IQR) estimates does not apply such a correction factor. If asymptotically normal consistency is wanted, the correction factor for IQR estimate is 1 / (2 * qnorm(3/4)) , which is half of that used for MAD estimates, which is 1 / qnorm(3/4) . This correction factor needs to be applied manually, i.e. there is no constant argument for the IQR functions.

Value

Returns a numeric vector of length 1, length N, or length K.

Seealso

For the corresponding non-differentiated estimates, see var , sd , mad and IQR . Internally, diff2 () is used which is a faster version of diff ().

References

[1] J. von Neumann et al., list("The mean square successive ", "difference") . Annals of Mathematical Statistics, 1941, 12, 153-162. list()

Examples

# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'SolidRleArraySeed' seed
dm_Rle <- RleArray(Rle(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L))),
dim = c(5, 3))

colIQRDiffs(dm_Matrix)

colMadDiffs(dm_Matrix)

colSdDiffs(dm_Matrix)

colVarDiffs(dm_Matrix)

# Only using rows 2-4
rowIQRDiffs(dm_Rle, rows = 2:4)

# Only using rows 2-4
rowMadDiffs(dm_Rle, rows = 2:4)

# Only using rows 2-4
rowSdDiffs(dm_Rle, rows = 2:4)

# Only using rows 2-4
rowVarDiffs(dm_Rle, rows = 2:4)

Estimates of the interquartile range for each row (column) in a matrix

Description

Estimates of the interquartile range for each row (column) in a matrix.

Usage

colIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ...)
rowIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ...)
list(list("colIQRs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("rowIQRs"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , missing values are dropped first, otherwise not.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric vector of length N (K).

Seealso

See IQR . See rowSds ().

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colIQRs(dm_matrix)

# Only using rows 2-4
rowIQRs(dm_matrix, rows = 2:4)
Link to this function

colLogSumExps()

Accurately computes the logarithm of the sum of exponentials across rows or columns

Description

Accurately computes the logarithm of the sum of exponentials across rows or columns.

Usage

colLogSumExps(lx, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(lx), ...)
rowLogSumExps(lx, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(lx), ...)
list(list("colLogSumExps"), list("DelayedMatrix"))(lx, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(lx), force_block_processing = FALSE, ...)
list(list("rowLogSumExps"), list("DelayedMatrix"))(lx, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(lx), force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
lxA NxK DelayedMatrix . Typically, lx are $log(x)$ values.
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , any missing values are ignored, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

A numeric vector of length N (K).

Seealso

To calculate the same on vectors, logSumExp ().

Examples

x <- DelayedArray(matrix(runif(10), ncol = 2))
colLogSumExps(log(x))
rowLogSumExps(log(x))

Standard deviation estimates for each row (column) in a matrix

Description

Standard deviation estimates for each row (column) in a matrix.

Usage

colMads(x, rows = NULL, cols = NULL, center = NULL,
  constant = 1.4826, na.rm = FALSE, dim. = dim(x), ...)
colSds(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL,
  dim. = dim(x), ...)
rowMads(x, rows = NULL, cols = NULL, center = NULL,
  constant = 1.4826, na.rm = FALSE, dim. = dim(x), ...)
rowSds(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL,
  dim. = dim(x), ...)
list(list("colMads"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  center = NULL, constant = 1.4826, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("colSds"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, center = NULL, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowMads"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  center = NULL, constant = 1.4826, na.rm = FALSE, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowSds"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, center = NULL, dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
center(optional) The center, defaults to the row means for the SD estimators and row medians for the MAD estimators.
constantA scale factor. See mad for details.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric vector of length N (K).

Seealso

sd , mad and var . rowIQRs ().

Examples

# A DelayedMatrix with a 'data.frame' seed
dm_df <- DelayedArray(data.frame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))
# A DelayedMatrix with a 'DataFrame' seed
dm_DF <- DelayedArray(S4Vectors::DataFrame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))

colMads(dm_df)

colSds(dm_df)

rowMads(dm_DF)

rowSds(dm_DF)

Calculates the mean for each row (column) in a matrix

Description

Calculates the mean for each row (column) in a matrix.

Usage

colMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(x), ...)
rowMeans2(x, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(x), ...)
list(list("colMeans2"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("colMeans2"), list("Matrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)
list(list("colMeans2"), list("SolidRleArraySeed"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)
list(list("rowMeans2"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowMeans2"), list("Matrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementation of rowMeans2() and colMeans2() is optimized for both speed and memory.

Value

Returns a numeric vector of length N (K).

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'SolidRleArraySeed' seed
dm_Rle <- RleArray(Rle(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L))),
dim = c(5, 3))

colMeans2(dm_matrix)

# NOTE: Temporarily use verbose output to demonstrate which method is
#       which method is being used
options(DelayedMatrixStats.verbose = TRUE)
# By default, this uses a seed-aware method for a DelayedMatrix with a
# 'SolidRleArraySeed' seed
rowMeans2(dm_Rle)
# Alternatively, can use the block-processing strategy
rowMeans2(dm_Rle, force_block_processing = TRUE)
options(DelayedMatrixStats.verbose = FALSE)

Calculates the median for each row (column) in a matrix

Description

Calculates the median for each row (column) in a matrix.

Usage

colMedians(x, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(x), ...)
rowMedians(x, rows = NULL, cols = NULL, na.rm = FALSE,
  dim. = dim(x), ...)
list(list("colMedians"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowMedians"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementation of rowMedians() and colMedians() is optimized for both speed and memory. To avoid coercing to double s (and hence memory allocation), there is a special implementation for integer matrices. That is, if x is an integer matrix , then rowMedians(as.double(x)) ( rowMedians(as.double(x)) ) would require three times the memory of rowMedians(x) ( colMedians(x) ), but all this is avoided.

Value

Returns a numeric vector of length N (K).

Seealso

See rowWeightedMedians and colWeightedMedians() for weighted medians. For mean estimates, see rowMeans2 and rowMeans .

Examples

# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colMedians(dm_Matrix)

rowMedians(dm_Matrix)
Link to this function

colOrderStats()

Gets an order statistic for each row (column) in a matrix

Description

Gets an order statistic for each row (column) in a matrix.

Usage

colOrderStats(x, rows = NULL, cols = NULL, which, dim. = dim(x), ...)
rowOrderStats(x, rows = NULL, cols = NULL, which, dim. = dim(x), ...)
list(list("colOrderStats"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  which, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowOrderStats"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  which, dim. = dim(x), force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
whichAn integer index in [1,K] ([1,N]) indicating which order statistic to be returned.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementation of rowOrderStats() is optimized for both speed and memory. To avoid coercing to double s (and hence memory allocation), there is a unique implementation for integer matrices.

Value

Returns a numeric vector of length N (K).

Seealso

See rowMeans() in colSums ().

Examples

# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# Only using columns 2-3
colOrderStats(dm_Matrix, cols = 2:3, which = 1)

# Different algorithms, specified by `which`, may give different results
rowOrderStats(dm_Matrix, which = 1)
rowOrderStats(dm_Matrix, which = 2)

Calculates the product for each row (column) in a matrix

Description

Calculates the product for each row (column) in a matrix.

Usage

colProds(x, rows = NULL, cols = NULL, na.rm = FALSE,
  method = c("direct", "expSumLog"), ...)
rowProds(x, rows = NULL, cols = NULL, na.rm = FALSE,
  method = c("direct", "expSumLog"), ...)
list(list("colProds"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, method = c("direct", "expSumLog"),
  force_block_processing = FALSE, ...)
list(list("colProds"), list("SolidRleArraySeed"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, method = c("direct", "expSumLog"), ...)
list(list("rowProds"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, method = c("direct", "expSumLog"),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , missing values are ignored, otherwise not.
methodA character string specifying how each product is calculated.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

If method = "expSumLog" , then then product () function is used, which calculates the produce via the logarithmic transform (treating negative values specially). This improves the precision and lowers the risk for numeric overflow. If method = "direct" , the direct product is calculated via the prod () function.

Value

Returns a numeric vector of length N (K).

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'HDF5ArraySeed' seed
# NOTE: Requires that the HDF5Array package is installed
library(HDF5Array)
dm_HDF5 <- writeHDF5Array(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colProds(dm_matrix)

rowProds(dm_matrix)

Estimates quantiles for each row (column) in a matrix

Description

Estimates quantiles for each row (column) in a matrix.

Usage

colQuantiles(x, rows = NULL, cols = NULL, probs = seq(from = 0, to =
  1, by = 0.25), na.rm = FALSE, type = 7L, ..., drop = TRUE)
rowQuantiles(x, rows = NULL, cols = NULL, probs = seq(from = 0, to =
  1, by = 0.25), na.rm = FALSE, type = 7L, ..., drop = TRUE)
list(list("colQuantiles"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25), na.rm = FALSE, type = 7L,
  force_block_processing = FALSE, ..., drop = TRUE)
list(list("rowQuantiles"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25), na.rm = FALSE, type = 7L,
  force_block_processing = FALSE, ..., drop = TRUE)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
probsA numeric vector of J probabilities in [0, 1].
na.rmIf TRUE , NA s are excluded first, otherwise not.
typeAn integer specify the type of estimator. See quantile for more details.
...Additional arguments passed to specific methods.
dropIf TRUE, singleton dimensions in the result are dropped, otherwise not.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric NxJ (KxJ) matrix , where N (K) is the number of rows (columns) for which the J quantiles are calculated.

Seealso

quantile .

Examples

# A DelayedMatrix with a 'data.frame' seed
dm_df <- DelayedArray(data.frame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))

# colnames, if present, are preserved as rownames on output
colQuantiles(dm_df)

# Input has no rownames so output has no rownames
rowQuantiles(dm_df)

Gets the rank of each row (column) of a matrix

Description

Gets the rank of each row (column) of a matrix.

Usage

colRanks(x, rows = NULL, cols = NULL, ties.method = c("max",
  "average", "min"), dim. = dim(x), preserveShape = FALSE, ...)
rowRanks(x, rows = NULL, cols = NULL, ties.method = c("max",
  "average", "min"), dim. = dim(x), ...)
list(list("colRanks"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  ties.method = c("max", "average", "min"), dim. = dim(x),
  preserveShape = FALSE, force_block_processing = FALSE, ...)
list(list("rowRanks"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  ties.method = c("max", "average", "min"), dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
ties.methodA character string specifying how ties are treated. For details, see below.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
preserveShapeA logical specifying whether the matrix returned should preserve the input shape of x , or not.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The row ranks of x are collected as rows of the result matrix.

The column ranks of x are collected as rows if preserveShape = FALSE , otherwise as columns .

The implementation is optimized for both speed and memory. To avoid coercing to double s (and hence memory allocation), there is a unique implementation for integer matrices. It is more memory efficient to do colRanks(x, preserveShape = TRUE) than t(colRanks(x, preserveShape = FALSE)) .

Any names of x are ignored and absent in the result.

Value

An integer matrix is returned. The rowRanks() function always returns an NxK matrix , where N (K) is the number of rows (columns) whose ranks are calculated.

The colRanks() function returns an NxK matrix , if preserveShape = TRUE , otherwise a KxN matrix .

%% The mode of the returned matrix is code{link[base]{integer}}, except for %% code{ties.method == "average"} when it is double .

Seealso

rank (). For developers, see also Section 'Utility functions' in 'Writing R Extensions manual', particularly the native functions R_qsort_I() and R_qsort_int_I() .

Examples

# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colRanks(dm_Matrix)

rowRanks(dm_Matrix)

Calculates the sum for each row (column) in a matrix

Description

Calculates the sum for each row (column) in a matrix.

Usage

colSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x),
  ...)
rowSums2(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x),
  ...)
list(list("colSums2"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("colSums2"), list("Matrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)
list(list("colSums2"), list("SolidRleArraySeed"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)
list(list("rowSums2"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), force_block_processing = FALSE, ...)
list(list("rowSums2"), list("Matrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, dim. = dim(x), ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , NA s are excluded first, otherwise not.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementation of rowSums2() and colSums2() is optimized for both speed and memory.

Value

Returns a numeric vector of length N (K).

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colSums2(dm_matrix)

# NOTE: Temporarily use verbose output to demonstrate which method is
#       which method is being used
options(DelayedMatrixStats.verbose = TRUE)
# By default, this uses a seed-aware method for a DelayedMatrix with a
# 'SolidRleArraySeed' seed
rowSums2(dm_Matrix)
# Alternatively, can use the block-processing strategy
rowSums2(dm_Matrix, force_block_processing = TRUE)
options(DelayedMatrixStats.verbose = FALSE)

Tabulates the values in a matrix by row (column)

Description

Tabulates the values in a matrix by row (column).

Usage

colTabulates(x, rows = NULL, cols = NULL, values = NULL, ...)
rowTabulates(x, rows = NULL, cols = NULL, values = NULL, ...)
list(list("colTabulates"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  values = NULL, force_block_processing = FALSE, ...)
list(list("rowTabulates"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  values = NULL, force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
valuesAn vector of J values of count. If NULL , all (unique) values are counted.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a NxJ (KxJ) matrix where N (K) is the number of row (column) vector s tabulated and J is the number of values counted.

Examples

# A DelayedMatrix with a 'DataFrame' seed
dm_DF <- DelayedArray(S4Vectors::DataFrame(C1 = rep(1L, 5),
C2 = as.integer((0:4) ^ 2),
C3 = seq(-5L, -1L, 1L)))

colTabulates(dm_DF)

rowTabulates(dm_DF)

Variance estimates for each row (column) in a matrix

Description

Variance estimates for each row (column) in a matrix.

Usage

colVars(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL,
  dim. = dim(x), ...)
rowVars(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL,
  dim. = dim(x), ...)
list(list("colVars"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, center = NULL, dim. = dim(x),
  force_block_processing = FALSE, ...)
list(list("rowVars"), list("DelayedMatrix"))(x, rows = NULL, cols = NULL,
  na.rm = FALSE, center = NULL, dim. = dim(x),
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , missing values are excluded first, otherwise not.
center(optional) The center, defaults to the row means.
dim.An integer vector of length two specifying the dimension of x , also when not a matrix .
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric vector of length N (K).

Seealso

See rowMeans() and rowSums() in colSums ().

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))
# A DelayedMatrix with a 'HDF5ArraySeed' seed
# NOTE: Requires that the HDF5Array package is installed
library(HDF5Array)
dm_HDF5 <- writeHDF5Array(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colVars(dm_matrix)

rowVars(dm_matrix)
Link to this function

colWeightedMads()

Weighted Median Absolute Deviation (MAD)

Description

Computes a weighted MAD of a numeric vector.

Usage

colWeightedMads(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, constant = 1.4826, center = NULL, ...)
rowWeightedMads(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, constant = 1.4826, center = NULL, ...)
list(list("colWeightedMads"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, constant = 1.4826, center = NULL,
  force_block_processing = FALSE, ...)
list(list("rowWeightedMads"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, constant = 1.4826, center = NULL,
  force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
wa vector of weights the same length as x giving the weights to use for each element of x . Negative weights are treated as zero weights. Default value is equal weight to all values.
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
na.rma logical value indicating whether NA values in x should be stripped before the computation proceeds, or not. If NA , no check at all for NA s is done. Default value is NA (for efficiency).
constantA numeric scale factor, cf. mad .
centerOptional numeric scalar specifying the center location of the data. If NULL , it is estimated from data.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Value

Returns a numeric scalar.

Seealso

For the non-weighted MAD, see mad . Internally weightedMedian () is used to calculate the weighted median.

Examples

# A DelayedMatrix with a 'matrix' seed
dm_matrix <- DelayedArray(matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colWeightedMads(dm_matrix, w = 1:5)

rowWeightedMads(dm_matrix, w = 3:1)
Link to this function

colWeightedMeans()

Calculates the weighted means for each row (column) in a matrix

Description

Calculates the weighted means for each row (column) in a matrix.

Usage

colWeightedMeans(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
rowWeightedMeans(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
list(list("colWeightedMeans"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("rowWeightedMeans"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
wA numeric vector of length K (N).
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , missing values are excluded from the calculation, otherwise not.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementations of these methods are optimized for both speed and memory. If no weights are given, the corresponding rowMeans() / colMeans() is used.

Value

Returns a numeric vector of length N (K).

Seealso

See rowMeans() and colMeans() in colSums () for non-weighted means. See also weighted.mean .

Examples

# A DelayedMatrix with a 'Matrix' seed
dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L)),
ncol = 3))

colWeightedMeans(dm_Matrix)
# Specifying weights inversely proportional to rowwise variances
colWeightedMeans(dm_Matrix, w = 1 / rowVars(dm_Matrix))
rowWeightedMeans(dm_Matrix, w = 1:3)
Link to this function

colWeightedMedians()

Calculates the weighted medians for each row (column) in a matrix

Description

Calculates the weighted medians for each row (column) in a matrix.

Usage

colWeightedMedians(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
rowWeightedMedians(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
list(list("colWeightedMedians"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("rowWeightedMedians"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
wA numeric vector of length K (N).
rowsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of rows (and/or columns) to operate over. If NULL , no subsetting is done.
na.rmIf TRUE , missing values are excluded from the calculation, otherwise not.
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The implementations of these methods are optimized for both speed and memory. If no weights are given, the corresponding rowMedians ()/ colMedians() is used.

Value

Returns a numeric vector of length N (K).

Seealso

Internally, weightedMedian () is used. See rowMedians () and colMedians() for non-weighted medians.

Examples

# A DelayedMatrix with a 'SolidRleArraySeed' seed
dm_Rle <- RleArray(Rle(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L))),
dim = c(5, 3))

# Specifying weights inversely proportional to rowwise MADs
colWeightedMedians(dm_Rle, w = 1 / rowMads(dm_Rle))
Link to this function

colWeightedVars()

Weighted variance and weighted standard deviation

Description

Computes a weighted variance / standard deviation of a numeric vector or across rows or columns of a matrix.

Usage

colWeightedSds(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
colWeightedVars(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
rowWeightedSds(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
rowWeightedVars(x, w = NULL, rows = NULL, cols = NULL,
  na.rm = FALSE, ...)
list(list("colWeightedSds"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("colWeightedVars"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("rowWeightedSds"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
list(list("rowWeightedVars"), list("DelayedMatrix"))(x, w = NULL, rows = NULL,
  cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)

Arguments

ArgumentDescription
xA NxK DelayedMatrix .
wa vector of weights the same length as x giving the weights to use for each element of x . Negative weights are treated as zero weights. Default value is equal weight to all values.
rowsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
colsA vector indicating subset of elements (or rows and/or columns) to operate over. If NULL , no subsetting is done.
na.rma logical value indicating whether NA values in x should be stripped before the computation proceeds, or not. If NA , no check at all for NA s is done. Default value is NA (for efficiency).
...Additional arguments passed to specific methods.
force_block_processingFALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize ) columns ( colFoo() ) or rows ( rowFoo() ) into memory as an ordinary base::array .

Details

The estimator used here is the same as the one used by the "unbiased" estimator of the Hmisc package. More specifically, weightedVar(x, w = w) == Hmisc::wtd.var(x, weights = w) ,

Value

Returns a numeric scalar.

Seealso

For the non-weighted variance, see var .

Examples

# A DelayedMatrix with a 'SolidRleArraySeed' seed
dm_Rle <- RleArray(Rle(c(rep(1L, 5),
as.integer((0:4) ^ 2),
seq(-5L, -1L, 1L))),
dim = c(5, 3))

colWeightedSds(dm_Rle, w = 1 / rowMeans2(dm_Rle))

# Specifying weights inversely proportional to rowwise means
colWeightedVars(dm_Rle, w = 1 / rowMeans2(dm_Rle))

# Specifying weights inversely proportional to columnwise means
rowWeightedSds(dm_Rle, w = 1 / colMeans2(dm_Rle))

# Specifying weights inversely proportional to columnwise means
rowWeightedVars(dm_Rle, w = 1 / colMeans2(dm_Rle))
Link to this function

from_DelayedArray_to_simple_seed_class()

Coerce DelayedArray to its 'simple seed' form

Description

Coerce DelayedArray to its 'simple seed' form

Usage

from_DelayedArray_to_simple_seed_class(x, drop = FALSE,
  do_transpose = TRUE)

Arguments

ArgumentDescription
xA DelayedArray
dropIf TRUE the result is coerced to the lowest possible dimension
do_transposeShould transposed input be physically transposed?

Details

Like DelayedArray:::.from_DelayedArray_to_array but returning an object of the same class as seedClass(x) instead of an array . In doing so, all delayed operations are realised (including subsetting).

Value

An object of the same class as seedClass(x) .

Note

Can be more efficient to leave the transpose implicit ( do_transpose = FALSE ) and switch from a row*() method to a col*() method (or vice versa).

Only works on DelayedArray objects with 'simple seeds'

Link to this function

rowblock_APPLY()

Adapted from DelayedArray:::colblock_APPLY()

Description

Adapted from DelayedArray:::colblock_APPLY()

Usage

rowblock_APPLY(x, APPLY, ..., sink = NULL)

Value

A list of length equal to ncol(x) , each list element storing the result for the corresponding column.

Get the class of the seed of a DelayedArray

Description

Get the class of the seed of a DelayedArray

Usage

seedClass(x)

Arguments

ArgumentDescription
xA DelayedArray::DelayedArray .

Value

The class of the seed of the DelayedArray::DelayedArray object.

Note

Can't use class(seed(x)) because seed(x) will return an error if the seed is a DelayedArray::DelayedOp .

Link to this function

subset_by_Nindex()

subset_by_Nindex

Description

subset_by_Nindex() is an internal generic function not aimed to be used directly by the user. It is basically an S4 generic for DelayedArray:::subset_by_Nindex .

Usage

subset_by_Nindex(x, Nindex)

Arguments

ArgumentDescription
xAn array-like object.
NindexAn unnamed list of subscripts as positive integer vectors, one vector per dimension in x . Empty and missing subscripts (represented by integer(0) and NULL list elements, respectively) are allowed. The subscripts can contain duplicated indices. They cannot contain NA s or non-positive values.

Details

subset_by_Nindex(x, Nindex) conceptually performs the operation x[Nindex[1], ..., Nindex[length(Nindex)]) . subset_by_Nindex() methods need to support empty and missing subscripts, e.g., subset_by_Nindex(x, list(NULL, integer(0))) must return an M x 0 object of class class(x) and subset_by_Nindex(x, list(integer(0), integer(0))) a 0 x 0 object of class class(x) .

Also, subscripts are allowed to contain duplicate indices so things like subset_by_Nindex(x, list(c(1:3, 3:1), 2L)) need to be supported.

Value

A object of class class(x) of the appropriate type (e.g., integer, double, etc.). For example, if x is a data.frame representing an M x N matrix of integers, subset_by_Nindex(x, list(NULL, 2L) must return its 2nd column as a data.frame with M rows and 1 column of type integer.