Learn R Programming

gratis (version 1.0.7)

simulate.mar: Generate synthetic data from a Mixture Autoregressive model

Description

This function simulates one random sample path from a mixture of k Gaussian AR(p) processes. The model is of the form $$y_t = \phi_{0,i} + \phi_{1,i}y_{t-1} + \dots + \phi_{p,i}y_{t-p} + \sigma_{i,t}\epsilon_t$$ with probability \(\alpha_i\), where \(\epsilon_t\) is a N(0,1) variate.

Usage

# S3 method for mar
simulate(object, nsim = 100, seed = NULL, n.start = 100, ...)

Value

`ts` object of length nsim.

Arguments

object

A `mar` object, usually the output of mar_model().

nsim

length of series to generate

seed

Either NULL or an integer that will be used in a call to set.seed before simulating the time series. The default, NULL, will not change the random generator state.

n.start

Length of 'burn-in' period.

...

Other arguments, not currently used.

Author

Rob J Hyndman

References

Feng Li, Mattias Villani, and Robert Kohn. (2010). Flexible Modeling of Conditional Distributions using Smooth Mixtures of Asymmetric Student T Densities, Journal of Statistical Planning and Inference, 140(12), pp. 3638-3654.

See Also

mar_model

Examples

Run this code
# MAR model with constant variances
phi <- cbind(c(0, 0.8, 0), c(0, 0.6, 0.3))
weights <- c(0.8, 0.2)
model1 <- mar_model(phi = phi, sigmas = c(1, 2), weights = weights)
y <- simulate(model1, 100)
plot(y)

# MAR model with heteroskedastic errors
sigmas.spec <- list(
  fGarch::garchSpec(model = list(alpha = c(0.05, 0.06))),
  fGarch::garchSpec(model = list(alpha = c(0.05, 0.05)))
)
model2 <- mar_model(phi = phi, sigmas = sigmas.spec, weights = weights)
y <- simulate(model2, 100)
plot(y)

Run the code above in your browser using DataLab