Problem with date formats in fortify (Arima model)

265 Views Asked by At

Hi and thanks for reading me.

I am working with an ARIMA model and I would like to convert the model to a DataFrame and then export it together with the database, but the date format is not correct. Dates should be in the format: "yyyy-mm-dd". For example, im getting "2007.000" instead "2007-01-03". Is there a way to fix it?

The codes im using are the following:

library(ggplot2)
library(quantmod)
library(forecast)

getSymbols("GOOG")
data <-  as.data.frame(GOOG) |> 
  tibble::rownames_to_column("Fecha") 
ts_data <- ts(data$GOOG.Close, start = 2007, frequency = 365)
d.arima <- forecast::auto.arima(ts_data)
d.forecast <- forecast::forecast(d.arima, level = c(95), h = 50)
data <- fortify(d.forecast, ts.connect = TRUE)

I would expect the table (and date format) to look like this:

head(data)

 "|    Index  |      Data|    Fitted| Point Forecast|     Lo 95|    Hi 95|"
 "|----------:|---------:|---------:|--------------:|---------:|--------:|"
 "| 2007-01-03|  232.9220|  232.8178|             NA|        NA|       NA|"
 "| 2007-01-04|  240.7277|  241.0227|             NA|        NA|       NA|"
 "| 2007-01-05|  242.6853|  247.0522|             NA|        NA|       NA|"
 "| 2007-01-06|  240.8871|  247.0309|             NA|        NA|       NA|"

But instead of this I get the following:

head(data)

 "|    Index|      Data|    Fitted| Point Forecast|     Lo 95|    Hi 95|"
 "|--------:|---------:|---------:|--------------:|---------:|--------:|"
 "| 2007.000|  232.9220|  232.8178|             NA|        NA|       NA|"
 "| 2007.003|  240.7277|  241.0227|             NA|        NA|       NA|"
 "| 2007.005|  242.6853|  247.0522|             NA|        NA|       NA|"
 "| 2007.008|  240.8871|  247.0309|             NA|        NA|       NA|"

Thanks for the help

0

There are 0 best solutions below