This function computes measures of variability.
Usage
rowVariability(
x,
g = NULL,
method = c("sd", "iqr", "mad", "rsd", "efficiency", "vmr")
)
Arguments
- x
matrix
ordata.frame
, where rows are features and columns are observations.- g
(optional) vector or factor object giving the group for the corresponding elements of
x
.- method
character string indicating the measure of variability. Available options are:
"sd"
the standard deviation
"iqr"
the interquartile range
"mad"
the median absolute deviation
"rsd"
the relative standard deviation (i.e., coefficient of variation)
"efficiency"
the coefficient of variation squared
"vmr"
the variance-to-mean ratio
Value
A vector
of length nrow(x)
containing the computed ratios.
If g
is provided, a matrix
with ratios for each class as column
vectors is returned.
Details
The corrected sample standard deviation is the defined as:
$$ SD = \sqrt{ \frac{1}{N-1} \sum_{i=1}{N}(x_{i} - \bar{x})^2 } $$
where \(x\) is a vector of \(N\) elements, and \(\bar{x}\) is its mean value.
The interquartile range is defined as the difference between the 75th and 25th percentiles of the data:
$$ IQR = Q_{3} - Q_{1})$$
The median absolute deviation is defined as the median of the absolute deviations from the mean:
$$ MAD = \median(|x_{i} - \bar{x}|)$$
The relative standard variation is defined as the ratio of the standard deviation to the mean:
$$ RSD = \frac{standard deviation}{mean} = \frac{\sigma}{\mu}$$
The efficiency is the square of the coefficient of variation:
$$ efficiency = (\frac{standard deviation}{mean})^2 = \frac{\sigma^2}{\mu^2}$$
The variance-to-mean ratio is computed as the ratio of the variance to the mean:
$$ VMR = \frac{variance}{mean} = \frac{\sigma^2}{\mu}$$
See also the following functions for further details:
Examples
#Seed
set.seed(1010)
#Define row/col size
nr = 5
nc = 10
#Data
x = matrix(
data = sample.int(n = 100, size = nr*nc, replace = TRUE),
nrow = nr,
ncol = nc,
dimnames = list(
paste0("f",seq(nr)),
paste0("S",seq(nc))
)
)
#Grouping variable
g = c(rep("a", nc/2), rep("b", nc/2))
#Variance-to-mean Ratio
rowVariability(x = x, method = 'vmr')
#> f1 f2 f3 f4 f5
#> 15.50644 21.77472 15.59739 17.69918 12.55625
#Variance-to-mean Ratio by group
rowVariability(x = x, g = g, method = 'vmr')
#> a b
#> f1 3.111675 9.123418
#> f2 29.269231 19.569767
#> f3 21.534700 11.842593
#> f4 5.087748 31.528846
#> f5 9.791391 17.806548