data(finch.ind)
####
#For most multivariate functions we need to replace (or exclude)
#NA values.
#For this example, we use the package mice to complete the data.
names.sp_ind_plot<-as.factor(paste(sp.finch, ind.plot.finch, sep="_"))
comm<-t(table(ind.plot.finch,1:length(ind.plot.finch)))
library(mice)
traits=traits.finch
mice<-mice(traits.finch)
traits.finch.mice<-complete(mice)
####
#A simple example to illustrate the concept of the function
#com.index.multi
res.sum.1<-com.index.multi(traits.finch,
index=c("sum(scale(x), na.rm=TRUE)", "sum(x, na.rm=TRUE)"),
by.factor=names.sp_ind_plot, nullmodels=c(2,2),
ind.plot=ind.plot.finch, nperm=50, sp=sp.finch)
attributes(ses.listofindex(as.listofindex(res.sum.1)))
####
#A more interesting example using the function hypervolume
#from the package hypervolume.
#We show here several results which differe in there factor
#that delimit the group to calculate different hypervolume
#(argument by_factor).
require(hypervolume)
res.hv.1<-com.index.multi(traits.finch.mice, index=c("as.numeric
(try(hypervolume(na.omit(x), reps=100, bandwidth=0.2, verbose=FALSE,
warnings=FALSE)@Volume))"), by.factor=rep(1,length(names.sp_ind_plot)),
nullmodels=c(2,2), ind.plot=ind.plot.finch, nperm=9, sp=sp.finch)
res.hv.2<-com.index.multi(traits.finch.mice, index=c("as.numeric
(try(hypervolume(na.omit(x), reps=100, bandwidth=0.2, verbose=FALSE,
warnings=FALSE)@Volume))"), by.factor=names.sp_ind_plot,
nullmodels=c(2,2), ind.plot=ind.plot.finch, nperm=9, sp=sp.finch)
res.hv.3<-com.index.multi(traits.finch.mice, index=c("as.numeric
(try(hypervolume(na.omit(x), reps=100, bandwidth=0.2, verbose=FALSE,
warnings=FALSE)@Volume))"), by.factor=ind.plot.finch,
nullmodels=c(2,2), ind.plot=ind.plot.finch, nperm=9, sp=sp.finch)
res.hv.4<-com.index.multi(traits.finch.mice, index=c("as.numeric
(try(hypervolume(na.omit(x), reps=100, bandwidth=0.2, verbose=FALSE,
warnings=FALSE)@Volume))"), by.factor=sp.finch,
nullmodels=c(2,2), ind.plot=ind.plot.finch, nperm=9, sp=sp.finch)
list.ind.multi<-as.listofindex(list(res.hv.2, res.hv.3, res.hv.4))
ses.listofindex(list.ind.multi)
plot(list.ind.multi)
plot(list.ind.multi, xlim=c(-200,20))
Run the code above in your browser using DataLab