#' @title Variance/mean ratio
#' @description Aggregation Index - Variance/mean
#' @param x number of parasites by host
#' @export
#' @examples
#' attach(birdticks)
#' var_mean(ticks)
var_mean <- function(x) {
if (any(is.na(x))){
warning("Missing values were ignored.")
x <- x[!is.na(x)]
}
if (!is.numeric(x)){
stop(paste("Number of parasites must be a numeric variable."))
}
if (any(x < 0)) {
stop(paste("Number of parasites must be positive values."))
}
if (any(!is.wholenumber(x))) {
stop(paste("Numbers of parasites must be integers."))
}
if (sum(x) == 0) {
return(NA)
} else {
I <- round(var(x)/mean(x), digits = 3)
return(I)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.