"adf"<- function(x, L = 2, int = T, trend = T) { #Construct Data for Augmented Dickey Fuller Model with L lags. #This is a modified version for R, in which the command rts was substituted by ts. x <- ts(x) D <- diff(x) if(L > 0) { for(i in 1:L) D <- ts.intersect(D, lag(diff(x), - i)) } D <- ts.intersect(lag(x, -1), D) if(trend == T) D <- ts.intersect(D, time(x)) y <- D[, 2] x <- D[, -2] if(int == T) summary(lm(y ~ x)) else summary(lm(y ~ x - 1)) }