multSimCsv: Multiple simulations of a pdmp model

Description Usage Arguments Details Value Working with the simulations See Also

Description

Perform simulations of a pdmp model and save the results in multiple csv files.

Usage

1
2
multSimCsv(obj, seeds, prefix = format(obj, end = "__"),
  append = FALSE, uniqueSeeds = TRUE, digits = NULL)

Arguments

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 append = TRUE, the simulated results will be appended at the end of the file. Otherwise an error will be thrown.

uniqueSeeds

logical. If some numbers in seeds appear multiple times, shall the corresponding simulations be saved only once? If append = TRUE, seeds and already simulated seeds will both be checked for repeated seed numbers.

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 getOption("digits").

Details

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:

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:

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.

Value

object of class multSimCsv providing the filenames of all files that contain the simulated results with corresponding LaF objects stored in element lafList.

Working with the simulations

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.

See Also

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.


CharlotteJana/pdmpsim documentation built on July 2, 2019, 5:37 a.m.