# arima fit forecast

can I ask i feel confused.. last fit==previous forecast?

    library(forecast)
model=arima(data[1:500],order=c(1,0,1)  , seasonal = c(1,1,1)   )
rev(fitted(model))[1] == rev( forecast(model, h = 1)$fitted)[1] #TRUE  its equal but modelb=arima(data[1:499],order=c(1,0,1) , seasonal = c(1,1,1) ,fixed=coef(model) ) predict(model, n.ahead=1 )$pred[1]


is different number

1. is this because im mixing arima with forecast library(Arima)
2. if i do "apply coefficients" on 1:499, i get forecast - but its different than latest fit of data[1:500].. (what does last fit represent?)

thanks

edit:

1. yes, it seems Arima from forecast library is working good (1:499 forecast==[1:500] latest fit[500] )
2. can I ask, why with arima 1:499 predict i get different value, than arima 1:500 fit latest value fit[500]

i tried add type response but didnt help predict(model, n.ahead=1,type="response") is there way how to achieve - predict arima 1:499 == latest fit arima 1:500?

i used latest fit data (1 newest value) from arima model (arima [1:500] fit), but i cant get work to predict/forecast them (predict arima [1:499] :-/

thanks alot

edit2:

reproducible example

### Code
library(forecast)

set.seed(20)

datat=c( arima.sim(list(order = c(1,1,1), ar = 0.7,ma=0.2), n = 50000)  )   #random data
dataa=ts(datat,frequency=1)

#modelb= Arima( (dataa[1:500]),order=c(1,1,1)   ,  seasonal = list( order =c(1,1,1), period = 1 )   )
modelb= Arima( (dataa[1:500]),order=c(2,2,4)    ,  seasonal = list( order =c(2,1,3), period = 1 )   )

print(summary(modelb) )

for(i in 4000:40000)
{

#  model= Arima((dataa[1:i]),order=c(1,1,1) ,  seasonal = list( order =c(1,1,1), period = 1 ),fixed=coef(modelb),model=modelb    )  #err in fixed length
#  model= Arima((dataa[1:i]),order=c(1,1,1) ,  seasonal = list( order =c(1,1,1), period = 1 ),fixed=coef(modelb)     )  #good
model= Arima((dataa[1:i]),order=c(2,2,4)  ,  seasonal = list( order =c(2,1,3), period = 1 ),fixed=coef(modelb)     )  #not good

#print(model)   #seems coeficients are good fixed
predikcia = forecast(model, h = 1)$$mean[1] predikcia2 =rev( forecast(model, h = 1)$$fitted)[1]

print("go")
print(predikcia2)
print(predikcia)
}


model 111 111 is working 100% accurate

[1] -72.99252
[1] -73.07326
[1] "go"
[1] -73.07326
[1] -79.43606
[1] "go"
[1] -79.43606
[1] -80.16272
[1] "go"
[1] -80.16272
[1] -77.33382


but model 224 213

[1] -96.95055
[1] -96.7422
[1] "go"
[1] -96.74245
[1] -97.82763
[1] "go"
[1] -97.82727
[1] -96.78442


those data are not the same. is there some way how to achieve 100% equality? thanks

//

when multiplying original data by 100, equality achieved :-)

solved (hope ^^)

fitted(model) and forecast(model, h=1)\$fitted both return fitted values from the training data. That is, they are one-step forecasts of the training data.
predict(model, n.ahead=1) is a forecast of the first time period beyond the training data.
If you want one-step forecasts of the training data, used fitted(). If you want forecasts beyond the training data, use forecast() or predict().