# NOT RUN {
data(finch.ind)
# }
# NOT RUN {
#Define the functions that will be calculating
funct<-c("mean(x, na.rm = TRUE)", "kurtosis(x, na.rm = TRUE)",
"max(x, na.rm = TRUE) - min(x, na.rm = TRUE)" )
#Test against the null model regional.ind
res.finch.sp_regional.ind<-ComIndex(traits = traits.finch, index = funct, sp = sp.finch,
nullmodels = "regional.ind", ind.plot = ind.plot.finch,
nperm = 9, print = FALSE)
#Test against the null model regional.pop
#Individuals values are transformed in populational values
res.finch.sp_regional.pop<-ComIndex(traits = traits.finch, index = funct, sp = sp.finch,
nullmodels = "regional.pop", ind.plot = ind.plot.finch,
nperm = 9, print = FALSE)
#We can calculate index with or without intraspecific variance.
#calculate of means by population (name_sp_site is a name of a population)
#determine the site for each population (sites_bypop)
name_sp_sites = paste(sp.finch, ind.plot.finch,sep = "_")
traits.by.pop<-apply(traits.finch, 2 ,
function (x) tapply(x, name_sp_sites, mean, na.rm = TRUE))
sites_bypop<-lapply(strsplit(paste(rownames(traits.by.pop), sep = "_"), split = "_"),
function(x) x[3])
#New list of function "funct"
funct.1<-c("tapply(x, ind.plot.finch, function(x) mean(x, na.rm = TRUE))",
"tapply(x, ind.plot.finch, function(x) kurtosis(x, na.rm = TRUE))",
"tapply(x, ind.plot.finch, function(x) max(x, na.rm = TRUE)-min(x, na.rm = TRUE))",
"tapply(x, ind.plot.finch, function(x) CVNND(x, na.rm = TRUE))" )
fact<-unlist(sites_bypop)
funct.2<-c("tapply(x, fact, function(x) mean(x, na.rm = TRUE))",
"tapply(x, fact, function(x) kurtosis(x, na.rm = TRUE))",
"tapply(x, fact, function(x) max(x, na.rm = TRUE)-min(x, na.rm = TRUE))",
"tapply(x, fact, function(x) CVNND(x, na.rm = TRUE))")
res.finch.withIV<-ComIndex(traits = traits.finch, index = funct.1,
sp = sp.finch, nullmodels = "regional.ind",
ind.plot = ind.plot.finch, nperm = 9, print = FALSE)
res.finch.withoutIV<-ComIndex(traits = traits.finch, index = funct.2,
sp = sp.finch, nullmodels = "regional.pop",
ind.plot = ind.plot.finch, nperm = 9, print = FALSE)
#ComIndex class are associated to S3 methods plot, print and summary.
res.finch.withIV
summary(res.finch.withIV)
plot(res.finch.withIV)
plot(res.finch.withoutIV)
plot(as.listofindex(list(res.finch.withIV, res.finch.withoutIV)))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab