# power_TL.dN # Written by David Galván # 09/30/2009 # Centro Nacional Patagónico. Boulevard Brown s/n, (U9120ACV) Puerto Madryn, Chubut, Argentina # galvan@cenpat.edu.ar #DESCRIPTION #Function to estimate the minimum sample size required to analyze size based feeding trends using d15N data sets. # power_TL.dN(ZB=0.842, ZA=1.645, sd.r=0.3, TLmin=11, TLmax=90, r.sample=100000, slope= 0.01) ##ARGUMENTS #ZB: value of Z 1-b (default value= Z 1-b for 80% power) #ZA: value of Z 1-a (default value= Z 1-a for 95% confidence) #sd.r: standard deviation of d15N. By default it is assumed sd for constant diet (Sweeting et al. 2005) #TLmin: Minimum length (TL) expressed as a percentage of the species' maximum length (Lmax) #TLmax: Maximum length (TL) expressed as a percentage of the Lmax #r.sample: size of the simulated population (default value= 100000) #slope: minimum change in Trophic Position (TP) accepted as ecologically significant. It corresponds to the slope of linear equation TL= slope*d15N. Default value of slope=0.01, a 1/4 increase in TP over 80% of Lmax, when trophic fractionation is 3.2 (Sweeting et al. 2007) ##DETAILS #The function estimates the minimum sample size for increasing TL ranges from TLmin to TLmax,to achieve the power specified by ZB under the assumptions ZA, Sd.R and slope. #The function first simulates a random data set of TL from a uniform distribution. The d15N(x) values are estimated from the model TL= slope*d15N with errors normally distributed (mean=0, sd=sd.r). #Then the function fit a linear model y~x and extract its correlation coefficient (r.squared) #The minimum sample size was estimated using the equation n=-3+(2*(ZB+ZA)/(log((1+r)/(1-r))))^2 (Díaz & Fernández 2002). ##VALUE #The function returns a four column object of class data.frame: #dTL: a column with TL ranges from TLmin to TLmax #n: indicates the minimum sample size required to achieve the power specified by ZB under the assumptions ZA, Sd.R and slope if the sampling covers a TL range= dTL #sd: the standard deviation of the simulated data set (i.e. uncertainty sources in the dN data set + TrL change #r2: the correlation coefficient of the relationship Y= b*X #Finally, the function returns a plot of the minimum sample size vs the TL range sampled. ########################################### power_TL.dN<-function (ZB=0.842, ZA=1.645, sd.r=0.3, TLmin=11, TLmax=90, r.sample=100000, slope= 0.01) { #first create a matrix to store data from Lmin=10% to Lmax=90% Lmax=90 Lmin=10 n.r<-matrix(0,Lmax-(Lmin-1),4) n.r<-as.data.frame(n.r) colnames(n.r)<-c("n","sd","r2","dTL") #the loop estimates the minimum n for increasing TL ranges (TLmin to TLmax) #to do this the function simulate data sets for increasing TL ranges (1%) for (i in Lmin:Lmax) { x<-runif(r.sample,1,i+1) y<-(slope*x)+rnorm(r.sample,mean=0,sd=sd.r) x<-as.integer(x) trend<-lm(y~x) s<-summary(trend) r<-sqrt(s$r.squared) n.r$r2[i-(Lmin-1)]<-s$r.squared n.r$n[i-(Lmin-1)]<-3+(2*(ZB+ZA)/(log((1+r)/(1-r))))^2 n.r$dTL[i-(Lmin-1)]<-i n.r$sd[i-(Lmin-1)]<-sd(y) } #to plot the relationship between minimum sample size and %TL covered plot(c(0,100),c(0,100), main= "Sample size vs Length range", xlab="%TL range",ylab="minimum N", type="n") points(n.r$dTL,n.r$n,pch=19,col=1) abline (v=(TLmax-TLmin), col="red") n.r } ############################################