Description Usage Arguments Value Slots Examples
The S4 class contains the simulation and summary statistics
function and other necessary arguments for a model to run in the main
bsl
function.
newModel
is the constructor function for a MODEL
object.
simulation
runs a number of simulations and computes the
correponding summary statistics with the provided model.
summStat
computes the summary statistics with the given data and model object.
The summary statistics function and relevant arguments are obtained from the model.
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 | newModel(
fnSim,
fnSimVec,
fnSum,
fnLogPrior,
simArgs,
sumArgs,
theta0,
thetaNames,
test = TRUE,
verbose = TRUE
)
## S4 method for signature 'MODEL'
simulation(
model,
n = 1,
theta = model@theta0,
summStat = TRUE,
parallel = FALSE,
parallelArgs = NULL,
seed = NULL
)
## S4 method for signature 'ANY,MODEL'
summStat(x, model)
|
fnSim |
A function that simulates data for a given parameter
value. The first argument should be the parameters. Other necessary
arguments (optional) can be specified with |
fnSimVec |
A vectorised function that simulates a number of
datasets simultaneously for a given parameter value. The first two
arguments should be the number of simulations to run and parameters,
respectively. Other necessary arguments (optional) can be specified with
|
fnSum |
A function for computing summary statistics of data. The
first argument should be the observed or simulated dataset. Other necessary
arguments (optional) can be specified with |
fnLogPrior |
A function that computes the log of prior density for a parameter. If this is missing, the prior by default is an improper flat prior over the real line for each parameter. The function must have a single input: a vector of parameter values. |
simArgs |
A list of additional arguments to pass into the simulation
function. Only use when the input |
sumArgs |
A list of additional arguments to pass into the summary
statistics function. Only use when the input |
theta0 |
Initial guess of the parameter value. |
thetaNames |
A string vector of parameter names, which must have the same length as the parameter vector. |
test |
Logical, whether a short simulation test will be ran upon initialisation. |
verbose |
Logical, whether to print verbose messages when initialising a “MODEL” object. |
model |
A “MODEL” class object. |
n |
The number of simulations to run. |
theta |
The parameter value. |
summStat |
Logical indicator whether the correpsonding summary statistics
should be returned or not. The default is |
parallel |
A logical value indicating whether parallel computing should
be used for simulation and summary statistic evaluation. The default is
|
parallelArgs |
A list of additional arguments to pass into the
|
seed |
A seed number to pass to the |
x |
The data to pass to the summary statistics function. |
A list of simulation results using the given parameter. x
contains the raw simulated datasets. ssx
contains the summary
statistics.
A vector of the summary statistics.
fnSim
A function that simulates data for a given parameter value. The
first argument should be the parameters. Other necessary arguments
(optional) can be specified with simArgs
.
fnSimVec
A vectorised function that simulates a number of datasets
simultaneously for a given parameter value. If this is not NULL
,
vectorised simulation function will be used instead of fnSim
. The
first two arguments should be the number of simulations to run and
parameters, respectively. Other necessary arguments (optional) can be
specified with simArgs
. The output must be a list of each simulation
result.
fnSum
A function for computing summary statistics of data. The first
argument should be the observed or simulated dataset. Other necessary
arguments (optional) can be specified with sumArgs
. The users should
code this function carefully so the output have fixed length and never
contain any Inf
value.
fnLogPrior
A function that computes the log of prior density for a
parameter. The default is NULL
, which uses an improper flat prior
over the real line for each parameter. The function must have a single
input: a vector of parameter values.
simArgs
A list of additional arguments to pass into the simulation
function. Only use when the input fnSim
or fnSimVec
requires
additional arguments. The default is NULL
.
sumArgs
A list of additional arguments to pass into the summary
statistics function. Only use when the input fnSum
requires
additional arguments. The default is NULL
.
theta0
Initial guess of the parameter value, which is used as the starting value for MCMC.
thetaNames
Expression, parameter names.
ns
The number of summary statistics of a single observation. Note this will be generated automatically, thus is not required for initialisation.
test
Logical, whether a short simulation test will be ran upon initialisation.
verbose
Logical, whether to print verbose messages when initialising a “MODEL” object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # set up the model for the ma2 example
data(ma2)
m <- newModel(fnSim = ma2_sim, fnSum = ma2_sum, simArgs = ma2$sim_args,
theta0 = ma2$start, fnLogPrior = ma2_prior, verbose = FALSE)
validObject(m)
# benchmark the serial and vectorised simulation function (require the rbenchmark package)
m1 <- newModel(fnSim = ma2_sim, fnSum = ma2_sum, simArgs = ma2$sim_args,
theta0 = ma2$start, fnLogPrior = ma2_prior)
m2 <- newModel(fnSimVec = ma2_sim_vec, fnSum = ma2_sum, simArgs = ma2$sim_args,
theta0 = ma2$start, fnLogPrior = ma2_prior)
require("rbenchmark")
## Not run:
benchmark(serial = simulation(m1, n = 1000, theta = c(0.6, 0.2)),
vectorised = simulation(m2, n = 1000, theta = c(0.6, 0.2)))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.