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")
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?