if (FALSE) {
##### EXAMPLE 1 #####
#####################
## the model has two parameters and outputs two summary statistics.
## defining a simple toy model:
toy_model<-function(x){ c( x[1] + x[2] + rnorm(1,0,0.1) , x[1] * x[2] + rnorm(1,0,0.1) ) }
## define prior information
toy_prior=list(c("unif",0,1),c("normal",1,2))
# a uniform prior distribution between 0 and 1 for parameter 1, and a normal distribution
# of mean 1 and standard deviation of 2 for parameter 2.
## define the targeted summary statistics
sum_stat_obs=c(1.5,0.5)
## to perform the Marjoram et al. (2003)'s method:
##
ABC_Marjoram_original<-ABC_mcmc(method="Marjoram_original", model=toy_model, prior=toy_prior,
summary_stat_target=sum_stat_obs)
ABC_Marjoram_original
## artificial example to perform the Marjoram et al. (2003)'s method, with modifications
# drawn from Wegmann et al. (2009) without Box-Cox and PLS transformations.
##
ABC_Marjoram<-ABC_mcmc(method="Marjoram", model=toy_model, prior=toy_prior,
summary_stat_target=sum_stat_obs)
ABC_Marjoram
## artificial example to perform the Wegmann et al. (2009)'s method.
##
ABC_Wegmann<-ABC_mcmc(method="Wegmann", model=toy_model, prior=toy_prior,
summary_stat_target=sum_stat_obs)
ABC_Wegmann
##### EXAMPLE 2 #####
#####################
## this time, the model is a C++ function packed into a R function -- this time,
# the option 'use_seed' must be turned to TRUE.
## define prior information
trait_prior=list(c("unif",3,5),c("unif",-2.3,1.6),c("unif",-25,125),c("unif",-0.7,3.2))
trait_prior
## define the targeted summary statistics
sum_stat_obs=c(100,2.5,20,30000)
## artificial example to perform the Marjoram et al. (2003)'s method.
##
n=10
ABC_Marjoram_original<-ABC_mcmc(method="Marjoram_original", model=trait_model,
prior=trait_prior, summary_stat_target=sum_stat_obs, n_rec=n, use_seed=TRUE)
ABC_Marjoram_original
## artificial example to perform the Marjoram et al. (2003)'s method, with modifications
# drawn from Wegmann et al. (2009) without Box-Cox and PLS transformations.
##
n=10
n_calib=10
tol_quant=0.2
ABC_Marjoram<-ABC_mcmc(method="Marjoram", model=trait_model, prior=trait_prior,
summary_stat_target=sum_stat_obs, n_rec=n, n_calibration=n_calib,
tolerance_quantile=tol_quant, use_seed=TRUE)
ABC_Marjoram
## artificial example to perform the Wegmann et al. (2009)'s method.
##
n=10
n_calib=10
tol_quant=0.2
ABC_Wegmann<-ABC_mcmc(method="Wegmann", model=trait_model, prior=trait_prior,
summary_stat_target=sum_stat_obs, n_rec=n, n_calibration=n_calib,
tolerance_quantile=tol_quant, use_seed=TRUE)
ABC_Wegmann
}
Run the code above in your browser using DataLab