Hi,everyone. I use the following program calculates Fisher's alpha from counts of individuals and species. The program is wrote by Prof. Kyle Harm. However, when I run the program, it can work very quickly sometimes, but it can not work very well sometimes. It depends on the counts of individuals and species. For example,
> calc.alpha(1000,70) [1] 17.14375 > calc.alpha(10000,70) [1] 10.15460 > calc.alpha(100,7) [1] 1.714375 But, > calc.alpha(1580,30) > calc.alpha(1000,7) It is very slow. So, what is the problem? Thanks very much. Jian Zhang # The following function calculates Fisher's alpha from counts of individuals and species. # Note that this program assumes that the true value of alpha lies within the range 0.001¨C10000 # (a likely assumption for local assemblages of organisms). # The function returns "-1" if there is a problem. calc.alpha=function(n.orig, s.orig) { a=numeric() len.n=length(n.orig) len.s=length(s.orig) if(len.n != len.s) { return(-1) } for(i in 1:len.n) { if(n.orig[i]<=0 | s.orig[i]<=0 | n.orig[i]<=s.orig[i]) { a[i]=(-1) } else { low.a=0.001 high.a=10000 low.s = low.a*log(1+(n.orig[i]/low.a)) high.s = high.a*log(1+(n.orig[i]/high.a)) if((s.orig[i]<=low.s) | (s.orig[i]>=high.s)) { a[i]=(-1) } else { use.s=s.orig[i]+1 while(s.orig[i] != use.s) { use.a=(low.a+high.a)/2 use.s=use.a*log(1+(n.orig[i]/use.a)) if(s.orig[i]<use.s) { high.a=use.a } if(s.orig[i]>use.s) { low.a=use.a } } a[i]=use.a } } } return(a) } [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.