22

I was using GRETL. There, when I do the forecasting for the validation of the arima model, I will get the fitted series in blue line and the original series in red line. Later, I switched to R and here I could not find any command to do the same. I am using Arima model from forecast package.

details,

In GRETL I use to do model->time series -> arima -> forecast. It will automatically print the fitted and the original series. Any idea to do the same on R?

Pankaj Parag
  • 437
  • 1
  • 6
  • 17

2 Answers2

46

This question is fairly open ended, but here is a very, very basic answer. Starting directly from one of the examples provided in the help files for Arima in the forecast package:

fit <- Arima(WWWusage,order=c(3,1,0))

You say you want the original series in red and the fitted series in blue:

plot(fit$x,col="red")
lines(fitted(fit),col="blue")

which produces a plot that looks something like this:

arima

joran
  • 169,992
  • 32
  • 429
  • 468
  • 16
    The last comment is a little unfair - it's not really that basic a question. Your answer is hardly info you'll find in the intro, and the structure of an Arima model object is pretty complex. – naught101 May 09 '12 at 06:57
  • @naught101 Maybe. On the other hand, I managed to answer the question and I know basically nothing about Arima models and had never even installed the forecast package before. – joran May 09 '12 at 14:15
  • 2
    Perhaps, but Arima should be arima, fitted(fit) returns NULL, and fit$x doesn't exist. – user1244215 Nov 20 '12 at 22:25
  • @user1244215 I don't know what you're talking about. This code runs just as I describe it. (I just re-checked.) – joran Nov 20 '12 at 22:30
  • 1
    @user1244215 you need to load the forecast library. – scai Jul 11 '16 at 18:55
  • 1
    @joran can you add forecast line to this plot? – ali srn Aug 02 '16 at 06:29
18

The differences you are finding are because the arima() function is different from the Arima() function. The former is contained in the basis stats package, the lattercomes from the package forecast and includes the fitted() function to predict over the observed values.

UseR10085
  • 7,120
  • 3
  • 24
  • 54
paul
  • 181
  • 1
  • 2