Function forecast()
produces list. With function str()
you can check structure of this object and with function names()
see the names of each element in this list.
library(forecast)
fit <- Arima(WWWusage,c(3,1,0))
test1<-forecast(fit)
names(test1)
[1] "method" "model" "level" "mean" "lower" "upper" "x"
[8] "xname" "fitted" "residuals"
#to extract forecast
test1$mean
Time Series:
Start = 101
End = 110
Frequency = 1
[1] 219.6608 219.2299 218.2766 217.3484 216.7633 216.3785 216.0062 215.6326 215.3175 215.0749
#or as vector
as.vector(test1$mean)
[1] 219.6608 219.2299 218.2766 217.3484 216.7633 216.3785 216.0062 215.6326 215.3175 215.0749
#to extract upper interval
test1$upper
80% 95%
[1,] 223.5823 225.6582
[2,] 228.5332 233.4581
[3,] 232.7151 240.3585
.... .... ....
[10,] 260.7719 284.9625
#to extract lower interval
test1$lower
#to extract only 95% upper interval
test1$upper[,2]