简体   繁体   中英

R dynlm package - Choosing the optimal lag number

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM