## Supplementary material to the paper: Sabatini F.M., Burrascano S., Tuomisto H. and Blasi C. ## Ground layer plant species turnover and beta diversity in Southern-European old-growth forests. Plos One ## Appendix S1 – True diversity decomposition Script for R. ### Calculates alpha beta and gamma diversity according to Tuomisto 2010. ### Arguments: ### dataset: must be a sites x species tab (either p\a, absolute or relative freq). ### q: must be a vector of the exponents of Hill's weighted generalised mean ("Inf" not accepted). ### w: weights the plots in different ways, "even" =evenly weighted plots, ### "bycover" = plots weighted according to the sum of their species' frequencies ### or it can be a vector of weights of length==number of sites; whether the sum of weights for each ### group of sites (factor, see below) is not ==1, then they will be automatically rescaled. ### factor: a factor vector of length ==number of sites that clusters sites into groups. ### div.dec returns a list of length=length(q), each element of the list is a dataframe ### reporting alpha beta and gamma levels for each group of sites. ### version 01/10/2013 by Francesco Sabatini, thanks to Hanna Tuomisto ### Please cite as: Sabatini F.M., Burrascano S., Tuomisto H. and Blasi C. ### Ground layer plant species turnover and beta diversity in Southern-European old-growth forests. ### Plos One. div.dec <- function(dataset, q, w=c("even", "bycover",w), factor=NULL){ require(vegan) if(min(q)<0) stop("q must be greater than 0") ###implement when there is no factor! if(is.null(factor)){ factor <- factor(rep("A",dim(dataset)[1]))} if(length(factor)!=dim(dataset)[1]){ stop("factor length is not equal to the number of rows in the dataset") } res <- vector(0, mode="list" ) # res <- list(NA, dim=c(length(levels(factor)),3, length(q))) for(qq in 1:length(q)){ q1 <- q[qq] res[[qq]] <- as.data.frame(matrix(NA, nrow=length(levels(factor)), ncol=3)) colnames(res[[qq]]) <- c("alpha", "beta", "gamma") rownames(res[[qq]]) <- levels(factor) for (k in 1:length(levels(factor)) ){ x <- dataset[which(factor==levels(factor)[k]),] if(length(w)>1){ if(length(w)==dim(dataset)[1]){ w1 <- w[which(factor==levels(factor)[k])] if(sum(w1)!=1) # stop("sum(w) must be==1, for each factor") w1 <- w1/sum(w1) x <- w1*(x/rowSums(x)) } if(length(w)!=dim(dataset)[1]) stop("w must have the same length as dim(dataset)[1]") } if(length(w)==1){ if(!w %in% c("even", "bycover")) stop("w must be specified, either as 'even' or 'bycover' or a numeric vector") if(w=="bycover") w1 <- rowSums(x)/sum(x) if(w=="even"){ w1 <- rep(1/dim(x)[1], dim(x)[1]) x <- x/rowSums(x) } } ifelse(q1 != 1, res[[qq]]$alpha[k] <- (sum(w1*(renyi(x, scale=q1, hill=T)^(1-q1))))^(1/(1-q1)), res[[qq]]$alpha[k] <- exp(sum(w1*diversity(x))) ) res[[qq]]$gamma[k] <- renyi(colSums(x), scale=q1, hill=T) # res[[qq]]$gamma[k] <- renyi(colSums( w1*(x/rowSums(x)) ), scale=q1, hill=T) res[[qq]]$beta[k] <- res[[qq]]$gamma[k]/res[[qq]]$alpha[k] } } names(res) <- paste("q=",q, sep="") if(length(levels(factor))==1){ res <- t(matrix((unlist(res)), nrow=3, ncol=length(q))) colnames(res) <- c("alpha", "beta", "gamma") rownames(res) <- paste(rep("q=", length(q)), q, sep="") } return(res) }