I have the following piece of code:
library(forecast)
set.seed(1234)
y <- ts(sort(rnorm(30)), start = 1978, frequency = 1) # annual data
fcasts <- numeric(10)
for (i in 1:10) { # start rolling forecast
# start from 1997, every time one more year included
win.y <- window(y, end = 1996 + i)
fit <- auto.arima(win.y)
fcasts[i] <- forecast(fit, h = 1)$mean
}
train <- window(y,end=1997)
fit<- auto.arima(train)
refit <- Arima(y, model=fit)
fc <- window(fitted(refit), start=1998)
I thought both should give same results, but why fcasts and fc give different results?