6
votes

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
1
You may be able to use the argument xreg to add the extra columns. But you will need to supply example regressors for the forecast auto.arima(data, xreg=as.matrix(mydata[-1]))Pierre L
thanks for your comment, example regressors would be a value for, lets say, c2 one step ahead? and if so, c2 has to be forecasted or predicted as well? suppose this is maybe a better topic in the stats section..Deusdeorum
Yes. If you supplied a value for c2 and one for c3. You can add that matrix to the forecast. Remember, you are not forecasting all three columns, rather you are forecasting c1 based on time and c2 and c3. The time variable is inherently supplied, the others must be supplied by you.Pierre L
thanks, i might probably lack some theory here, the values of c2 and c3 one step ahead is supposed to be supplied by me but isn't the best way of picking c2 and c3 actually to forecast them separately and pick that value?Deusdeorum
You can do that. get a ts(c2) estimate and the same for c3. I've used that before.Pierre L

1 Answers

9
votes

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)