## Function

Code
• methods {utils}
function (x, alternative = c("stationary", "explosive"), k = trunc((length(x) -
1)^(1/3)))
{
if ((NCOL(x) > 1) || is.data.frame(x))
stop("x is not a vector or univariate time series")
if (any(is.na(x)))
stop("NAs in x")
if (k < 0)
stop("k negative")
alternative <- match.arg(alternative)
DNAME <- deparse(substitute(x))
k <- k + 1
x <- as.vector(x, mode = "double")
y <- diff(x)
n <- length(y)
z <- embed(y, k)
yt <- z[, 1]
xt1 <- x[k:n]
tt <- k:n
if (k > 1) {
yt1 <- z[, 2:k]
res <- lm(yt ~ xt1 + 1 + tt + yt1)
}
else res <- lm(yt ~ xt1 + 1 + tt)
res.sum <- summary(res)
STAT <- res.sum$coefficients[2, 1]/res.sum$coefficients[2,
2]
table <- cbind(c(4.38, 4.15, 4.04, 3.99, 3.98, 3.96), c(3.95,
3.8, 3.73, 3.69, 3.68, 3.66), c(3.6, 3.5, 3.45, 3.43,
3.42, 3.41), c(3.24, 3.18, 3.15, 3.13, 3.13, 3.12), c(1.14,
1.19, 1.22, 1.23, 1.24, 1.25), c(0.8, 0.87, 0.9, 0.92,
0.93, 0.94), c(0.5, 0.58, 0.62, 0.64, 0.65, 0.66), c(0.15,
0.24, 0.28, 0.31, 0.32, 0.33))
table <- -table
tablen <- dim(table)[2]
tableT <- c(25, 50, 100, 250, 500, 1e+05)
tablep <- c(0.01, 0.025, 0.05, 0.1, 0.9, 0.95, 0.975, 0.99)
tableipl <- numeric(tablen)
for (i in (1:tablen)) tableipl[i] <- approx(tableT, table[,
i], n, rule = 2)$y interpol <- approx(tableipl, tablep, STAT, rule = 2)$y
if (!is.na(STAT) && is.na(approx(tableipl, tablep, STAT,
rule = 1)\$y))
if (interpol == min(tablep))
warning("p-value smaller than printed p-value")
else warning("p-value greater than printed p-value")
if (alternative == "stationary")
PVAL <- interpol
else if (alternative == "explosive")
PVAL <- 1 - interpol
else stop("irregular alternative")
PARAMETER <- k - 1
METHOD <- "Augmented Dickey-Fuller Test"
names(STAT) <- "Dickey-Fuller"
names(PARAMETER) <- "Lag order"
structure(list(statistic = STAT, parameter = PARAMETER, alternative = alternative,
p.value = PVAL, method = METHOD, data.name = DNAME),
class = "htest")
}
<bytecode: 0x0000000025588fc8>
<environment: namespace:tseries>

Help
• tools:::Rd2HTML
• utils:::.getHelpFile

## Augmented Dickey–Fuller Test

### Description

Computes the Augmented Dickey-Fuller test for the null that x has a unit root.

### Usage

adf.test(x, alternative = c("stationary", "explosive"),
k = trunc((length(x)-1)^(1/3)))


### Arguments

 x a numeric vector or time series. alternative indicates the alternative hypothesis and must be one of “stationary” (default) or “explosive”. You can specify just the initial letter. k the lag order to calculate the test statistic.

### Details

The general regression equation which incorporates a constant and a linear trend is used and the t-statistic for a first order autoregressive coefficient equals one is computed. The number of lags used in the regression is k. The default value of trunc((length(x)-1)^(1/3)) corresponds to the suggested upper bound on the rate at which the number of lags, k, should be made to grow with the sample size for the general ARMA(p,q) setup. Note that for k equals zero the standard Dickey-Fuller test is computed. The p-values are interpolated from Table 4.2, p. 103 of Banerjee et al. (1993). If the computed statistic is outside the table of critical values, then a warning message is generated.

Missing values are not allowed.

### Value

A list with class “htest” containing the following components:

 statistic the value of the test statistic. parameter the lag order. p.value the p-value of the test. method a character string indicating what type of test was performed. data.name a character string giving the name of the data. alternative a character string describing the alternative hypothesis.

A. Trapletti

### References

A. Banerjee, J. J. Dolado, J. W. Galbraith, and D. F. Hendry (1993): Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford.

S. E. Said and D. A. Dickey (1984): Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order. Biometrika 71, 599–607.

pp.test
x <- rnorm(1000)  # no unit-root