This function creates a function for advancing the state of an SDE model using a simple Euler-Maruyama integration method. The resulting function (closure) can be used in conjunction with other functions (such as `simTs`

) for simulating realisations of SDE models.

1 |

`drift` |
A function representing the drift vector of the SDE model
(corresponding roughly to the RHS of an ODE model). |

`diffusion` |
A function representing the diffusion matrix of the SDE model (the square root of the infinitesimal variance matrix). |

`dt` |
Time step to be used by the simple Euler-Maruyama integration method. Defaults to 0.01. |

An R function which can be used to advance the state of the SDE model with given drift vector and diffusion matrix, by using an Euler-Maruyama method with step size `dt`

. The function closure has interface `function(x0,t0,deltat,...)`

, where `x0`

and `t0`

represent the initial state and time, and `deltat`

represents the amount of time by which the process should be advanced. The function closure returns a vector representing the simulated state of the system at the new time.

`StepEuler`

, `StepCLE`

, `simTs`

, `simSample`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
# Immigration-death diffusion approx with death rate a CIR process
myDrift <- function(x,t,th=c(lambda=1,alpha=1,mu=0.1,sigma=0.1))
{
with(as.list(c(x,th)),{
c( lambda - x*y ,
alpha*(mu-y) )
})
}
myDiffusion <- function(x,t,th=c(lambda=1,alpha=1,mu=0.1,sigma=0.1))
{
with(as.list(c(x,th)),{
matrix(c( sqrt(lambda + x*y) , 0,
0, sigma*sqrt(y) ),ncol=2,nrow=2,byrow=TRUE)
})
}
# create a stepping function
stepProc = StepSDE(myDrift,myDiffusion)
# integrate the process and plot it
out = simTs(c(x=5,y=0.1),0,20,0.1,stepProc)
plot(out)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.