## NOTE: 'nsimul' argument usually needs to be >= 99
## here much lower value is used for demonstration
data(mite)
data(mite.xy)
data(mite.env)
## Function to get equal area partitions of the mite data
cutter <- function (x, cut = seq(0, 10, by = 2.5)) {
out <- rep(1, length(x))
for (i in 2:(length(cut) - 1))
out[which(x > cut[i] & x <= cut[(i + 1)])] <- i
return(out)}
## The hierarchy of sample aggregation
levsm <- data.frame(
l1=1:nrow(mite),
l2=cutter(mite.xy$y, cut = seq(0, 10, by = 2.5)),
l3=cutter(mite.xy$y, cut = seq(0, 10, by = 5)),
l4=cutter(mite.xy$y, cut = seq(0, 10, by = 10)))
## Let's see in a map
par(mfrow=c(1,3))
plot(mite.xy, main="l1", col=as.numeric(levsm$l1)+1)
plot(mite.xy, main="l2", col=as.numeric(levsm$l2)+1)
plot(mite.xy, main="l3", col=as.numeric(levsm$l3)+1)
par(mfrow=c(1,1))
## Additive diversity partitioning
adipart(mite, index="richness", nsimul=19)
adipart(mite ~ ., levsm, index="richness", nsimul=19)
## Hierarchical null model testing
## diversity analysis (similar to adipart)
hiersimu(mite, FUN=diversity, relative=TRUE, nsimul=19)
hiersimu(mite ~., levsm, FUN=diversity, relative=TRUE, nsimul=19)
## Hierarchical testing with the Morisita index
morfun <- function(x) dispindmorisita(x)$imst
hiersimu(mite ~., levsm, morfun, drop.highest=TRUE, nsimul=19)
Run the code above in your browser using DataLab