###Lande's (1996) scheme for additive partitioning of diversity for a site by species matrix with zeros requires vegan. Sites are columns, with the first column being species names, here is a working example. #dat<-matrix(sample(0:10,100,replace=TRUE),ncol=10) #coms<-c("A1","A2","A3","A4","A5","A6","A7","A8","A9","A10") #spp<-c("SP1","SP2","SP3","SP4","SP5","SP6","SP7","SP8","SP9","SP10") #dat<-data.frame(spp,dat) #names(dat)[2:11]<-coms #addPart(dat,index="richness") #by Marc Cadotte #Oct 2008 addPart<-function (data,index="simpson") { INDICES <- c("shannon", "simpson", "richness") index <- match.arg(index, INDICES) no.spp<-apply(data[,2:ncol(data)],MARGIN=2,sum) q<-no.spp/sum(no.spp) p.bar<-apply(data[,2:ncol(data)], MARGIN=1,sum)/sum( apply(data[,2:ncol(data)], MARGIN=1,sum)) if (index == "simpson") { alph<-diversity(data[,2:ncol(data)], index="simpson",MARGIN=2) lmbd<-1-alph d.sqr<-sum(q*lmbd)-sum(p.bar^2) D.bar<-sum(alph*q) Dt<-d.sqr+D.bar return(rbind(D.bar,d.sqr,Dt)) } if (index == "shannon") { alph<-diversity(data[,2:ncol(data)], index="shannon",MARGIN=2) H.bar<-sum(alph*q) H.among<--sum(p.bar*log(p.bar))-sum(q*alph) Ht<-H.bar+H.among return(rbind(H.bar,H.among,Ht)) } if (index == "richness") { for (i in 2:ncol(data)) { for (j in 1:nrow(data)) { if (data[j,i] > 1) data[j,i]=1 } } alph<-apply(data[,2:ncol(data)], MARGIN=2,sum) S.bar<-sum(alph*q) St<-nrow(data) S.among<-St-S.bar return(rbind(S.bar,S.among,St)) } }