simTimes: Simulate a model at a specified set of times, using a...

Description Usage Arguments Value See Also Examples

View source: R/StepGillespie.R

Description

This function simulates a single realisation from a Markovian model and records the state at a specified set of times using a function (closure) for advancing the state of the model, such as created by StepGillespie or StepEulerSPN.

Usage

1
simTimes(x0,t0=0,times,stepFun,...)

Arguments

x0

The initial state of the process at time t0.

t0

The initial time to be associated with the initial state x0. Defaults to 0.

times

A vector of times at which the state of the process is required. It is assumed that the times are in increasing order, and that the first time is at least as big as t0.

stepFun

A function (closure) for advancing the state of the process, such as produced by StepGillespie or StepEulerSPN.

...

Additional arguments will be passed to stepFun.

Value

An R matrix where each row represents the state of the process at one of the required times. The row names contain the sampled times.

See Also

StepEulerSPN, StepGillespie, simTs, simSample, as.timedData, pfMLLik

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# load the LV model
data(spnModels)
# create a stepping function
stepLV = StepGillespie(LV)
# simulate a realisation using simTimes
times = seq(0,100,by=0.1)
plot(ts(simTimes(c(x1=50,x2=100),0,times,stepLV),start=0,deltat=0.1),plot.type="single",lty=1:2)
# simulate a realisation at irregular times
times = c(0,10,20,50,100)
out2 = simTimes(c(x1=50,x2=100),0,times,stepLV)
print(out2)

Example output

Loading required package: abind
Loading required package: parallel
     x1  x2
0    50 100
10   63  88
20  106 135
50  298 276
100   4 402

smfsb documentation built on May 2, 2019, 5:13 a.m.