Reputation: 78
I am wondering if there is a way to choose the optimal number of the lags in the dynlm package given a criterion such as AIC.
For example, I have the following equations:
fit = dynlm(y ~ L(y,1)+ L(x,1)
fit = dynlm(y ~ L(y,1)+ L(x,1)+ L(x,2)
fit = dynlm(y ~ L(y,1)+ L(x,1)+ L(x,2)+ L(x,3)
fit = dynlm(y ~ L(y,1)+ L(x,1)+ L(x,2)+ L(x,3)+ L(x,4))
Do I have to create a do loop and generate which equation and pull the AIC? Anyone is familiar with an automatic way?
Thanks,
Upvotes: 0
Views: 1178
Reputation: 269694
To compare the AIC of two models they must have the same response but that is not the case in your situation because adding a lag will reduce the set of y's that are fit.
The dyn package has an anova.dyn
method which compares lagged models created by that package automatically subsetting the longer series to ensure that the series can be validly compared.
Upvotes: 3