# NOT RUN {
# }
# NOT RUN {
## Individual-based and coverage-based rarefaction
# Simulate a community with number of species (spn) and evenness randomly selected
spn <- round(runif(1, 10, 200))
evenness <- runif(1, log(1.1), log(33))
com <- round(rlnorm(spn, 2, evenness))
Ss <- round(runif(1, 50, 500))
sample1 <- sample(paste("sp",1:length(com)), rpois(1, Ss), replace=TRUE, prob=com)
sample1 <- data.frame(table(sample1))
colnames(sample1) <- c("species", "sample1")
sample2 <- sample(paste("sp",1:length(com)), rpois(1, Ss), replace=TRUE, prob=com)
sample2 <- data.frame(table(sample2))
colnames(sample2) <- c("species", "sample2")
df <- merge(sample1, sample2, by="species", all=TRUE)
rownames(df) <- df$species
df[is.na(df)] <- 0
df <- df[,2:3]
# Ecological null model test using sample-based rarefaction curves
# for species richness (q = 0)
# The test should not reject the null hypothesis in most cases (p > 0.05)
ibecoq0 <- EcoTest.individual(df, MARGIN=2, powerfun=0.8, log.scale=TRUE)
plot(ibecoq0)
# Ecological null model test using coverage-based rarefaction curves
# for the exponential Shannon index (q = 1)
ibecoq1cov <- EcoTest.individual(df, MARGIN=2, method="coverage",
q=1, powerfun=0.8, log.scale=TRUE)
plot(ibecoq1cov)
## Sample-based and coverage-based rarefaction
# Load the data
data(Chiapas)
Chiapas <- subset(Chiapas, Region!="El Triunfo")
str(Chiapas)
# Ecological null model test using sample-based rarefaction curves
# for species richness (q = 0)
sbecoq0 <- EcoTest.sample(Chiapas[,-1], by=Chiapas[,1], MARGIN=1)
plot(sbecoq0)
# Ecological null model test using coverage-based rarefaction curves
# for the inverse Simpson index (q = 2)
sbecoq2cov <- EcoTest.sample(Chiapas[,-1], by=Chiapas[,1],
MARGIN=1, method="coverage", q=2)
plot(sbecoq2cov)
# }
Run the code above in your browser using DataLab