simulate {dse}R Documentation

Simulate a TSmodel

Description

Simulate a model to produce artificial data.

Usage

    simulate(model, ...)
    ## S3 method for class 'ARMA'
simulate(model, y0=NULL, input=NULL, input0=NULL,
        start=NULL, freq=NULL, sampleT=100, noise=NULL, sd=1, Cov=NULL,
        rng=NULL, noise.model=NULL, compiled=.DSEflags()$COMPILED, ...)
    ## S3 method for class 'SS'
simulate(model, input=NULL, 
        start=NULL, freq=NULL,sampleT=100, noise=NULL, sd=1, Cov=NULL,
	rng=NULL, compiled=.DSEflags()$COMPILED, ...)
    ## S3 method for class 'TSestModel'
simulate(model, input=inputData(model),
			sd=NULL, Cov=NULL, ...)

Arguments

model

An object of class TSmodel or TSestModel.

input

Data for the exogenous variable if specified in the model.

sampleT

The length of the sample to simulate.

start

start date for resulting data.

freq

freq for resulting data.

y0, input0

Lagged values prior to t=1 for y and u, in reverse order so y0[1,] and input0[1,]correspond to t=0. These arguments are not implemented for state space models. If not specified initial values are set to zero.

noise

Noise can be supplied. Otherwise it will be generated. If supplied it should be a list as described below in details.

Cov

The covariance of the noise process. If this is specified then sd is ignored. A vector or scalar is treated as a diagonal matrix. For an object of class TSestModel, if neither Cov nor sd are specified, then Cov is set to the estimated covariance (model$estimates$cov).

sd

The standard deviation of the noise. This can be a vector.

noise.model

A TSmodel to be used for generating noise (not yet supported by SS methods).

rng

The random number generator information needed to regenerate a simulation.

compiled

Specifies the compiled version of the code should be used (instead of the S code version).

...

arguments passed to other methods.

Details

A state space or ARMA model (see TSmodel, ARMA, and SS for more details) is simulated with pseudo random noise (The default noise is a normally distributed processes. An object of class TSdata is returned. This can be used as input to estimation algorithms. If start and freq are specified, or if input or noise$w (in that order) have time series properties, these are given to the output.

If noise is not supplied then random values will be generated using other supplied information or defaults. The rng will be set first if it is specified.

The default noise generation will be N(0,I) If Q is not square in a non innovations state space model (i.e. the system noise has a dimension less than the state dimension), then it is padded with zeros, so generated noise of higher dimension has no effect. If sd is supplied, then w as describe below will be N(0,sqr(sd)). sd can be a vector of p elements corresponding to each of the p outputs.

If noise is supplied it should be a list of the necessary noise processes. For non-innovation form state space models the list must have elements w, e, and w0. (w0 is w for t=0 in state space model and prior lags in ARMA models.) For innovation form state space models and ARMA models with MA components the list should have elements w and w0, but if w0 is not specified it is set to zero. For ARMA models with no MA components (i.e. VAR models) the list needs only w. In this case, and in the innovations form state space model with w0=0, a matrix may be supplied in place of a list. w should be a sampleT by p matrix giving the noise for t=1 to sampleT. If noise is specified sampleT will be set to the number of periods in w.

If noise$w0 is a matrix (rather than a vector) for a state space model simulation (as it is for ARMA simulations) then it is set to a vector of zeros. This provides compatability with VAR models (ARMA models with no lags in B).

Input must be specified for ARMA models with model$C not NULL and state space models with model$G not NULL..

In general ARMA and SS simulations will not produce exactly the same results because it is impossible to determine necessary transformation of initial conditions and w0.

Value

The value returned is an object of class TSdata which can be supplied as an argument to estimation routines. (See TSdata). In addition to the usual elements (see the description of a TSdata object) there are some additional elements: model- the generating model, rng - the initial RNG and seed, version - the version of S used (random number generators may vary) Cov as specified sd as specified noise - the noise details as provided in the argument or as generated. state - the state variable for state space models.

See Also

makeTSnoise, TSmodel, TSdata, ARMA, SS

Examples

    mod1 <- ARMA(A=array(c(1,-.25,-.05), c(3,1,1)), B=array(1,c(1,1,1)))
    AR   <- array(c(1, .5, .3, 0, .2, .1, 0, .2, .05, 1, .5, .3) ,c(3,2,2))
    VAR  <- ARMA(A=AR, B=diag(1,2))
    print(VAR)
    simData <- simulate(VAR)

    C    <- array(c(0.5,0,0,0.2),c(1,2,2))
    VARX <- ARMA(A=AR, B=diag(1,2), C=C) 
    simData <- simulate(VARX, sampleT=150, input=matrix(rnorm(300),150,2))

    MA   <- array(c(1, .2, 0, .1, 0, 0, 1, .3), c(2,2,2)) 
    ARMA  <- ARMA(A=AR, B=MA, C=NULL) 
    simData <- simulate(ARMA, sampleT=200)

    ARMAX <- ARMA(A=AR, B=MA, C=C) 
    simData <- simulate(ARMAX, sampleT=150, input=matrix(rnorm(300),150,2))

    data("eg1.DSE.data.diff", package="dse")
    model <- estVARXls(eg1.DSE.data.diff)
    simData <- simulate(model)

    ss <- SS(F=array(c(.5, .3, .2, .4), c(2,2)), 
             H=array(c(1, 0, 0, 1), c(2,2)),
	     K=array(c(.5, .3, .2, .4), c(2,2)))

    print(ss)
    simData <- simulate(ss)

    testEqual(simData, simulate(ss))
    testEqual(simData, simulate(ss, rng=setRNG::getRNG(simData)))

    simData2 <- simulate(ss,
        noise=list(w=matrix(runif(300), 150,2), w0=runif(2)))

    simData3 <- simulate(ss, noise=matrix(runif(400), 200,2))
    

[Package dse version 2020.2-1 Index]