I am using arima.sim to simulate data. I want to introduce in the simulation intercept constant drift and trend and i dont know how do it


Deterministic Trend

If your drift intercept is $c$, you can just add the function $c t$ to the zero mean process.


xt <- arima.sim(n=50, list(order=c(1,0,1), ar = c(.9), ma = -.2))


xtWithDrift <- xt + .20*seq(1,50))

The model would be written like \begin{align*} X_t &= \phi X_{t-1} + Z_t + \theta Z_{t-1} \\ Y_t &= a + ct + X_t. \end{align*}

Stochastic Trend

If you want a stochastic trend, you're better off simulating the differences, then summing those. With a nonrandom starting point, for example:

startSpot <- 3
yt <- arima.sim(n=50, list(order=c(1,0,1),ar=c(.9), ma=-.2)) + .2 #see comment below
plot(startSpot + cumsum(yt))

This gives you $$ X_t = 3 + \sum_{j=1}^t Y_t $$ where $Y_t$ is the ARMA(1,1). $X_t$ is the ARIMA(1,1,1). Or in other words, $$ (1 - \phi B)(Y_t - .2) = (1 + \theta B) Z_t, $$ where $Y_t = X_t - X_{t-1}$.

  • 1
    $\begingroup$ I am pretty sure that the mean = 0.2 isn't doing exactly what you think it is. If you wish the $Y_t$ series to have a mean of approx 0.2 then add do yt <- arima.sim(...) + 0.2, see: stats.stackexchange.com/questions/294748/… $\endgroup$
    – t-student
    Jul 28 '17 at 21:10
  • $\begingroup$ @markstep thanks very much. I just made the appropriate changes. $\endgroup$
    – Taylor
    Jul 28 '17 at 21:28
  • $\begingroup$ Thank you for your answer, im trying to learn and i have a new question. I run like you write: yt<-arima.sim(n=5000,list(order=c(1,0,0),ar=.9))+.2 then i run: mean(yt) (p<-arima(yt,order = c(1,0,0),include.mean = TRUE)) #Model Ar(1) and i obtain mean=0.181 always a diferent value in several simulation and the coeficients ar(1)=0.9 always, what is right but the intercept is always the means, With this model, the mean shouldnt be lamdba/(1-.9)=.2/.1=2?? Why this happen Thank you again $\endgroup$ Jul 29 '17 at 2:14
  • $\begingroup$ @CarlosSergioJara no you're okay. .2 is the mean. The sample means should be close to .2 (.18 is pretty close). Your formula is correct about the intercept here, but it has nothing to do with this example. Maybe try simulating more examples, and calculate more sample means. You can also get a good idea of how far off it should be if you don't add .2. Calculate the sample means then, and see how close they are to 0 $\endgroup$
    – Taylor
    Jul 29 '17 at 3:05
  • $\begingroup$ Thank You again ¿And when the mean in a process ar(1) would be lamba/(1-phi1)=2? ¿How could i simulate this process? Being more precisely ¿What is mu=lambda/(1-phi) 20=.02/(1-.09)? $\endgroup$ Jul 29 '17 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.