| multSimCsv | R Documentation |
Perform simulations of a pdmp model and save the results in multiple csv files.
multSimCsv(
obj,
seeds,
prefix = format(obj, end = "__"),
append = FALSE,
uniqueSeeds = TRUE,
digits = NULL
)
obj |
object of class pdmpModel or one of its subclasses |
seeds |
integer vector with seeds that shall be simulated (different seeds lead to different simulated trajectories) |
prefix |
string which determines the begin of all filenames that are created by the method, e.g. "NameOfModel". You can also specify a path where to save the result, e.g. "home/path/to/simulations/NameofModel". |
append |
logical. If there already exists a file with the same filename
and |
uniqueSeeds |
logical. If some numbers in |
digits |
integer indicating how many significant digits are to be saved
in the csv files. Restricting digits can lead to smaller csv files. The
default, NULL, uses |
This method performs a simulation of the pdmpModel obj for every seed
that appears in vector seeds. The result is stored in different csv
files in the working directory (or any other directory if specified in
prefix). Saving the results as csv files is important for large
simulations where the files become bigger than the working memory of the
computer. Saving as .rda object (as can be done with method
multSim) then becomes useless because rda objects are loaded
completely into R and therefore have to be smaller than the working memory.
If the simulations are stored as csv files, they can be accessed with methods
from package LaF.
Every csv file created by multSimCsv contains the simulated values of
one of the variables of the model obj.
If e.g. the init slot of obj is given as
c(f = 1, g = 2, h = 3) and prefix = "exampleModel",
method multSimCsv will create three csv files named
exampleModel_Simulations_f.csv, exampleModel_Simulations_g.csv,
and exampleModel_Simulations_h.csv where the first contains all
simulated values of variable f, the second of g and the third
of h.
The csv files are constructed as follows:
The first row contains the names of the columns. The first column is named "Seed", all other column names come from the time values, e. g. "time0" "time0.1" "time0.2" and so on.
All other rows contain the seed (first column) and the corresponding simulation for one of the variables.
Slot obj@out is not affected by multSim.
In case of a break or an error, already simulated seeds will still be saved
in the csv files.
Method multSimCsv also saves and returnes an object of s3 class
multSimCsv which contains all important informations about the
simulation and can be loaded into the working memory. In our example,
this object would be saved as "exampleModel_MultSimCsv.rda".
The class has 6 elements:
model containing the pdmpModel obj,
seeds containing the integer vector seeds,
csvList: a character vector containing the filenames of
stored simulated results,
datamodel containing all the information package LaF needs
for opening the csv files,
lafList: a list for the corresponding LaF objects,
timeList: a list containing the time needed for every simulation
Element lafList has to be created during run-time, therefore it is
saved as null. The returned multSimCsv object however has a valid
lafList. If you want to load a multSimCsv object from a rda
file, use loadMultSimCsv to create lafList automatically.
object of class multSimCsv providing the filenames of all
files that contain the simulated results with corresponding LaF objects
stored in element lafList.
If you stored your simulations in csv files with multSimCsv, you
can access the results by loading the corresponding rda object
with loadMultSimCsv and store them in a variable, i.e.
msCsv. Then you can read out i.e. the simulated values of
the second variable (referring to the order of your variables in
slot init) with the third seed via msCsv$lafList[[2]][3, ].
There are also a lot of plot methods available. To use them, you first
have to choose some seed numbers and time values and use method
getMultSimData to store them in a data.frame.
This method may need some time for calculation and the result needs to
fit into the working memory. Afterwards, you can apply methods
plot, plotTimes, plotStats,
summarize_at, hist, density
and plotSeeds on the data.frame created with
getMultSimData. You can also use plotTimes to find
the seed numbers of interesting outliers by setting parameter nolo suitably.
loadMultSimCsv to load a stored multSimCsv
object, multSim to perform multiple simulations that need not
too much memory, multSim2multSimCsv to convert an object
created with method multSim into a multSimCsv object.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.