add_reftable {Infusion} | R Documentation |
Create or augment a list of simulated distributions of summary statistics
Description
add_reftable
creates or augments a reference table of simulations, and formats the results appropriately for further use. The user does not have to think about this return format. Instead, s-he only has to think about the very simple return format of the function given as its Simulate
argument. The primary role of his function is to wrap the call(s) of the function specified by Simulate
. Depending on the arguments, parallel or serial computation is performed.
When parallelization is implied, it is performed by by default a “socket” cluster, available on all operating systems. Special care is then needed to ensure that all required packages are loaded in the called processes, and that all required variables and functions are passed therein: check the packages
and env
arguments. For socket clusters, foreach
or pbapply
is called depending whether the doSNOW
package is attached (doSNOW
allows more efficient load balancing than pbapply
).
Alternatively, if the simulation function cannot be called directly by the R code, simulated samples can be added using the newsimuls
argument. Finally, a generic data frame of simulated samples can be reformatted as a reference table by using only the reftable
argument.
add_simulation
is a wrapper for add_reftable
, suitable when nRealizations
>1. It is now distinctly documented: the distinct features of add_simulation
were conceived for the first workflow implemented in Infusion
but are somewhat obsolete now.
Usage
add_reftable(reftable=NULL, Simulate, parsTable=par.grid, par.grid=NULL,
nRealizations = 1L, newsimuls = NULL,
verbose = interactive(), nb_cores = NULL, packages = NULL, env = NULL,
control.Simulate=NULL, cluster_args=list(), cl_seed=NULL, ...)
Arguments
reftable |
Data frame: a reference table. Each row contains parameters value of a simulated realization of the data-generating process, and the simulated summary statistics.
As parameters should be told apart from statistics by Infusion functions, information about parameter names should be attached to the |
Simulate |
An *R* function, or the name (as a character string) of an *R* function used to generate summary statistics for samples form a data-generating process. When an external simulation program is called, |
parsTable , par.grid |
A data frame of which each line is the vector of parameters needed by |
nRealizations |
The number of simulated samples of summary statistics, for each parameter vector (each row of |
newsimuls |
If the function used to generate empirical distributions cannot be called by R, then |
nb_cores |
Number of cores for parallel simulation; |
cluster_args |
A list of arguments, passed to |
verbose |
Whether to print some information or not. |
... |
Additional arguments passed to |
control.Simulate |
A list, used as an exclusive alternative to “...” to pass additional arguments to |
packages |
For parallel evaluation: Names of additional libraries to be loaded on the cores, necessary for |
env |
For parallel evaluation: an environment containing additional objects to be exported on the cores, necessary for |
cl_seed |
(all parallel contexts:) Integer, or NULL. If an integer, it is used to initialize |
Details
The newsimuls
argument should have the same structure as the return value of the function itself, except that newsimuls
may include only a subset of the attributes returned by the function. It is thus a data frame; its required attributes are LOWER
and UPPER
which are named vectors giving bounds for the parameters which are variable in the whole analysis (note that the names identify these parameters in the case this information is not available otherwise from the arguments). The values in these vectors may be incorrect in the sense of failing to bound the parameters in the newsimuls
, as the actual bounds are then corrected using parameter values in newsimuls
and attributes from reftable
.
Value
A data.frame (with additional attributes) is returned.
The value has the following attributes: LOWER
and UPPER
which are each a vector of per-parameter minima and maxima deduced from any newsimuls
argument, and optionally any of the arguments Simulate, control.Simulate, packages, env, parsTable
and reftable
(all corresponding to input arguments when provided, except that the actual Simulate
function is returned even if it was input as a name).
Examples
## see main documentation page for the package for other typical usage