coalesc_abc {ecolottery}R Documentation

Estimation of neutral and non-neutral parameters of community assembly using Approximate Bayesian Computation (ABC)


Estimates parameters of neutral migration-drift dynamics (through migration rate m and parameters of environmental filtering (through a filtering function from the composition of a local community and the related regional pool.


  coalesc_abc(comm.obs, pool = NULL, multi = "single", traits = NULL,
              f.sumstats, = NULL, params = NULL, 
              theta.max = NULL, nb.samp = 10^6, parallel = TRUE,
              tol = NULL, pkg = NULL, method="rejection")
  do.simul(J, pool = NULL, multi = "single", = NULL, 
              traits = NULL, f.sumstats = NULL, = NULL,
              params, theta.max = NULL, nb.samp = 10^6, 
              parallel = TRUE, tol = NULL, pkg = NULL,
              method = "rejection")



the observed community composition. If multi = FALSE (default), should be a matrix or data.frame of individuals on rows with their individual id (first column), and species id (second column).


composition of the regional pool to which the local community is hypothesized to be related through migration dynamics with possible environmental filtering. Should be a matrix of individuals on rows with their individual id (first column), species id (second column), and (optionally) the trait values of the individuals.


structure of the community inputs:

  • if multi = "single", comm.obs contains a single community

  • if multi = "tab", the user provides a site-species matrix (sites in rows and species in columns)

  • if multi = "seqcom", comm.obs contains a list of communities


the trait values of species in the regional pool. It is used if trait information is not provided in pool. In this case, intraspecific trait variation is assumed to be null.


a function allowing to calculate the summary statistics of local community composition. Will be used to compare observed and simulated community composition in the ABC estimation. It should take a community as input and output a list of summary statistics.

the hypothesized environmental filtering function. It is a function of individual trait values and additional parameters to be estimated.


a matrix of the bounds of the parameters used in The row names of params provide the parameter names used in ABC calculation and output. First column contains minimum values and second column contains maximum values.


if pool = NULL, regional abundances will be simulated following a log-series distribution. The function will estimate the theta parameter of this distribution. theta.max then provides the upper bound for this estimation.


the number of parameter values to be sampled in ABC calculation. Random values of parameters of environmental filtering (see and params) and of migration (denoted as m) are drawn from a uniform distribution between minimum and maximum values provided in params (and between 0 and 1 for m).


boolean. If parallel = TRUE, the function will perform parallel processing using the parLapply() function of package parallel.


the tolerance value used in ABC estimation (see help in abc() function of package abc for further information).


packages needed for calculation of and/or f.sumstats.


the method to be used in ABC estimation (see help on abc() function of package abc for further information).


local community size.

number of communities.


coalesc_abc() performs ABC estimation for one (if multi = FALSE, default) or several communities (if multi = TRUE) related to the same regional pool.

do.simul() provides the simulated communities used in ABC estimation, and is not intended to be used directly.



parameter values used in simulations.


observed summary statistics.


observed summary statistics standardized according to the mean and standard deviation of simulated values.


standardized summary statistics of the communities simulated with parameter values listed in par.


a single (if multi = FALSE, default) or a list of abc objects including ABC estimation information for each community provided in input (comm.obs).


F. Munoz


Jabot, F., and J. Chave. 2009. Inferring the parameters of the neutral theory of biodiversity using phylogenetic information and implications for tropical forests. Ecology Letters 12:239-248.

Csillery, K., M. G. B. Blum, O. E. Gaggiotti, and O. Francois. 2010. Approximate Bayesian computation (ABC) in practice. Trends in Ecology & Evolution 25:410-418.

Csillery, K., O. Francois, and M. G. Blum. 2012. abc: an R package for Approximate Bayesian Computation (ABC). Methods in Ecology and Evolution 3:475-479.

See Also

abc() in abc package, parLapply() in parallel package.


# Trait-dependent filtering function
filt_gaussian <- function(t, params) exp(-(t-params[1])^2/(2*params[2]^2))

# Definition of parameters and their range
params <- data.frame(rbind(c(0, 1), c(0.05, 1)))
row.names(params) <- c("topt", "sigmaopt")
# Number of values to sample in prior distributions
nb.samp <- 10^6 # Should be large

## Not run: 
# Basic summary statistics
f.sumstats <- function(com) array(dimnames=list(c("cwm", "cwv", "cws",
                                                  "cwk", "S", "Es")),
                                  c(mean(com[,3]), var(com[,3]), 

# An observed community is here simulated (known parameters)
comm <- coalesc(J = 400, m = 0.5, theta = 50,
                filt = function(x) filt_gaussian(x, c(0.2, 0.1)))

# ABC estimation of the parameters based on observed community composition 
## Warning: this function may take a while
res <- coalesc_abc(comm$com, comm$pool, f.sumstats = f.sumstats,
          = filt_gaussian, params = params, 
                   nb.samp = nb.samp, parallel = TRUE, 
                   pkg = c("e1071","vegan"), method = "neuralnet")
plot(res$abc, param = res$par)

# Cross validation
## Warning: this function is slow
res$cv <- abc::cv4abc(param = res$par, sumstat = res$ss, nval = 1000,
                      tols = c(0.01, 0.1, 1), method = "neuralnet")

# Multiple community option
# When the input is a site-species matrix, use argument multi="tab"
# See vignette Barro_Colorado for more details

# When the input is a list of communities, use argument multi="seqcom"
comm.obs <- list()

comm.obs[[1]] <- cbind(rep(1,400), coalesc(J = 400, m = 0.5, filt = function(x)
                                           filt_gaussian(x, c(0.2, 0.1)),
                                           pool = comm$pool)$com))
comm.obs[[2]] <- cbind(rep(2,400), coalesc(J = 400, m = 0.5, filt = function(x) 
                                           filt_gaussian(x, c(0.5, 0.1)),
                                           pool = comm$pool)$com))
comm.obs[[3]] <- cbind(rep(3,400), coalesc(J = 400, m = 0.5, filt = function(x) 
                                           filt_gaussian(x, c(0.8, 0.1)),
                                           pool = comm$pool)$com))

comm.obs <- lapply(comm.obs, as.matrix)

res <- coalesc_abc(comm.obs, comm$pool, multi="seqcom", f.sumstats=f.sumstats,
          = filt_gaussian, params = params, nb.samp = nb.samp,
                   parallel = TRUE, pkg = c("e1071","vegan"), tol = 0.1,
                   method = "neuralnet")
lapply(res$abc, summary)

## End(Not run)

[Package ecolottery version 1.0.0 Index]