MATLAB: Need help with complicated loop to create several different models

aicarbicconfigurationlagsloop

Hey everyone,
I am creating an AR model and I want to calculate the AIC and BIC for each different possible configuration of the model. Over all 24 lags are possible. So I want to calculate the AIC and BIC for all included lags starting with ARLag = 1, ARLag=2, ARLag=3 …. ARLag=24, I also want the AIC and BIC for all models as ARLag=1:2, ARLag=1:3…., ARLag 1:24… ok and now the really complicated part: I want the AIC and BIC for all combinations of Lags like ARLag=[1 3], ARLag=[1 4]…ARLag=[1 24], ARLag=[1 2 4], … ARLag=[1 2 24] etc. So basically I want to know the AIC and BIC for each possible combination of lags so that I can choose the model with the minimal AIC and BIC!
Does anyone have an idea how I could do this??

Best Answer

Don't do it the complicated way. Use the AIC and the BIC only to find the model order, i.e. the highest lag of the model.
for p = 1 : 24
% estimate a Model with order p
ARLag = 1 : p;
next p
Calculate the AIC and the BIC and then choose the model order p. Afterwards do the fine tuning. Estimate the AR(p) model and exclude lags if the coefficients are not significant. Re-estimate the model until all coefficients are significant. The AIC and BIC are not needed to find out if the lags 1 to p-1 are part of the model.
And don't forget to check the residuals. If they exhibit autocorrelation the t-statistics is not valid and your model may not be appropriate.