I have been trying to implement a forecasting model to perform multiple time series forecasting, I tried to start this with Holt Winters and ARIMA but I am coming across an error,
For Holt Winters the Error is :
Error in HoltWinters(x = df_timeseries[, i], seasonal = "multiplicative") : data must be non-zero for multiplicative Holt-Winters
So I moved it to Additive but then the error says predictions :
Error: object 'predictions1' not found
When I tried to forecast with ARIMA, there is a similar error:
Error: object 'predictions2' not found
I understand the issue is probably due to the fact that these two data frame are not created before but how do I create this, as I am not sure how the output will look like or even if the logic is correct? I was trying trail and error method to resolve figure out a solution.
Attaching the data frame for reference:
structure(list(Date = structure(c(17897, 17928, 17956, 17987,
18017, 18048, 18078, 18109, 18140, 18170, 18201, 18231, 18262,
18293, 18322, 18353, 18383, 18414, 18444, 18475, 18506, 18536,
18567, 18597, 18628, 18659, 18687, 18718, 18748, 18779, 18809,
18840, 18871, 18901, 18932, 18962, 18993, 19024, 19052, 19083,
19113, 19144, 19174, 19205, 19236), class = "Date"), `XYZ|419` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 791, 833, 478, 343, 543, 560, 427,
302, 391, 279, 405, 580, 824, 767, 1102, 1000, 1032, 668, 540,
477, 353, 427, 28, 2, 914, 718, 44, 0, 0, 0, 0, 0, 0, 0, 0),
`XYZ|426` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 29, 374, 330, 402, 1005, 1533, 1582, 1824, 1168, 193,
895, 613, 651, 267, 233, 135, 173, 564, 789, 343, 275, 383,
181, 96, 499, 53, 84, 23), `XYZ|465` = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 292, 240, 364, 806,
1110, 1232, 1207, 753, 571, 731, 0, 174, 0, 23, 86, 31, 559,
857, 316, 217, 182, 93, 50, 323, 42, 48, 23), `XYZ|489` = c(481,
179, 295, 187, 180, 78, 535, 164, 172, 340, 495, 445, 469,
230, 163, 187, 222, 147, 154, 140, 194, 379, 402, 533, 659,
545, 269, 277, 187, 4, 80, 149, 129, 192, 396, 446, 0, 0,
0, 0, 0, 0, 0, 0, 0), `XYZ|457` = c(181, 80, 74, 150, 665,
187, 335, 238, 149, 281, 696, 440, 619, 349, 310, 396, 251,
202, 165, 176, 166, 249, 167, 364, 411, 327, 326, 396, 6,
107, 177, 136, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA,
-45L), class = c("tbl_df", "tbl", "data.frame"))
Can someone help me out and tell me if this is even possible or what corrections to make so that I can have a decent forecast.
library(dplyr)
library(tidyr)
library(tidyverse)
library(forecast)
library(lubridate)
library(readxl)
setwd("C:/")
df <- read_xlsx("C:/X.xlsx")
#Convert the date from Char to Date with Lubridate, YMD means the data is in the form Year,Month,Date
df$Date <- ymd(df$Date)
str(df$Date)
#Convert our data into time series, give the start date, end date and set frequency as month.
df_timeseries <- ts(data = df[-1],
start = 2019,
end = 2022,
frequency = 12)
plot.ts(df_timeseries)
for(i in 1:ncol(df_timeseries))
{
HW_model = HoltWinters(x=df_timeseries[,i],
seasonal = "additive")
predictions1[,i] = forecast(HW_model,
h=length(12))
}
for(i in 1:ncol(df_timeseries))
{
SMAX_model = auto.arima(y=df_timeseries[,i],
stepwise = FALSE,
approximation = FALSE)
predictions2[,i] = forecast(SMAX_model,
h=length(12))
}
plot(predictions1)
plot(predictions2)