# NOT RUN {
# }
# NOT RUN {
## Individual-based and coverage-based rarefaction
# Simulate a community with number of species (sr) and evenness randomly selected
spn <- rlnorm(runif(1, 10, 200))
evenness <- runif(1, log(1.1), log(33))
com <- round(rlnorm(spn, 3, evenness))
# Sample the community (with sample size n = 500 individuals)
sample1 <- sample(paste("sp",1:length(com)), 500, replace=TRUE, prob=com)
sample1 <- table(sample1)
# Get the individual-based and coverage-based rarefaction curves for different Hill numbers
ibr.q0 <- rarefaction.individual(sample1)
ibr.q1 <- rarefaction.individual(sample1, q=1)
ibr.q2 <- rarefaction.individual(sample1, q=2)
ibr.q0.cov <- rarefaction.individual(sample1, method="coverage")
ibr.q1.cov <- rarefaction.individual(sample1, q=1, method="coverage")
ibr.q2.cov <- rarefaction.individual(sample1, q=2, method="coverage")
# Plot the results
par(mfcol=c(1,2))
plot(ibr.q0[,1], ibr.q0[,2], lwd=2, xlab="Number of individuals", ylab="Hill numbers",
type="l", main="Individual-based rarefaction")
lines(ibr.q1[,1], ibr.q1[,2], lwd=2, lty=2)
lines(ibr.q2[,1], ibr.q2[,2], lwd=2, lty=3)
legend("bottomright", lty=c(1,2,3), lwd=2, legend=c("q = 0", "q = 1", "q = 2"), cex=1.2)
plot(ibr.q0.cov[,1], ibr.q0.cov[,2], lwd=2, xlab="Coverage", ylab="Hill numbers",
type="l", main="Coverage-based rarefaction")
lines(ibr.q1.cov[,1], ibr.q1.cov[,2], lwd=2, lty=2)
lines(ibr.q2.cov[,1], ibr.q2.cov[,2], lwd=2, lty=3)
legend("topleft", lty=c(1,2,3), lwd=2, legend=c("q = 0", "q = 1", "q = 2"), cex=1.2)
## Sample-based and coverage-based rarefaction
# Load the data
data(Chiapas)
Chiapas <- subset(Chiapas, Region=="El Triunfo")
str(Chiapas)
# Get sample-based and coverage-based rarefaction curves for different Hill numbers
sbr.q0 <- rarefaction.sample(Chiapas[,-1])
sbr.q1 <- rarefaction.sample(Chiapas[,-1], q=1)
sbr.q2 <- rarefaction.sample(Chiapas[,-1], q=2)
sbr.q0.cov <- rarefaction.sample(Chiapas[,-1], method="coverage")
sbr.q1.cov <- rarefaction.sample(Chiapas[,-1], q=1, method="coverage")
sbr.q2.cov <- rarefaction.sample(Chiapas[,-1], q=2, method="coverage")
# Plot the results
par(mfcol=c(1,2))
plot(sbr.q0[,1], sbr.q0[,2], lwd=2, xlab="Sampling units", ylab="Hill numbers",
type="l", main="Sample-based rarefaction")
lines(sbr.q1[,1], sbr.q1[,2], lwd=2, lty=2)
lines(sbr.q2[,1], sbr.q2[,2], lwd=2, lty=3)
legend("bottomright", lty=c(1,2,3), lwd=2, legend=c("q = 0", "q = 1", "q = 2"), cex=1.2)
plot(sbr.q0.cov[,1], sbr.q0.cov[,2], lwd=2, xlab="Coverage", ylab="Hill numbers",
type="l", main="Coverage-based rarefaction")
lines(sbr.q1.cov[,1], sbr.q1.cov[,2], lwd=2, lty=2)
lines(sbr.q2.cov[,1], sbr.q2.cov[,2], lwd=2, lty=3)
legend("topleft", lty=c(1,2,3), lwd=2, legend=c("q = 0", "q = 1", "q = 2"), cex=1.2)
# }
Run the code above in your browser using DataLab