# NOT RUN {
data(finch.ind)
# }
# NOT RUN {
#For most multivariate functions we need to replace (or exclude) NA values. 
#For this example, we use the package mice to complete the data.
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 ComIndexMulti
n_sp_plot<-as.factor(paste(sp.finch, ind.plot.finch, sep = "_")) 
res.sum.1<-ComIndexMulti(traits.finch, 
              index = c("sum(scale(x), na.rm = T)", "sum(x, na.rm = T)"), 
              by.factor = n_sp_plot, nullmodels = "regional.ind", 
              ind.plot = ind.plot.finch, nperm = 9, sp = sp.finch)
res.sum.1
#A more interesting example using the function hypervolume
library(hypervolume)
hv<-hypervolume(traits.finch.mice, 
        reps = 100,bandwidth = 0.2, 
        verbose = F, warnings = F)
plot(hv)
hv.1<-ComIndexMulti(traits.finch.mice, 
             index = c("as.numeric(try(hypervolume(na.omit(x), reps = 100, 
                 bandwidth = 0.2, verbose = F, warnings = F)@Volume))"),
             by.factor = rep(1,length(n_sp_plot)), nullmodels = "regional.ind",
             ind.plot = ind.plot.finch, nperm = 9, sp = sp.finch) 
hv.1
# }
Run the code above in your browser using DataLab