colWeightedSds {DelayedMatrixStats} | R Documentation |
Computes a weighted variance / standard deviation of a numeric vector or across rows or columns of a matrix.
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, ...) ## S4 method for signature 'DelayedMatrix' colWeightedSds(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...) ## S4 method for signature 'DelayedMatrix' colWeightedVars(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...) ## S4 method for signature 'DelayedMatrix' rowWeightedSds(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...) ## S4 method for signature 'DelayedMatrix' rowWeightedVars(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, force_block_processing = FALSE, ...)
x |
A NxK DelayedMatrix. |
w |
a vector of weights the same length as |
rows |
A |
cols |
A |
na.rm |
a logical value indicating whether |
... |
Additional arguments passed to specific methods. |
force_block_processing |
|
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)
,
Returns a numeric
scalar.
This function handles missing values consistently with
weightedMean
().
More precisely, if na.rm = FALSE
, then any missing values in either
x
or w
will give result NA_real_
.
If na.rm = TRUE
, then all (x, w)
data points for which
x
is missing are skipped. Note that if both x
and w
are missing for a data points, then it is also skipped (by the same rule).
However, if only w
is missing, then the final results will always
be NA_real_
regardless of na.rm
.
For the non-weighted variance, see var
.
# 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))