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

2010-08-25 Thread StephenRichards

Thanks to Mark Leeds and Dennis Murphy for their suggestions.  The function
arima.sim() only simulates stationary series without a trend, so the best
approach appears to be to add the simulated stationary part to the trend as
follows:

  Temp <- arima.sim(n=N.Years.Forecast, list(ar=AR.Coef, ma=MA.Coef,
intercept=Intercept), sd=SD)
  if (1 == D.) Simulated.Kappa <- Trend + cumsum(Temp)
  if (2 == D.) Simulated.Kappa <- Trend + cumsum(cumsum(Temp))

This appears to work well for d=1 in an ARIMA(p,d,q) model, but less well
for d=2, where the results appear to be unstable.  The problem is that if
the forecast starts with two or three biggish values of the differences then
these seem to take over the forecast of Kappa.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-include-trend-drift-term-in-arima-sim-tp2331581p2337729.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2010-08-19 Thread StephenRichards

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.08121,  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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.