1

When plotting fitted ARIMA results on the original data, the fitted values sometimes appear off by one timestep:

library(forecast)
set.seed(1)
#simualted ts
eg <- arima.sim(n = 100, list(order = c(1,1,2), ar =  -0.5, ma = c(.1, -0.3)),
                sd = 1)
#fitted Arima with same order
eg_aa <- forecast::Arima(eg, order = c(1,1,2))

par(mfrow = c(2,1),
    oma = c(0,0,0,0), 
    mar = c(2,4,1,1))
plot(eg,  main="as-is") # plot original sim
lines(fitted(eg_aa), col = "red") # plot fitted values
legend("topleft", legend = c("original","fitted"), col = c("black","red"),lty = 1)

plot(eg, main = "time-deltat") # plot original sim
points(time(fitted(eg_aa))-deltat(eg), # plot fitted values shifted back one time-step
       fitted(eg_aa),
       type = "l", col = "red")

the plot

but not always, the fitted values line up in this example: in-r-plot-arima-fitted-model-with-the-original-series

From what I remember from my timeseries class, a once differenced model should only have fits for the observations after the first, so I am not clear where arima() gets the t=1 fit. but most of all I want to know if the apparent time-shift is a bug or just an odd outcome of the arima model. Any ideas?

Community
  • 1
  • 1
  • Did you do `factor` on a 0 based item? – IRTFM Jan 11 '18 at 01:34
  • @42- Thanks for answering. No? I did not call `factor` on anything. Unless that happens within a function. But I don't know what you mean by "0 based item", so perhaps I did. – Chris McCort Jan 12 '18 at 17:26
  • Any character vector is implicitly coerced to factor with a call to data.frame, but in this case I think you are probably complaining about the shift that is induced when you apply `diff` to a vector of numeric values. It's always a bit arbitrary what one uses to pad the beginning of the sequence, so it may not even get padded. I suspect if you pay attention to this phenomena in the future, that you will find it related to the choice of the `p,d,q` specifications. – IRTFM Jan 12 '18 at 19:04
  • @42- Thank you again. Oh, yes I am familiar with the coercion to factor. Yes, sorry my original question was not clear enough, it was to do with the shift. I suspected it had to do with the differencing in the model, but in the other example I found it is also differenced. From what I remember from my timeseries class, a once differenced model should only have fits for the observations after the first, so I am not entirely clear where `arima()` gets the `t=1` fit. but most of all I want to know if the apparent time-shift is a bug or just an odd outcome of the arima model. – Chris McCort Jan 12 '18 at 19:49
  • You claim that one series shows a backward shift and the other does not. I claim they both show the same sort of lag for the fitted values. – IRTFM Jan 12 '18 at 22:01

0 Answers0