ShanKothari / DecomposingFD

Code to calculate functional trait diversity as defined by Scheiner et al. (2016), and its decomposition into richness, evenness, and dispersion.
8 stars 5 forks source link

No outputs when running FTD.comm #6

Closed nikhailarum closed 6 years ago

nikhailarum commented 6 years ago

Hello Mr. Kothari

I have recently tried using the code you developed for calculating functional diversity across multiple communities. In using the FTD.comm function on my datasets I get no outputs. I have specified my trait distance matrix as tdmat and my site by species matrix as spmat with species names as columns for my site by species matrix. My tdmat object is a distance matrix and spmat is a data matrix. They read correctly into R, however when I run the FTD.comm function I get no outputs or error message, and FTD.comm is just listed as a function.

I am using the unedited code from your github page, which reads as:

`function(tdmat,spmat,q=1,abund=F,match.names=T){

if(abund==F){ spmat[spmat>0]<- 1 spmat<-spmat/rowSums(spmat) }

n.comm<-nrow(spmat) if(match.names==T){ sp.arr<-match(rownames(as.matrix(tdmat)),colnames(spmat)) spmat<-spmat[,sp.arr] }

apply FTD to each community in turn

out<-apply(spmat,1,function(x) unlist(FTD(tdmat=tdmat,weights=x,q=q))) df.out<-data.frame(t(out)) rownames(df.out)<-rownames(spmat)

warning for zero-species communities

if(sum(df.out$nsp==0)>0){ warning("at least one community has no species") }

nsp<-sum(colSums(spmat>0))

calculate mean richness, dispersion, evenness, FTD

u.M<-sum(df.out$nsp*df.out$M)/sum(df.out$nsp) u.nsp<-mean(df.out$nsp)

to do: check if u.nsp is always calculated as arithmetic mean

if(q==1){

geometric mean -- limit of generalized mean as q->1

u.qDT<-prod(df.out$qDT)^(1/n.comm)

} else {

generalized mean with m=1-q

u.qDT<-(sum(df.out$qDT^(1-q))/n.comm)^(1/(1-q))

} u.M.prime<-u.M*u.nsp/(u.nsp-1)

calculate mean FTD and evenness

u.qDTM<-1+u.qDT*u.M u.Et<-u.qDT/u.nsp

list more things

list(com.FTD=df.out,nsp=nsp,u.nsp=u.nsp,u.M=u.M,u.M.prime=u.M.prime,u.Et=u.Et,u.qDT=u.qDT,u.qDTM=u.qDTM) }`

My trait distance matrices and site by species matrices are stored as .txt files, however they read into R without any issues. I understand the trait distance matrices have to have all species present, but does this mean that all species must be present as columns in the same order as the site by species matrix? I ask this as this would make the last column redundant, as well as the first row ie. if a sample has 25 species then the trait distance matrix should have 25 rows and 25 columns? My tdmat has 25 species, but 24 columns and 24 rows. Is this the reason I am getting no outputs? I am struggling to understand why I get no outputs, yet no error messages either. Any help with this issue would be greatly appreciated. If needed I can upload examples of my trait distance matrix and my site by species matrix for you to view if needed.

Regards Nikhail

ShanKothari commented 6 years ago

Redundant with previous issue (#5)?