Suppose i have some time series as below and i want to forecast c1
one step a head, doing so is pretty straight forward and easy in R:
testurl = "https://docs.google.com/spreadsheets/d/1jtpQaSxNY1V3b-Xfa5OJKDCLE6pNlzTbwhSHByei4EA/pub?gid=0&single=true&output=csv"
test = getURL(testurl)
mydata = read.csv(textConnection(test), header = TRUE)
data <- ts(mydata['c1'])
fit <- auto.arima(data)
fcast <- forecast(fit)
fcast
note that the numbers is just random numbers, and the auto.arima suggest us to use an arima(0,1,0)
and the forecast one step a head is 52.
however, what if one want to use c2
and c3
to improve (in terms of aic and bic for example) the out of sample forecast? how would one actually continue then?
c1 c2 c3
40 0,012 1
41 0,015 1
42 0,025 1
40 −0,015 1
44 0,000 0
50 0,015 0
52 0,015 1
51 0,020 1
50 0,025 1
52 0,030 0
53 0,045 1
52 0,030 1
52 0,025 0
52 0,000 0
51 0,010 0
50 −0,02 1
48 −0,025 1
49 −0,030 1
51 −0,040 1
52 −0,350 0
If I understand correctly you're trying to fit a dynamic regression model to your data with xreg
in auto.arima()
. You can automatically determine a model fit using something like this:
tsdata <- ts(mydata)
fit <- auto.arima(tsdata[,1], xreg = as.matrix(mydata[,2:3]))
To generate your 1-step ahead forecast you will need to supply a matrix
of future values of C2
and C3
to the xreg
argument in the forecast function. One way you could do this would be like this:
fc.c2 <- forecast(tsdata[,2], h = 1)
fc.c3 <- forecast(tsdata[,3], h = 1)
newxreg <- as.matrix(cbind(fc.c2$mean, fc.c3$mean))
fc.c1 <- forecast(fit, xreg = newxreg)