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$

closed as off-topic by mpiktas, John, Sven Hohenstein, Nick Cox, Peter Flom Nov 16 '15 at 11:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mpiktas, John, Sven Hohenstein, Nick Cox, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

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.

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