mjpModel-sim: Simulation of a mjpModel object

Description Usage Arguments Value Note See Also Examples

Description

Simulation of a mjpModel object

Usage

1
2
3
## S4 method for signature 'mjpModel'
sim(obj, initialize = FALSE, seed = 1,
  njump = 1e+06, outSlot = TRUE, ...)

Arguments

obj

object of class mjpModel or one of its subclasses

initialize

boolean variable. If initialize = TRUE and obj contains a user-defined initializing function (initfunc), this function will be called before the simulation. This can be useful i. e. to set a random initial value (see examples). If random numbers are generated within initfunc, they will be affected by the given seed. To avoid this, add set.seed(NULL) to the function definition of initfunc. Parameter initialize defaults to FALSE, because it is not necessary for simulating piecewise deterministic Markov models.

seed

an integer or NULL. This makes the result of sim reproducible, although random numbers are used during execution. Simulation with equal seeds will lead to equal results. If seed is set to NULL, a new one is created from the current time and the process ID.

njump

number of maximal possible jumps. The default value is 1e+06 and should be sufficient. If the simulation breaks before the end of simulation time, try to set a higher value for njump.

outSlot

boolean variable. If FALSE, only the result of the simulation is returned. If TRUE, the whole obj is returned with the simulation result stored in slot out.

...

optional parameters passed to the solver function.

Value

The returned value depends on the parameter outSlot. If outSlot = TRUE, the function returns the complete pdmpModel instance with the simulation result saved in the out slot. Otherwise, only the simulation result is returned.

Note

If the result is stored in slot out, it can get lost if the value of the other slots is changed via <-. See mjp-accessors for further informations.

See Also

function multSim or multSimCsv for multiple simulations, ... for plot and summary methods of the simulation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
data("KendallBD") # load object of class pdmpModel

#### simulations

# simulate and plot the result
plot(sim(KendallBD, seed = 1))

# simulate and plot the result with random seed
plot(sim(KendallBD, seed = NULL))

# simulating again with seed = 1 leads to the same result as before
plot(sim(KendallBD, seed = 1))

#### be careful about slot out!

out(KendallBD) # NULL, because results have not been stored

simBD <- sim(kendallBD) # simulation results are stored in out
head(out(simBD))

init(KendallBD) <- c(N = 10)
head(out(KendallBD)) # NULL, because slot init has changed

simBD <- sim(KendallBD, outSlot = FALSE)
str(simBD) # only the simulation result, the mjpModel object is lost

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