Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I've been using the ets() and auto.arima() functions from the forecast package to forecast a large number of univariate time series. I've been using the following function to choose between the 2 methods, but I was wondering if CrossValidated had any better (or less naive) ideas for automatic forecasting.

auto.ts <- function(x,ic="aic") {
    XP=ets(x, ic=ic) 
    AR=auto.arima(x, ic=ic)

    if (get(ic,AR)<get(ic,XP)) {
        model<-AR
    }
    else {
        model<-XP
    }
        model
}

/edit: What about this function?

auto.ts <- function(x,ic="aic",holdout=0) {
    S<-start(x)[1]+(start(x)[2]-1)/frequency(x) #Convert YM vector to decimal year
    E<-end(x)[1]+(end(x)[2]-1)/frequency(x)
    holdout<-holdout/frequency(x) #Convert holdout in months to decimal year
    fitperiod<-window(x,S,E-holdout) #Determine fit window

    if (holdout==0) {
        testperiod<-fitperiod
    }
    else {
        testperiod<-window(x,E-holdout+1/frequency(x),E) #Determine test window
    }

    XP=ets(fitperiod, ic=ic)
    AR=auto.arima(fitperiod, ic=ic)

    if (holdout==0) {
        AR_acc<-accuracy(AR)
        XP_acc<-accuracy(XP)
    }
    else {
        AR_acc<-accuracy(forecast(AR,holdout*frequency(x)),testperiod)
        XP_acc<-accuracy(forecast(XP,holdout*frequency(x)),testperiod)
    }

    if (AR_acc[3]<XP_acc[3]) { #Use MAE
        model<-AR
    }
    else {
        model<-XP
    }
    model
}

The "holdout" is the number of periods you wish to use as an out of sample test. The function then calculates a fit window and a test window based on this parameter. Then it runs the auto.arima and ets functions on the fit window, and chooses the one with the lowest MAE in the test window. If the holdout is equal to 0, it tests the in-sample fit.

Is there a way to automatically update the chosen model with the complete dataset, once it has been selected?

share|improve this question

1 Answer

up vote 7 down vote accepted

The likelihoods from the two model classes, and hence the AIC values, are not comparable due to different initialization assumptions. So your function is not valid. I suggest you try out the two model classes on your series and see which gives the best out-of-sample forecasts.

share|improve this answer
I've edited my question to include a function I wrote to do that. Does my new function make sense? – Zach Jan 19 '11 at 18:41
If holdout=0, it is using insample fit which will favour the model with more parameters. But if holdout>0, it makes sense, although you need quite a large holdout sample for the method to select the best model reliably. In general, I would choose the model to use based on other considerations rather than only consider the out-of-sample forecast performance on a short holdout sample from one series. For example, you could consider the out-of-sample performance across the whole ensemble of series (rather than one series at a time), and select the best model class that way. – Rob Hyndman Jan 22 '11 at 7:56
thanks for the suggestion, I'll start to move in that direction. In the case where my holdout equals zero what if I introduced some kind of penalty for parameters? – Zach Jan 24 '11 at 23:23
As I keep saying, use out-of-sample performance on a large set of series. You can't easily compare in-sample performance of the two model classes. – Rob Hyndman Jan 24 '11 at 23:47
Ok, thanks for all the advice. I'll use out-of-sample performance on the whole ensemble to choose a model class. – Zach Jan 25 '11 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.