Skip to contents

Calculate diversity statistics on a matrix containing counts of multilocus genotypes per population.

Usage

diversity_stats(z, H = TRUE, G = TRUE, lambda = TRUE, E5 = TRUE, ...)

Arguments

z

a table of integers representing counts of MLGs (columns) per population (rows)

H

logical whether or not to calculate Shannon's index

G

logical whether or not to calculate Stoddart and Taylor's index (aka inverse Simpson's index).

lambda

logical whether or not to calculate Simpson's index

E5

logical whether or not to calculate Evenness

...

any functions that can be calculated on a vector or matrix of genotype counts.

Value

a numeric matrix giving statistics (columns) for each population (rows).

Details

This function will calculate any diversity statistic for counts of multilocus genotypes per population. This does not count allelic diversity. The calculations of H, G, and lambda are all performed by vegan::diversity(). E5 is calculated as $$E_{5} = \frac{(1/\lambda) - 1}{e^{H} - 1}$$.

Author

Zhian N. Kamvar

Examples

library(poppr)
data(Pinf)
tab <- mlg.table(Pinf, plot = FALSE)
diversity_stats(tab)
#>                Index
#> Pop                    H        G    lambda       E.5
#>   South America 3.267944 23.29032 0.9570637 0.8825297
#>   North America 3.687013 34.90909 0.9713542 0.8711297
# \dontrun{
# Example using the poweRlaw package to calculate the negative slope of the
# Pareto distribution.

library("poweRlaw")
power_law_beta <- function(x){
  xpow <- displ(x[x > 0])                 # Generate the distribution
  xpow$setPars(estimate_pars(xpow))       # Estimate the parameters
  xdat <- plot(xpow, draw = FALSE)        # Extract the data
  xlm <- lm(log(y) ~ log(x), data = xdat) # Run log-log linear model for slope
  return(-coef(xlm)[2])
}

Beta <- function(x){
  x <- drop(as.matrix(x))
  if (length(dim(x)) > 1){
    res <- apply(x, 1, power_law_beta)
  } else {
    res <- power_law_beta(x)
  }
  return(res)
}

diversity_stats(tab, B = Beta)
#>                Index
#> Pop                    H        G    lambda       E.5        B
#>   South America 3.267944 23.29032 0.9570637 0.8825297 2.087440
#>   North America 3.687013 34.90909 0.9713542 0.8711297 2.735194
# }