Since a Monte-Carlo simulation lasts potentially much longer (up to several hours or days if the number of observations is in the millions) than the main calculations, this function offers multiple possibilities to save and load the simulations. By default, simulations are stored and loaded with suitable default values and no user choices are required. If desired, the simulation, saving and loading can be controlled by the argument option
. This argument has to be a list
or NULL
. For the list
the following named entries are allowed: "simulation"
, "save"
, "load"
, "envir"
and "dirs"
. All missing entries will be set to their default option.
Each Monte-Carlo simulation is specific to the parametric family
, their parameters in case of families "LR"
or "2Param"
, the number of observations and the used filter. Monte-Carlo simulations can also be performed for a (slightly) larger number of observations \(n_q\) given in the argument nq
, which avoids extensive resimulations for only a little bit varying number of observations at price of a (slightly) smaller detection power. We recommend to not use a nq
more than two times larger than the number of observations n
.
Objects of the following types can be simulated, saved and loaded:
"vector"
: an object of class "MCSimulationMaximum"
for n
observations, i.e. a numeric vector of length r
"vectorIncreased"
: an object of class "MCSimulationMaximum"
for nq
observations, i.e. a numeric vector of length r
"matrix"
: an object of class "MCSimulationVector"
for n
observations, i.e. a matrix of dimensions as.integer(log2(n)) + 1L
and r
"matrixIncreased"
: an object of class "MCSimulationVector"
for nq
observations, i.e. a matrix of as.integer(log2(n)) + 1L
and r
Computation of scale depend critical values, i.e. calucatlions for the families "hjsmurf"
, "hjsmurfSPS"
, "hjsmurfLR"
, "LR"
and "2Param"
require an object of class "MCSimulationVector"
. Otherwise, objects of class "MCSimulationVector"
and objects of class "MCSimulationMaximum"
lead to the same result (if the number of observations is the same), but an object of class "MCSimulationVector"
requires much more storage space and has slightly larger saving and loading times. However, simulations of type "vectorIncreased"
, i.e. objects of class "MCSimulationMaximum"
with nq
observations, have to be resimulated if as.integer(log2(n1)) != as.integer(log2(n2))
when the saved simulation was computed with n == n1
and the simulation now is required for n == n2
and nq >= n1
and nq >= n2
. All in all, if all data sets in the analysis have the same number of observations simulations of type "vector"
for families "jules"
, "jsmurf"
, "jsmurfPS"
, "jsmurfLR"
and "matrix"
for families "hjsmurf"
, "hjsmurfSPS"
, "hjsmurfLR"
, "LR"
and "2Param"
are recommended. If they have a slightly different number of observations it is recommend to set nq
to the largest number and to use simulations for an increased number of observations. For families "jules"
, "jsmurf"
, "jsmurfPS"
, "jsmurfLR"
one should also consider the following: If as.integer(log2(n))
is the same for all data sets type "vectorIncreased"
is recommend , if they differ type "matrixIncreased"
avoids a resimulation at the price of a larger object to be stored and loaded.
The simulations can either be saved in the workspace in the variable critValStepRTab
or persistently on the file system for which the package R.cache
is used. Loading from the workspace is faster, but either the user has to save the workspace manually or in a new session simulations have to be performed again. Moreover, storing in and loading from variables and RDS files is supported.
options$envir and options$dirs
For loading from / saving in the workspace the variable critValStepRTab
in the environment
options$envir
will be looked for and if missing in case of saving also created there. Moreover, the variable(s) specified in options$save$variable
(explained in the Subsection Saving: options$save) will be assigned to this environment
. By default the global environment .GlobalEnv
is used, i.e. options$envir == .GlobalEnv
.
For loading from / saving on the file system loadCache(key = keyList, dirs = options$dirs)
and saveCache(stat, key = attr(stat, "keyList"), dirs = options$dirs)
are called, respectively. In other words, options$dirs
has to be a character
vector
constituting the path to the cache subdirectory relative to the cache root directory as returned by getCacheRootPath
(). If options$dirs == ""
, the path will be the cache root path. By default the subdirectory "stepR"
is used, i.e. options$dirs == "stepR"
. Missing directories will be created.
Simulation: options$simulation
Whenever Monte-Carlo simulations have to be performed, i.e. when stat == NULL
and the required Monte-Carlo simulation could not be loaded, the type specified in options$simulation
will be simulated by monteCarloSimulation
. In other words, options$simulation
must be a single string of the following: "vector"
, "vectorIncreased"
, "matrix"
or "matrixIncreased"
. By default (options$simulation == NULL
), an object of class "MCSimulationVector"
for nq
observations will be simulated, i.e. options$simulation
== "matrixIncreased"
. For this choice please recall the explanations regarding computation time and flexibility at the beginning of this section.
Loading: options$load
Loading of the simulations can be controlled by the entry options$load
which itself has to be a list
with possible entries: "RDSfile"
, "workspace"
, "package"
and "fileSystem"
. Missing entries disable the loading from this option.
Whenever a Monte-Carlo simulation is required, i.e. when the variable q
is not given, it will be searched for at the following places in the given order until found:
in the variable stat
,
in options$load$RDSfile
as an RDS file, i.e. the simulation will be loaded by
readRDS(options$load$RDSfile).
In other words, options$load$RDSfile
has to be a connection
or the name of the file where the R object is read from,
in the workspace or on the file system in the following order: "vector"
, "matrix"
, "vectorIncreased"
and finally of "matrixIncreased"
. For each option it will first be looked in the workspace and then on the file system. All searches can be disabled by not specifying the corresponding string in options$load$workspace
and options$load$fileSystem
. In other words, options$load$workspace
and options$load$fileSystem
have to be vectors of strings containing none, some or all of "vector"
, "matrix"
, "vectorIncreased"
and "matrixIncreased"
,
if all other options fail a Monte-Carlo simulation will be performed.
By default (if options$load
is missing / NULL
) no RDS file is specified and all other options are enabled, i.e.
options$load <- list(workspace = c("vector", "vectorIncreased",
"matrix", "matrixIncreased"),
fileSystem = c("vector", "vectorIncreased",
"matrix", "matrixIncreased"),
RDSfile = NULL).
Saving: options$save
Saving of the simulations can be controlled by the entry options$save
which itself has to be a list
with possible entries: "workspace"
, "fileSystem"
, "RDSfile"
and "variable"
. Missing entries disable the saving in this option.
All available simulations, no matter whether they are given by stat
, loaded, simulated or in case of "vector"
and "vectorIncreased"
computed from "matrix"
and "matrixIncreased"
, respectively, will be saved in all options for which the corresponding type is specified. Here we say a simulation is of type "vectorIncreased"
or "matrixIncreased"
if the simulation is not performed for n
observations. More specifically, a simulation will be saved:
in the workspace or on the file system if the corresponding string is contained in options$save$workspace
and options$save$fileSystem
, respectively. In other words, options$save$workspace
and options$save$fileSystem
have to be vectors of strings containing none, some or all of "vector"
, "matrix"
, "vectorIncreased"
and "matrixIncreased"
,
in a variable named by options$save$variable
in the environment
options$envir
. Hence, options$save$variable
has to be a vector of one or two containing variable names (character vectors). If options$save$variable
is of length two a simulation of type "vector"
or "vectorIncreased"
(only one can occur at one function call) will be saved in options$save$variable[1]
and "matrix"
or "matrixIncreased"
(only one can occur at one function call) will be saved in options$save$variable[2]
. If options$save$variable
is of length one both will be saved in options$save$variable
which means if both occur at the same call only "vector"
or "vectorIncreased"
will be saved. Each saving can be disabled by not specifying options$save$variable
or by passing ""
to the corresponding entry of options$save$variable
.
By default (if options$save
is missing) "vector"
and "vectorIncreased"
will be saved in the workspace and "matrixIncreased"
on the file system, i.e.
options$save <- list(workspace = c("vector", "vectorIncreased"),
fileSystem = c("matrix", "matrixIncreased"),
RDSfile = NULL, variable = NULL).
Simulations can be removed from the workspace by removing the variable critValStepRTab
, i.e. by calling remove(critValStepRTab, envir = envir)
, with envir
the used environment, and from the file system by deleting the corresponding subfolder, i.e. by calling unlink(file.path(R.cache::getCacheRootPath(), dirs), recursive = TRUE),
with dirs
the corresponding subdirectory.