R: Augmented Dickey Fuller (ADF) test I'm having a problem with the Dickey-Fuller p-values and test statistic for unit root test in R. I tried using functions:
urca::ur.df()
fUnitRoots::adfTest()
tseries::adf.test()

All of them showed different results for the same test settings (lag, type) compared to the gretl output.
For example:
set.seed(1)
x <- rnorm(50, 0, 3)
schwert.param <- trunc(12 * (length(na.omit(x)) / 100) ^ (1 / 4))
adfTest(x = na.omit(x), lags = schwert.param, type = "nc", title = NULL, description = NULL)

# Title:
# Augmented Dickey-Fuller Test
# 
# Test Results:
# PARAMETER:
# Lag Order: 10
# STATISTIC:
# Dickey-Fuller: -2.4362
# P VALUE: 0.01749 

And for the same vector x in gretl I got:
>     Test statistic: tau_nc(1) = -4.03652 
>     Asymptotic p-value = 5.57e-005

Both test settings were without constant and trend, lags = 10. So, why I'm getting different result for the same data input. I know, Dickey-Fuller test is using Monte Carlo to obtain p-values for test statistic, but shuld they differ that much, or I'm doing sth wrong with that function in R?

@ChristophHanck @GraemeWalsh:
Ok, probably I found what's going on here. First of all, I changed gretl language from polish to english, and I found there is an option checked by default in the ADF test window - "test down from maximum lag order" using Akaike information criterion. If I uncheck that option I'm going to get the same results as in R.
Now I'd like to know how to use that option in R. Does anybody know how to do that?
 A: I didn't try to replicate the problems with gretl but at least the R packages you mention seem to agree if both the deterministics (trend vs. constant aka drift vs. none) and the lags (fixed, information criteria, heuristics) are specified in the same way. There are differences in the way the p-values are computed but for the data x you generated they are very similar.
I have written the overview below for my students and thought I could share it here if someone finds it useful. Personally, I mostly used tseries and CADFtest:


*

*adf.test() in tseries.
Deterministics: Linear trend only.
Lags: Heuristic by default, but can be selected by the user.
P-value: From critical value table.

*CADFtest() in CADFtest.
Deterministics: Trend by default, constant (aka drift) or none also supported.
Lags: Default is 1 but can be selected via information criteria or by the user.
P-value: Computation based on Costantini et al. (2007). See also Lupi (2009). Unit Root CADF Testing with R. Journal of
Statistical Software, 32 (2), 1-19. http://www.jstatsoft.org/v32/i02/.
Comments: Additional regressors (and their lags) can be added to auxiliary
regression.

*ur.df() in urca.
Deterministics: None by default, constant and trend also supported.
Lags: Default is 1, but can be selected via information criteria or by the user.
P-value: None, but summary() reports critical value table (1%, 5%, 10%).

*adfTest() in fUnitRoots.
Deterministics: None by default, constant and trend also supported.
Lags: Default is 1, but can be selected by the user.
P-value: From critical value table.
Comments: Based on adf.test() from tseries but extended by
additional deterministics.


For the data you had generated:

set.seed(1)
x <- rnorm(50, 0, 3)

Let's look at the different results for the test with trend (because this is supported by all functions) and 10 lags (as suggested by your heuristic above). The test statistics is always exactly the same and the p-values are close.

tseries::adf.test(x, k = 10)
##         Augmented Dickey-Fuller Test
## 
## data:  x
## Dickey-Fuller = -1.6757, Lag order = 10, p-value = 0.7044
## alternative hypothesis: stationary

library("CADFtest")
CADFtest(x, max.lag.y = 10, type = "trend")
##         ADF test
## 
## data:  x
## ADF(10) = -1.6757, p-value = 0.743
## alternative hypothesis: true delta is less than 0
## sample estimates:
##     delta 
## -1.751283 

urca::ur.df(x, lags = 10, type = "trend")
## ############################################################### 
## # Augmented Dickey-Fuller Test Unit Root / Cointegration Test # 
## ############################################################### 
## 
## The value of the test statistic is: -1.6757 1.3699 2.0189 

fUnitRoots::adfTest(x, lags = 10, type = "ct")
## Title:
##  Augmented Dickey-Fuller Test
## 
## Test Results:
##   PARAMETER:
##     Lag Order: 10
##   STATISTIC:
##     Dickey-Fuller: -1.6757
##   P VALUE:
##     0.7044 
## 
## Description:
##  Sat Aug 22 20:19:18 2015 by user: zeileis

