Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating Time Series Model in R

I want to answer the following question, I know that I can use the arima.sim function but I am not sure how to simulate model asked:

I want to simulate the following:

yt =α+βt+φyt−1 +εt, εt ∼IIDN(0,1)

when: alpha=1, beta=0 and theta=0.8

Before each simulation we should set the seed to 100,000. Assume a starting value of y0=0 and obtain 500 observations. I have tried the following but it doesn't seem to work:

set.seed(seed = 100000)
e <- rnorm(500)
m1 <- arima.sim(model = list(c(ma=0.8,alpha=1,beta=0)),n=500)

I have to simulate 4 different models for 4 different values of beta, theta and alpha. Any suggestions?

Thanks in advance.

like image 403
Peter Avatar asked Feb 22 '26 01:02

Peter


2 Answers

Since you were using arima.sim in your attempt, here is an arima.sim option:

set.seed(100000)
t <- 1:500
alpha <- 1
beta <- 0
theta <- 0.8
ts <- alpha + beta * t + arima.sim(list(ma = theta), n = length(t))

Since beta = 0, there is no deterministic time-dependent trend, and the process corresponds to an MA(1) process with non-zero mean alpha.

This decomposition into a deterministic and stochastic term corresponds to rewriting your equation as

enter image description here

with the MA(1) process

enter image description here

where the ϵ's are the i.i.d. N(0, 1) residuals.

We can visualise the data

library(forecast)
autoplot(ts)

enter image description here

like image 197
Maurits Evers Avatar answered Feb 24 '26 13:02

Maurits Evers


1. (α,β,φ) = (1,0,0.8)

set.seed(seed = 1232020)
e <- rnorm(500,mean=0,sd=1)

alpha <- 1
beta <- 0
theta <- 0.8
m_1 <- 0
for(i in 2:length(e)){
  m_1[i] <- alpha+beta*i+theta*m_1[i-1]+e[i]
}

Think this should do the trick :)

like image 36
Peter Avatar answered Feb 24 '26 13:02

Peter