Description Usage Arguments Value Author(s) References See Also Examples

View source: R/EasyABC-internal.R View source: R/ABC_rejection.R

This function launches a series of `nb_simul`

model simulations with model parameters drawn in the prior distribution specified in `prior_matrix`

.

1 2 |

`model` |
a |

`prior` |
a list of prior information. Each element of the list corresponds to a model parameter. The list element must be a vector whose first argument determines the type of prior distribution: possible values are |

`nb_simul` |
a positive integer equal to the desired number of simulations of the model. |

`prior_test` |
a string expressing the constraints between model parameters.
This expression will be evaluated as a logical expression, you can use all the logical operators including |

`summary_stat_target` |
a vector containing the targeted (observed) summary statistics.
If not provided, |

`tol` |
tolerance, a strictly positive number (between 0 and 1) indicating the proportion of simulations retained nearest the targeted summary statistics. |

`use_seed` |
logical. If |

`seed_count` |
a positive integer, the initial seed value provided to the function |

`n_cluster` |
a positive integer. If larger than 1 (the default value), |

`verbose` |
logical. |

`progress_bar` |
logical, |

The returned value is a list containing the following components:

`param` |
The model parameters used in the |

`stats` |
The summary statistics obtained at the end of the |

`weights` |
The weights of the different |

`stats_normalization` |
The standard deviation of the summary statistics across the |

`nsim` |
The number of |

`nrec` |
The number of retained simulations (if targeted summary statistics are provided). |

`computime` |
The computing time to perform the simulations. |

Franck Jabot, Thierry Faure and Nicolas Dumoulin

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.

`binary_model`

, `binary_model_cluster`

, `ABC_sequential`

, `ABC_mcmc`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | ```
##### EXAMPLE 1 #####
#####################
set.seed(1)
## artificial example to show how to use the 'ABC_rejection' function.
## defining a simple toy model:
toy_model<-function(x){ 2 * x + 5 + rnorm(1,0,0.1) }
## define prior information
toy_prior=list(c("unif",0,1)) # a uniform prior distribution between 0 and 1
## only launching simulations with parameters drawn in the prior distributions
set.seed(1)
n=10
ABC_sim<-ABC_rejection(model=toy_model, prior=toy_prior, nb_simul=n)
ABC_sim
## launching simulations with parameters drawn in the prior distributions
# and performing the rejection step
sum_stat_obs=6.5
tolerance=0.2
ABC_rej<-ABC_rejection(model=toy_model, prior=toy_prior, nb_simul=n,
summary_stat_target=sum_stat_obs, tol=tolerance)
## NB: see the package's vignette to see how to pipeline 'ABC_rejection' with the function
# 'abc' of the package 'abc' to perform other rejection schemes.
## Not run:
##### EXAMPLE 2 #####
#####################
## this time, the model has two parameters and outputs two summary statistics.
## defining a simple toy model:
toy_model2<-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_prior2=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.
## only launching simulations with parameters drawn in the prior distributions
set.seed(1)
n=10
ABC_sim<-ABC_rejection(model=toy_model2, prior=toy_prior2, nb_simul=n)
ABC_sim
## launching simulations with parameters drawn in the prior distributions
# and performing the rejection step
sum_stat_obs2=c(1.5,0.5)
tolerance=0.2
ABC_rej<-ABC_rejection(model=toy_model2, prior=toy_prior2, nb_simul=n,
summary_stat_target=sum_stat_obs2, tol=tolerance)
## NB: see the package's vignette to see how to pipeline 'ABC_rejection' with the function
# 'abc' of the package 'abc' to perform other rejection schemes.
##### EXAMPLE 3 #####
#####################
## this time, the model is a C++ function packed into a R function -- this time, the option
# 'use_seed' must be turned to TRUE.
n=10
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
## only launching simulations with parameters drawn in the prior distributions
ABC_sim<-ABC_rejection(model=trait_model, prior=trait_prior, nb_simul=n, use_seed=TRUE)
ABC_sim
## launching simulations with parameters drawn in the prior distributions and performing
# the rejection step
sum_stat_obs=c(100,2.5,20,30000)
tolerance=0.2
ABC_rej<-ABC_rejection(model=trait_model, prior=trait_prior, nb_simul=n,
summary_stat_target=sum_stat_obs, tol=tolerance, use_seed=TRUE)
## NB: see the package's vignette to see how to pipeline 'ABC_rejection' with the function
# 'abc' of the package 'abc' to perform other rejection schemes.
##### EXAMPLE 4 - Parallel implementations #####
################################################
## NB: the option use_seed must be turned to TRUE.
## For models already running with the option use_seed=TRUE, simply change
# the value of n_cluster:
sum_stat_obs=c(100,2.5,20,30000)
ABC_simb<-ABC_rejection(model=trait_model, prior=trait_prior, nb_simul=n,
use_seed=TRUE, n_cluster=2)
## For other models, change the value of n_cluster and modify the model so that the first
# parameter becomes a seed information value:
toy_model_parallel<-function(x){
set.seed(x[1])
2 * x[2] + 5 + rnorm(1,0,0.1) }
sum_stat_obs=6.5
ABC_simb<-ABC_rejection(model=toy_model_parallel, prior=toy_prior, nb_simul=n,
use_seed=TRUE, n_cluster=2)
## End(Not run)
``` |

YunlongNie/ABCBen documentation built on June 3, 2017, 10:46 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.