Learn R Programming

poppr (version 2.9.6)

diversity_stats: Produce a table of diversity statistics

Description

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

Value

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

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.

Author

Zhian N. Kamvar

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}$$.

See Also

diversity_boot() diversity_ci() poppr()

Examples

Run this code
library(poppr)
data(Pinf)
tab <- mlg.table(Pinf, plot = FALSE)
diversity_stats(tab)
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab