R/wITV.R

Defines functions wITV

#' @export
wITV <- function(spIDs, traitVals, relAbund){
  spIDs <- as.character(spIDs)
  pij <- relAbund
  Nij <- table(spIDs)
  tij <- tapply(traitVals, spIDs, mean)
  tijInd <- rep(tij, times=Nij)
  varIndiv <- (traitVals - tijInd)^2
  varWithin <- tapply(varIndiv, spIDs, sum)
  varWithinWeighted <- (pij / Nij) * varWithin
  sumvarWithinWeighted <- sum(varWithinWeighted)
  varBetween <- (tij -  sum(pij*tij) )^2
  varBetweenWeighted <- pij * varBetween
  sumvarBetweenWeighted <- sum(varBetweenWeighted)
  wITV<- (sumvarWithinWeighted)/(sumvarBetweenWeighted + sumvarWithinWeighted)
  return(wITV)
}
paternogbc/ecodados documentation built on May 8, 2022, 4:19 a.m.