Time series forecasting including a variable

HI all,

I have my data as below:

I have Date, Category and Qty in my data.
Category has n different types.

Although i'm able to forecast Qty, using just Date.
I would want to include Category in the forecast, so i do not have to load n different files to separate one category at a time.
I'm new to R and any guidance is highly appreciated.
Please advise.

Date Category Qty
1/1/2019 A 123
1/2/2019 A 345
1/3/2019 A 123
1/4/2019 A 555
1/5/2019 A 756
1/6/2019 A 128
1/7/2019 A 192
1/8/2019 A 106
1/9/2019 A 113
1/10/2019 A 140
1/1/2019 B 234
1/2/2019 B 564
1/3/2019 B 568
1/4/2019 B 879
1/5/2019 B 453
1/6/2019 B 321
1/7/2019 B 345
1/8/2019 B 654
1/9/2019 B 675
1/10/2019 B 142
1/1/2019 C 978
1/2/2019 C 984
1/3/2019 C 901
1/4/2019 C 993
1/5/2019 C 876
1/6/2019 C 566
1/7/2019 C 599
1/8/2019 C 920
1/9/2019 C 856
1/10/2019 C 517

Could you please post a Reproducible Example of the method you are using now? That will make it much easier to help you.

1 Like

HI,
Below is what i'm using without including 'category' variable.
I would want to do a time series forecast with category variable included as above sample data set mentioned.

Y <- ts(df[,2], start = c(2019,2), frequency = 330)

fit_arima <- auto.arima(Y,d=1, stepwise = FALSE, approximation = FALSE, trace = TRUE)
print(summary(fit_arima))
checkresiduals(fit_arima)

fcst <- forecast(fit_arima, h=7)
autoplot(fcst)
print(summary(fcst))

Hi all,
I'm trying to use Time series forecast for multiple columns at the same time...
Using below code..But it is giving same value for all future dates. Can someone please help?
Original data:

Date Category Qty
1/1/2019 A 123
1/2/2019 A 345
1/3/2019 A 123
1/4/2019 A 555
1/5/2019 A 756
1/6/2019 A 128
1/7/2019 A 192
1/8/2019 A 106
1/9/2019 A 113
1/10/2019 A 140
1/1/2019 B 234
1/2/2019 B 564
1/3/2019 B 568
1/4/2019 B 879
1/5/2019 B 453
1/6/2019 B 321
1/7/2019 B 345
1/8/2019 B 654
1/9/2019 B 675
1/10/2019 B 142
1/1/2019 C 978
1/2/2019 C 984
1/3/2019 C 901
1/4/2019 C 993
1/5/2019 C 876
1/6/2019 C 566
1/7/2019 C 599
1/8/2019 C 920
1/9/2019 C 856
1/10/2019 C 517

library(forecast)
library(fpp2)
View(df1)

#reshape and convert it to a proper time-series format like ts:
tsMat <- ts(reshape2::dcast(df1, Date~Category))
tsMat
View(tsMat)
output <- lapply(tsMat, function(x) forecast(auto.arima(x)))
lapply(tsMat, function(x) forecast(auto.arima(x),h=5))

Hi @brad5,

You might find that the xreg parameter to auto.arima() is what you are looking for. Take a look at this thread.

Andrew.

You may also use the feed-forward neural network using the nnetar() function in the forecast package. It has the option for xreg parameter.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.