Skip to contents

This function computes the signal-to-noise ratio of the values in x. It is the reciprocal of the coefficient of variation.

See the Details section below for further information.

Usage

snr(x, g = NULL, na.rm = TRUE)

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.

Value

A numerical value or a vector containing the computed measure per class.

Details

The signal-to-noise ratio is here defined as the ratio of the mean to the standard deviation:

$$ SNR = \frac{mean}{standard deviation} = \frac{\mu}{\sigma} $$

If x can be partitioned into \(c\) subgroups (provided by g), then the \(SNR\) is computed for each class.

References

https://en.wikipedia.org/wiki/Coefficient_of_variation

Author

Alessandro Barberis

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

#Signal-to-noise ratio
snr(x)
#> [1] 2.21424

#Signal-to-noise ratio by group
snr(x = x, g = g)
#>        a        b 
#> 1.450843 5.195253