Learn R Programming

EasyABC (version 1.0)

ABC_rejection: Rejection sampling scheme for ABC

Description

This function launches a series of nb_simul model simulations with model parameters drawn in the prior distribution specified in prior_matrix.

Usage

ABC_rejection(model, prior_matrix, nb_simul, use_seed = TRUE, seed_count = 0, n_cluster=1, progress_bar=FALSE)

Arguments

model
a R function implementing the model to be simulated. It must take as arguments an array containing a seed value (if use_seed=TRUE) and the model parameters and returning an array of summary statistics obtained at the end of the s
prior_matrix
a matrix or data frame containing the ranges of the prior distribution for each of the $p$ model parameters. It has $p$ lines and 2 columns. The first (second) column contains the lower (upper) bound of the prior distribution of the $p$ parameters.
nb_simul
a positive integer equal to the desired number of simulations of the model.
use_seed
logical. If TRUE (default), ABC_rejection provides as input to the function model an array containing an integer seed value and the model parameters used for the simulation. The seed value should be used by
seed_count
a positive integer, the initial seed value provided to the function model (if use_seed=TRUE). This value is incremented by 1 at each call of the function model.
n_cluster
a positive integer. If larger than 1 (the default value), ABC_rejection will launch model simulations in parallel on n_cluster cores of the computer.
progress_bar
logical, FALSE by default. If TRUE, ABC_rejection will output a bar of progression with the estimated remaining computing time. Option not available with multiple cores.

Value

  • The returned value is a list containing the following components:
  • paramThe model parameters used in the model simulations.
  • statsThe summary statistics obtained at the end of the model simulations.
  • weightsThe weights of the different model simulations. In the standard rejection scheme, all model simulations have the same weights.
  • stats_normalizationThe standard deviation of the summary statistics across the model simulations.
  • nsimThe number of model simulations performed.
  • computimeThe computing time to perform the simulations.

References

Pritchard, J.K., and M.T. Seielstad and A. Perez-Lezaun and M.W. Feldman (1999) Population growth of human Y chromosomes: a study of Y chromosome microsatellites. Molecular Biology and Evolution, 16, 1791--1798.

See Also

binary_model, binary_model_cluster, ABC_sequential, ABC_mcmc

Examples

Run this code
## artificial example to show how to use the ABC_rejection function
    set.seed(1)
    n=10
    priormatrix=cbind(c(500,3,-2.3,1,-25,-0.7),c(500,5,1.6,1,125,3.2))
    priormatrix
    ABC_rej<-ABC_rejection(model=trait_model, prior_matrix=priormatrix, nb_simul=n, n_cluster=1, progress_bar=FALSE)
    ABC_rej

    ## To use the ABC_rejection function with multiple cores, simply change the value of n_cluster:
    ABC_rejb<-ABC_rejection(model=trait_model, prior_matrix=priormatrix, nb_simul=n, n_cluster=2, progress_bar=FALSE)

Run the code above in your browser using DataLab