2
votes

I am having problems with a time series plot in R. More specifically one with predictions on it.

Here's the data set, it's meteorological data taken from the Central England temperature (CET) data set. I have cut it to just include the last 6 years, and contains monthly average temperatures.

Year JAN FEB MAR  APR  MAY  JUN  JUL  AUG  SEP  OCT NOV  DEC
2007 7.0 5.8 7.2 11.2 11.9 15.1 15.2 15.4 13.8 10.9 7.3  4.9
2008 6.6 5.4 6.1  7.9 13.4 13.9 16.2 16.2 13.5  9.7 7.0  3.5
2009 3.0 4.1 7.0 10.0 12.1 14.8 16.1 16.6 14.2 11.6 8.7  3.1
2010 1.4 2.8 6.1  8.8 10.7 15.2 17.1 15.3 13.8 10.3 5.2 -0.7
2011 3.7 6.4 6.7 11.8 12.2 13.8 15.2 15.4 15.1 12.6 9.6  6.0
2012 5.4 3.8 8.3  7.2 11.7 13.5 15.5 16.6 13.0  9.7 6.8  4.8

However, my data set doesn't have a year column, it's just listing 1-6 as row names as I'm having problems with it.

Now I've used the arima() function, the data set is called data

m <- arima(data, order = c(2, 0, 0), seasonal = list(order = c(1, 0, 0)))

I have used other numbers in the seasonal part, but this gives the lowest AIC.

I then used

pm <- predict(m, n.ahead = 12, se.fit = TRUE)

ts.plot(cbind(f, pm$pred, pm$pred-2*pm$se, pm$pred+2*pm$se), col = ("black", "black", "red", "red"))

This should produce a time series plot with 95% prediction intervals for this particular model.

However, I'm receiving this error:

Error in xy.coords(x = matrix(rep.int(tx, k), ncol = k), y = x, log = log) : 
  (list) object cannot be coerced to type 'double'

Any help/suggestions would be greatly appreciated.

1

1 Answers

9
votes

Install the forecast package. It provides a forecast method that calculates intervals, and a plot method for that.

install.packages("forecast")
library(forecast)
pm <- forecast(m, h=12)
plot(pm)