# How to choose number of lags for Zivot unit root test?

The fUnitRoots package considers lag=2 as the default value in the urzaTest() function (Zivot & Andrews unit root test), while for the ur.za() function in the urca package the default is lag=NULL.

What is the "criteria" to choose a good number of lags?

-

(instead of a comment) I would go for the minimization of information criteria either AIC or BIC, or any other just choose the parameter k other than 2 in AIC() function:

require(urca)
## An example from example(ur.za)
data(nporg)
gnp <- na.omit(nporg[, "gnp.r"])
za.gnp <- ur.za(gnp, model="both", lag=2)
AIC(eval(attributes(za.gnp)$testreg)) [1] 485.0148 BIC(eval(attributes(za.gnp)$testreg))
[1] 501.6351


For the efficient implementation you may consult on the stack-overflow, I think. A rough way to go is to run the for cycle, but it may be too slow.

-

The original Zivot Andrews paper uses lags to address serial correlation. The number of lags used is determined individually for each potential breakpoint. For each potential breakpoint ZA starts with a common maximum number of lags. For each potential breakpoint the number of lags is reduced sequentially until the longest lag is statistically significant. See ZA for full development.

If your routines are not varying the number of lags for each potential breakpoint then I suggest they are not following ZA. Suggest reading the ZA paper may be useful.

-