library(tseries) s <- 1:10 d <- diff(s) diffinv(d, xi = 1) x <- rnorm(1000) # no unit-root ts.plot(x) adf.test(x,k=2) y <- diffinv(x) # contains a unit-root ts.plot(y) adf.test(y,k=2) Thurman<-read.table("eggs.txt", header=T) year<-Thurman$year egg<-Thurman$egg chic<-Thurman$chic library(ts) year<-ts(year) chic<-ts(chic) egg<-ts(egg) "adf"<-function(x, L = 2, int = T, trend = T){ 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)) } adf(chic, L=1, int=T, trend=T) adf(chic, L=1, int=T, trend=F) adf(chic, L=1, int=F, trend=F) # use t-statistics but look up different tables