user1943079
user1943079

Reputation: 523

How to plot model with forecasts in R?

I recently upgraded R from 2.x to 3.1 and I feel like there were some changes that I am not aware of with regards to plotting models.

airpass_model = arima(log(AirPassengers) , order=c(0,1,1),
  seasonal=list(order=c(0,1,1), period=12))
plot(airpass_model, n1=c(1969, 1), n.ahead=24, pch=19, ylab='Log(Air Passengers)')

I get the following error after executing the second line. It'd be great if anyone could explain why?

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

Upvotes: 1

Views: 223

Answers (1)

Stephan Kolassa
Stephan Kolassa

Reputation: 8267

Better to use the Arima() function in the forecast library and then call forecast before plotting:

library(forecast)
airpass_model = arima(log(AirPassengers) , order=c(0,1,1),
  seasonal=list(order=c(0,1,1), period=12))
plot(forecast(airpass_model,h=24), pch=19, ylab='Log(Air Passengers)')

airpass

After all, when you talk about "plotting a model", you could be talking about plotting ACF/PACF or a lot of other information.

Finally, this may be enlightening - very much recommended.

Upvotes: 2

Related Questions