Skip to contents

Calculates the coefficient of variation, also known as relative standard deviation, which is given by $$sd(x)/mean(x)$$

Usage

rsd(x, as_percentage = TRUE, na.rm = TRUE, adjust = FALSE, adjust_lo = 1)

Arguments

x

Numeric: Input

as_percentage

Logical: If TRUE, multiply by 100

na.rm

Logical: If TRUE, remove missing values before computation

adjust

Logical: If TRUE, if x contains values < adjust_lo, x will be shifted up by adding its minimum

adjust_lo

Float: Threshold to be used if adjust = TRUE

Details

This is not meaningful if mean is close to 0. For such cases, set adjust = TRUE. This will add min(x) to x

Examples

if (FALSE) { # \dontrun{
mplot3_x(sapply(1:100, function(x) cov(rnorm(100))), "d", xlab = "rnorm(100) x 100 times")
# cov of rnorm without adjustment is all over the place
mplot3_x(sapply(1:100, function(x) cov(rnorm(100), adjust = T)), "d",
  xlab = "rnorm(100) x 100 times"
)
# COV after shifting above 1 is what you probably want
} # }