distr = function(type,param,pool_size) { # This function generates some abundance distributions # It returns proportions of abundances no_rep = 100; # constant #type = 1 geometric (param is the proportion of neighbouring species) # = 2 lognormal (param is the standard deviation) # = 3 Tokeshi power fraction # = 4 broken stick (fully random) if (type == 1) { #geometric abund = NULL abund[1]= param; for (i in 2:pool_size) abund[i] = abund[i - 1] * param } if (type == 2) { #lognormal xabund=NULL abund=rep(0,pool_size) for (k in 1:no_rep) { for (i in 1:pool_size) { sd = rnorm(1); xabund[i] = exp(param * sd); } xabund = sort(xabund, decreasing=T) abund = abund + xabund } abund = abund / no_rep; } if (type == 3) { #broken stick abund=rep(0,pool_size) for (k in 1:no_rep) { xabund = 1 for (i in 1:(pool_size-1)) { s=length(xabund) r=ceiling(s * runif(1)) r1=runif(1); xabund[r] = xabund[r] * r1 xabund=c(xabund, xabund[r] * (1-r1)) } xabund = sort(xabund, decreasing=T) abund = abund + xabund } abund = abund / no_rep } if (type ==4) { #random abund=rep(0,pool_size) for (k in 1:no_rep) { xabund = runif(pool_size); xabund = sort(xabund, decreasing=T) abund = abund + xabund; } abund = abund / no_rep; } abund=abund/sum(abund) #n=cumsum(abund); abund }