1
$\begingroup$

I am testing several variables for unit roots via the ur.df (from urca package) and CADFtest (from CADFtest package) functions. Both packages have functions allow to select the optimal number of lags via information criteria. While the resulting number of lags is visible in the test output, I would like to store them as a factor (to later summarize the results for all variables in an output matrix). However, when I try using the slot function, the following errors come up:

urca (with a maximum of 14 lags and automatic lag order selection through the AIC):

x <- ur.df(myvar$var1, lags = 14, selectlags = "AIC")

=> x@lags = 14 (i.e. the maximum number of lags, although only 12 lags are used). If I don't include lags = 14, the automatic selection no longer works and x@lags = 1.

CADF (with a maximum of 14 lags and automatic lag order selection through the AIC):

x <- CADFtest(myvar$var1, max.lag.y = 14, criterion = "AIC")  

=> x@lags yields the error message

"Error: trying to get slot "lags" from an object (class "CADFtest") that is not an S4 object"

Is there a way to either fix the @lags slot for urca or implement a similar function for CADFtest?

$\endgroup$
1
$\begingroup$

The function CADFtest does not return S4 class object. It uses S3 classes, which in this case means that the result is a list with class attribute set to c("CADFtest","htest"). To see the names of the elements of this list use function names. You can access them either using $ or [[ notation. Probably x$max.lag.y is what you are looking for.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Wonderful!! Thank you so so much, mpiktas, that solves it!! $\endgroup$ – user95220 Nov 16 '15 at 7:57