mcRun: Monte Carlo Simulation

Description Usage Arguments Details Value Examples

Description

Run Monte Carlo simulations, taking advantage of multiple processing cores or a computing cluster

Usage

1
2
3
4
mcRun(mcr.fn, mcr.fnArgs = NULL, mcr.cluster = NULL,
  mcr.outfile = tempfile(fileext = ".csv"), mcr.datFn = NULL,
  mcr.datArgs = NULL, mcr.dat = NULL, mcr.constant = NULL,
  mcr.varying = NULL, mcr.LoadOnExit = TRUE, mcr.reportInt = 100)

Arguments

mcr.fn

A character string naming the function that performs the analysis: for example, for one-factor designs this could be any one of fitanova, fitlmer, fitlmer.mcmc, fitstepwise, fitstepwise.bestpath, fitrsonly, fitnocorr, or lrCompare. May also be a user-supplied function (see 'Details').

mcr.fnArgs

Arguments to be passed from mcRun to the function named by mcr.fn.

mcr.cluster

A processing cluster object, typically created by a call to makeCluster from the package parallel. If NULL (default), uses a single processing core.

mcr.outfile

name of file to which to write the output ("comma separated value" format). Defaults to "out.csv".

mcr.datFn

Name of function to be used to generate data set for each Monte Carlo run (e.g., 'mkDf'). May be a user-supplied function that returns a data frame. If a the same dataset is to be used for all runs, then set to 'NULL' and define mcr.dat instead.

mcr.datArgs

Arguments to be passed from mcRun to the function named by mcr.datFn.

mcr.dat

A data frame to be used in all Monte Carlo runs. If the data are to be generated by a function, set to 'NULL' and use mcr.datFn instead.

mcr.constant

list of parameter values that are constant over all runs.

mcr.varying

A matrix, data frame or list of lists containing the parameters to be varied over runs, with each row corresponding to a single run. This determines the number of Monte Carlo runs (see 'Details').

mcr.LoadOnExit

whether the data should be loaded from the file upon completion into an R object, and passed on as the return value from the function.

mcr.reportInt

Interval at which to give status updates on progress (default = every 100 runs)

Details

The number of simulations that will be run is given by nrow(mcr.varying), the number of rows in the parameter matrix passed as an argument to the function. The results matrix will be stored in the file whose path is given by mcr.outfile in Comma Separated Values (CSV) format.

If mcr.fn is a user-supplied function, the corresponding function must return a vector with all elements of mode 'numeric', and accept arguments mcr.data and (optionally) mcr.params. All arguments in mcr.fnList will be passed to that function.

If mcr.datFn is a user-supplied function, the corresponding function must return a data frame and accept the argument mcr.params. All arguments in mcr.datArgs will be passed to that function.

Value

If mcr.LoadOnExit is true, loads the data from the CSV file and returns it to the calling function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
nmc <- 10
pmx <- cbind(randParams(genParamRanges(), nmc, 1001), seed=mkSeeds(nmc, 1001))

cl <- NULL # single-core processing
# alternatively:
# cl <- parallel:::makeCluster(number.of.clusters)
# see the 'parallel' package

mx <- mcRun("fitanova", mcr.cluster=cl,
mcr.fnArgs=list(wsbi=TRUE), # pass this along to fitanova
mcr.varying=pmx, # parameters that are varying; each row is a single run
mcr.datFn="mkDf",  # data-generating function to call
mcr.datArgs=list(nitem=12, wsbi=TRUE), # values to be passed along to mkDf
mcr.reportInt=5) # report progress every 5 runs

dalejbarr/simgen documentation built on May 14, 2019, 3:32 p.m.