mixedsde.sim {mixedsde} | R Documentation |
Simulation Of A Mixed Stochastic Differential Equation
Description
Simulation of M independent trajectories of a mixed stochastic differential equation (SDE) with linear drift and two random effects
, for
.
Usage
mixedsde.sim(M, T, N = 100, model, random, fixed = 0, density.phi,
param, sigma, t0 = 0, X0 = 0.01, invariant = 0, delta = T/N,
op.plot = 0, add.plot = FALSE)
Arguments
M |
number of trajectories |
T |
horizon of simulation. |
N |
number of simulation steps, default Tx100. |
model |
name of the SDE: 'OU' (Ornstein-Uhlenbeck) or 'CIR' (Cox-Ingersoll-Ross). |
random |
random effects in the drift: 1 if one additive random effect, 2 if one multiplicative random effect or c(1,2) if 2 random effects. |
fixed |
fixed effects in the drift: value of the fixed effect when there is only one random effect, 0 otherwise.
If random =2, fixed can be 0 but |
density.phi |
name of the density of the random effects. |
param |
vector of parameters of the distribution of the two random effects. |
sigma |
diffusion parameter |
t0 |
time origin, default 0. |
X0 |
initial value of the process, default X0=0. |
invariant |
1 if the initial value is simulated from the invariant distribution, default 0.01 and X0 is fixed. |
delta |
time step of the simulation (T/N). |
op.plot |
1 if a plot of the trajectories is required, default 0. |
add.plot |
1 for add trajectories to an existing plot |
Details
Simulation of M independent trajectories of the SDE (the Brownian motions are independent), with linear drift. Two diffusions are implemented, with one or two random effects:
Ornstein-Uhlenbeck model (OU)
If random = 1, is a fixed effect:
If random = 2, is a fixed effect:
If random = c(1,2),
Cox-Ingersoll-Ross model (CIR)
If random = 1, is a fixed effect:
If random = 2, is a fixed effect:
If random = c(1,2),
The initial value of each trajectory can be simulated from the invariant distribution of the process:
Normal distribution with mean and variance
for the OU, a gamma distribution
for the C-I-R model.
Density of the random effects
Several densities are implemented for the random effects, depending on the number of random effects.
If two random effects, choice between
'normalnormal': Normal distributions for both
and param=c(mean_
, sd_
, mean_
, sd_
)
'gammagamma': Gamma distributions for both
and param=c(shape_
, scale_
, shape_
, scale_
)
'gammainvgamma': Gamma for , Inverse Gamma for
and param=c(shape_
, scale_
, shape_
, scale_
)
'normalgamma': Normal for , Gamma for
and param=c(mean_
, sd_
, shape_
, scale_
)
'normalinvgamma': Normal for , Inverse Gamma for
and param=c(mean_
, sd_
, shape_
, scale_
)
'gammagamma2': Gamma for
, Gamma
for
and param=c(shape_
, scale_
, shape_
, scale_
)
'gammainvgamma2': Gamma for
, Inverse Gamma for
and param=c(shape_
, scale_
, shape_
, scale_
)
If only is random, choice between
'normal': Normal distribution with param=c(mean, sd)
lognormal': logNormal distribution with param=c(mean, sd)
'mixture.normal': mixture of normal distributions with
param=c(p,
)
'gamma': Gamma distribution with param=c(shape, scale)
'mixture.gamma': mixture of Gamma distribution
with param=c(p, shape1, scale1, shape2, scale2)
'gamma2': Gamma distribution with param=c(shape, scale)
'mixed.gamma2': mixture of Gamma distribution +
with param=c(p, shape1, scale1, shape2, scale2)
If only is random, choice between
'normal': Normal distribution with param=c(mean, sd)
'gamma': Gamma distribution with param=c(shape, scale)
'mixture.gamma': mixture of Gamma distribution
with param=c(p, shape1, scale1, shape2, scale2)
Value
X |
matrix (M x (N+1)) of the M trajectories. |
phi |
vector (or matrix) of the M simulated random effects. |
References
This function mixedsde.sim is based on the package sde, function sde.sim. See Simulation and Inference for stochastic differential equation, S.Iacus, Springer Series in Statistics 2008 Chapter 2
See Also
https://cran.r-project.org/package=sde
Examples
#Simulation of 5 trajectories of the OU SDE with random =1, and a Gamma distribution.
simuOU <- mixedsde.sim(M=5, T=10,N=1000,model='OU', random=1,fixed=0.5,
density.phi='gamma', param=c(1.8, 0.8) , sigma=0.1,op.plot=1)
X <- simuOU$X ;
phi <- simuOU$phi
hist(phi)