This function computes the coefficient of variation
of the values in x
. It is also known as relative standard deviation.
See the Details section below for further information.
Arguments
- x
numerical vector.
- g
(optional) vector or factor object giving the group for the corresponding elements of
x
.- na.rm
logical indicating whether missing values should be removed before computation.
Details
The coefficient of variation - also known as Normalized Root-Mean-Square Deviation (NRMSD), Percent RMS, and relative standard deviation (RSD) - is a measure of statistical dispersion.
It is defined as the ratio of the standard deviation to the mean:
$$ CV = RSD = \frac{standard deviation}{mean} = \frac{\sigma}{\mu}$$
It is be computed as:
$$ RSD = \frac{ \sqrt{\sum_{j=1}^{n}} ({x}_{j} - \bar{x})^2 / n }{ \bar{x} } $$
where \(\bar{x}\) is the sample mean.
If x
can be partitioned into \(c\) subgroups (provided by g
),
then the \(RSD\) is computed for each class.
The coefficient of variation ranges between \([-\infty, \infty]\).
The main advantage of the coefficient of variation is that it is unitless.
References
Fong, Biuk-Aghai, Si, Lightweight Feature Selection Methods Based on Standardized Measure of Dispersion for Mining Big Data, 2016 IEEE International Conference on Computer and Information Technology (CIT)
Examples
#Seed
set.seed(1010)
#Define size
n = 10
#Data
x = sample.int(n = 100, size = n, replace = TRUE)
#Grouping variable
g = c(rep("a", n/2), rep("b", n/2))
#Coefficient of variation
rsd(x)
#> [1] 0.4516223
#Coefficient of variation by group
rsd(x = x, g = g)
#> a b
#> 0.6892545 0.1924834