# Hellinger transformation # First calculate the total species abundances by site (site.totals=apply(spe, 1, sum)) # Scale species abundances by dividing them by site totals (scale.spe<-spe/site.totals) # Calculate the square root of scaled species abundances (sqrt.scale.spe<-sqrt(scale.spe)) # Compare the results sqrt.scale.spe spe.hel sqrt.scale.spe-spe.hel # or: sqrt.scale.spe/spe.hel # Chi-square transformation # First calculate the total species abundances by site (site.totals<-apply(spe, 1, sum)) # Then calculate the square root of total species abundances (sqrt.spe.totals<-sqrt(apply(spe, 2, sum))) # Scale species abundances by dividing them by the site totals and the species totals scale.spe2<-spe for (i in 1:nrow(spe)) { for (j in 1:ncol(spe)) { (scale.spe2[i,j]=scale.spe2[i,j]/(site.totals[i]*sqrt.spe.totals[j])) }} #Adjust the scale abundance species by multiplying by the square root of the species matrix total (adjust.scale.spe2<-scale.spe2*sqrt(sum(rowSums(spe)))) # Compare the results adjust.scale.spe2 spe.chi adjust.scale.spe2-spe.chi # or: adjust.scale.spe2/spe.chi