sally.Y
sally.Y

Reputation: 31

how to several AR(1) time series which are iid in R

I can simulate one AR(1) time series in R by using: arima.sim(list(order = c(1,0,0), ar = 0.8), n=100)

but how can I simulate several AR(1) time series which are iid in R?

Thank you!

Upvotes: 3

Views: 605

Answers (2)

Ben
Ben

Reputation: 1486

Use the rGARMA function in the ts.extend package

You can generate random vectors from any stationary Gaussian ARMA model using the ts.extend package. This package generates random vectors directly form the multivariate normal distribution using the computed autocorrelation matrix for the random vector, so it gives random vectors from the exact distribution and does not require "burn-in" iterations. Here is an example of generating multiple independent time-series vectors all from an AR(1) model.

#Load the package
library(ts.extend)

#Set parameters
AR <- 0.8
m  <- 100

#Generate n = 36 random vectors from this model
set.seed(1)
SERIES <- rGARMA(n = 36, m = m, ar = AR, errorvar = 1)

#Plot the series using ggplot2 graphics
library(ggplot2)
plot(SERIES)

enter image description here

Upvotes: 0

Andrelrms
Andrelrms

Reputation: 819

you can use replicate(), let's say you want to do replicate it 10 times, you just need to do :

replicate(10,arima.sim(list(order = c(1,0,0), ar = 0.8), n=100))

you will get a matrix with 10 columns and 100 rows, so each column is a simualtion.

Upvotes: 3

Related Questions