[R] How to include trend (drift term) in arima.sim

StephenRichards stephen at richardsconsulting.co.uk
Thu Aug 19 19:09:49 CEST 2010


I have been trying to simulate from a time series with trend but I don't see
how to include the trend in the arima.sim() call.  The following code
illustrates the problem:

# Begin demonstration program
x <- c(0.168766559,  0.186874000,  0.156710548,  0.151809531,  0.144638812,
       0.142106888,  0.140961714,  0.134054659,  0.138722419,  0.134037018,
       0.122829846,  0.120188714,  0.122060497,  0.137424358,  0.113311269,
       0.125051374,  0.103707302,  0.089999121,  0.094848588,  0.100941354,
       0.096845633,  0.072098064,  0.081167803,  0.068140319,  0.063988361,
       0.053722446,  0.051986886,  0.044317196,  0.032021664,  0.023656304,
       0.025620223,  0.012297433, -0.003523446, -0.005782116, -0.027448303,
      -0.034745961, -0.042594172, -0.058662672, -0.072392916, -0.089123923,
      -0.093551415, -0.105782822, -0.117481560, -0.126549691, -0.141332587,
      -0.158428491, -0.166864452, -0.167363354, -0.177367386, -0.198326344,
      -0.218109541, -0.232391155, -0.237220250, -0.244477140, -0.255906978,
      -0.279480229)

#    Fit arima(p=1,d=2,q=1)
Arima <- arima(x, order = c(1,2,1))
Arima$coef

#    Simulate from the fitted model:
set.seed(1)
x.sim <- arima.sim(list(order = c(1,2,1), ar = Arima$coef[1], ma =
Arima$coef[2]), n = 1000, sd = sqrt(Arima$sig))
Arima2 <- arima(x.sim, order = c(1,2,1))
Arima2$coef

# We recover the ar and ma coefficients but we haven't included the drift
# in the simulation so the simulated series is well wide of the mark.  The
# following plots demonstrate how wide:
par(mfrow = c(1,2))
plot(ts(x), main = "Data")
plot(x.sim, main = "Simulated data")

# End demonstration program


The documentation for arima.sim() isn't terribly clear on this area.  Any
ideas?
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-include-trend-drift-term-in-arima-sim-tp2331581p2331581.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list