simQLdata: Simulate the statistical model

Description Usage Arguments Details Value Author(s) Examples

View source: R/simQLData.R

Description

The function runs simulations of the user-defined statistical model either for a single parameter or a list of parameters.

Usage

1
2
3
simQLdata(sim, ..., nsim, X = NULL, mode = c("list", "matrix", "mean"),
  cl = NULL, iseed = NULL, na.rm = getOption("na.rm", TRUE),
  verbose = FALSE)

Arguments

sim

user supplied simulation function

...

arguments passed to 'sim'

nsim

number of simulation replications at each parameter

X

list or matrix of model parameters

mode

type of return value: "list", "matrix", "mean"

cl

cluster object, NULL (default), of class MPIcluster, SOCKcluster, cluster

iseed

integer seed for initializing the cluster workers

na.rm

whether to remove NA values from simulation results

verbose

if TRUE, then print intermediate output

Details

Basically, the given simulation function 'sim' is called for each parameter value 'nsim' times and the results are returned depending on the chosen type 'mode'.

If 'X' is NULL (default), then the design, that is, the matrix of sample points, is first generated by multiDimLHS and the result is stored as an attribute named 'X'. In this case, the arguments 'N','bounds' and 'method' must be given as named input arguments as required by multiDimLHS. In case of catched errors, the function tries to omit the corresponding simulation runs from the final results if possible.

Depending on the complexity of the model simulations we strongly encourage the use of a cluster object 'cl'. Make sure to export all functions to the cluster environment beforehand which are required by the user-defined simulation function. Also, using the option 'qle.cache' caches results of a function call to be stored in the current working directory. The filename is generated by a hash code using the digest package. Setting an integer seed iseed before stores each result in a separate file and makes the data reproducible while loading the data again.

Value

List of (aggregated) simulation results of class simQL and the following attributes:

X

matrix of sample points (equal to 'X' if supplied) or the result of multiDimLHS

nsim

number of simulation runs at each parameter

iseed

an integer seed value to initialize cluster workers

error

only in case of errors detected in simulation function

Author(s)

M. Baaske

Examples

1
2
3
4
5
# generate design points, simulate and return the sample means
sim <- simQLdata(sim=function(x) rlnorm(1,x[1],x[2]),
         nsim=10,N=8, method="maximinLHS",
         lb=c(-1.5,0),ub=c(2,1), mode="mean") 
  

qle documentation built on May 2, 2019, 9:55 a.m.