0
$\begingroup$

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

can i ask

  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 ^^)

$\endgroup$

1 Answer 1

1
$\begingroup$

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.

See https://otexts.com/fpp2/residuals.html for a discussion of fitted values.

If you want one-step forecasts of the training data, used fitted(). If you want forecasts beyond the training data, use forecast() or predict().

$\endgroup$
3
  • $\begingroup$ Thank you. I found, on some data and specific model arima, one latest fit value [1:500] isnt the same as prediction from [1:499]. tried with Arima model (fit and forecast) and is working 100% properly.. so I guess its a bug on arima since if I cant create predictions to be equals fit, its surprising behavior ..but I tested it multiple times and cant achieve that arima fit (which was suspicious good ^^ pitty its a bug $\endgroup$
    – user2120
    Mar 9, 2021 at 11:28
  • $\begingroup$ I tried a little and was able to reproduce mini inaccuracy - edit (edit 2) was added to original with reproducible example. $\endgroup$
    – user2120
    Mar 9, 2021 at 19:09
  • $\begingroup$ sorry, when multiplying original data by 100, equality achieved :-) sorry for spam, but thanks :-) $\endgroup$
    – user2120
    Mar 9, 2021 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.