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