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

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'. This is either a list or a matrix as the outcome of function 'sim' or the mean of 'nsim' simulation replications at each parameter.

If 'X' equals NULL (default), then the design, that is, the matrix of sample points, is first generated by function 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 which are then passed to multiDimLHS. In case of errors catched, the corresponding simulation runs are omitted from the results if possible.

We recommend using a cluster object 'cl' depending on the complexity of model simulations. If using a cluster 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") 
  

mbaaske/qle documentation built on May 27, 2019, midnight