Skip to contents

This function computes the variance-to-mean ratio.

See the Details section below for further information.

Usage

vmr(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 variance-to-mean ratio (also known as index of dispersion) is a measure of dispersion. It is computed as:

$$ VMR = \frac{variance}{mean} = \frac{\sigma^2}{\mu}$$

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

References

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

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

#Variance-to-mean ratio
vmr(x)
#> [1] 12.87005

#Variance-to-mean ratio by group
vmr(x = x, g = g)
#>         a         b 
#> 23.848606  2.815789