# 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()


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?

• Interesting. I can't determine why there are differences off-hand, but it might be worth stepping into each function to see exactly what's going on. I done something similar in response to this question. Typically, code for these functions straightforward, so if you eyeball them the answer might be sticking out. Hope my suggestion helps. Aug 22, 2015 at 14:49
• I know, but I can't get into the code in gretl to see differences. Even KPSS test output from R is much different than the gretl test output... Aug 22, 2015 at 14:57
• I thought gretl was open!? In any case, I pinged a maintainer for you, so hopefully he can provide an answer. Aug 22, 2015 at 16:02
• @GraemeWalsh: It's open source. But I don't know how to dig in to that code. Fortunately, found some code my teacher wrote with ADF test. I'll get into and improve that code. Then I'll post that if it will be similar to the gretl output. Aug 22, 2015 at 16:08
• there's the t-statistic $(\hat\rho-1)/s.e.(\hat\rho)$ and the coefficient statistic $T(\hat\rho-1)$ - does Gretl maybe use the latter? Aug 22, 2015 at 17:28

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/.
• 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

CADFtest(x, max.lag.y = 10, type = "trend")
##
## 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