1

I have a gold price data set with "DATE" and "GOLD PRICE" variables.After doing all the pre processing steps in R,I convert the data frame object to time series by ts or xts function and check for stationary through adf test.

Now by enabling forecast library I run auto.arima function and forecast next ten values.

x <- "DATE"         "GOLD PRICE"
      01-01-2006        1326

x.xts <- xts(x$GOLD PRICE,X$DATE),
fit <- auto.arima(x.xts)
forecast <- forecast(fit,h=10)

Now when I plot the forecast I get some values plotted in x instead of actual dates.I am able to get the date from x.xts through index(x.xts). But I want to extract it from forecast to get it plotted in graph for better understanding.

Someone please help me through this with the R codes.

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
Jennifer Therese
  • 1,105
  • 9
  • 17

1 Answers1

1

You need to explicitly note the date when creating the ts (or xts) object. Using a reproducible example:

library("forecast")
data("gas") 
# gas is already a TS object. 
# We remove it and recreate it to show the appropriate method
gas2 <- vector(gas); rm(gas)
gas <-  ts(gas2, start= c(1956,1), frequency= 12)
fit <- auto.arima(gas)
forecast(fit, h= 10)
         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
Sep 1995       57178.66 54885.61 59471.71 53671.74 60685.58
Oct 1995       53080.77 50466.09 55695.46 49081.96 57079.59
Nov 1995       50940.76 48086.64 53794.87 46575.77 55305.75
Dec 1995       40923.84 37931.85 43915.84 36347.99 45499.70
Jan 1996       43739.23 40654.37 46824.09 39021.35 48457.12
Feb 1996       43706.56 40557.77 46855.34 38890.91 48522.20
Mar 1996       47849.24 44653.96 51044.52 42962.48 52736.00
Apr 1996       50204.88 46974.32 53435.44 45264.16 55145.60
May 1996       56691.41 53432.91 59949.91 51707.96 61674.86
Jun 1996       61053.42 57771.93 64334.92 56034.81 66072.04
alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
  • fit_forecast <- forecast(auto.arima(ts),h=10) > fit_forecast Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 238896001 1207.494 1189.010 1225.977 1179.226 1235.761 238982401 1207.737 1181.598 1233.876 1167.761 1247.714 239068801 1207.981 1175.967 1239.995 1159.020 1256.942 Here I get the forecast but the dates are not explicit. I want the dates as in your example instead of values. – Jennifer Therese Nov 28 '16 at 07:19
  • @JenniferTherese Welcome to SO! Please edit your OP to provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – alexwhitworth Nov 28 '16 at 17:17