#' @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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.