G01EWF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01EWF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G01EWF returns the probability associated with the lower tail of the distribution for the Dickey–Fuller unit root test statistic.

## 2  Specification

 FUNCTION G01EWF ( METHOD, TYPE, N, TS, NSAMP, STATE, IFAIL)
 REAL (KIND=nag_wp) G01EWF
 INTEGER METHOD, TYPE, N, NSAMP, STATE(*), IFAIL REAL (KIND=nag_wp) TS

## 3  Description

If the root of the characteristic equation for a time series is one then that series is said to have a unit root. Such series are nonstationary. G01EWF is designed to be called after G13AWF and returns the probability associated with one of three types of (augmented) Dickey–Fuller test statistic: $\tau$, ${\tau }_{\mu }$ or ${\tau }_{\tau }$, used to test for a unit root, a unit root with drift or a unit root with drift and a deterministic time trend, respectively. The three types of test statistic are constructed as follows:
1. To test whether a time series, ${y}_{t}$, for $\mathit{t}=1,2,\dots ,n$, has a unit root the regression model
 $∇yt = β1 yt-1 + ∑ i=1 p-1 δi ∇ yt-i +εt$
is fit and the test statistic $\tau$ constructed as
 $τ = β^1 σ11$
where $\nabla$ is the difference operator, with $\nabla {y}_{t}={y}_{t}-{y}_{t-1}$, and where ${\stackrel{^}{\beta }}_{1}$ and ${\sigma }_{11}$ are the least squares estimate and associated standard error for ${\beta }_{1}$ respectively.
2. To test for a unit root with drift the regression model
 $∇yt = β1 yt-1 + ∑ i=1 p-1 δi ∇ yt-i +α +εt$
is fit and the test statistic ${\tau }_{\mu }$ constructed as
 $τμ = β^1 σ11 .$
3. To test for a unit root with drift and deterministic time trend the regression model
 $∇yt = β1 yt-1 + ∑ i=1 p-1 δi ∇ yt-i +α +β2t +εt$
is fit and the test statistic ${\tau }_{\tau }$ constructed as
 $ττ = β^1 σ11 .$
All three test statistics: $\tau$, ${\tau }_{\mu }$ and ${\tau }_{\tau }$ can be calculated using G13AWF.
The probability distributions of these statistics are nonstandard and are a function of the length of the series of interest, $n$. The probability associated with a given test statistic, for a given $n$, can therefore only be calculated by simulation as described in Dickey and Fuller (1979). However, such simulations require a significant number of iterations and are therefore prohibitively expensive in terms of the time taken. As such G01EWF also allows the probability to be interpolated from a look-up table. Two such tables are provided, one from Dickey (1976) and one constructed as described in Section 9. The three different methods of obtaining an estimate of the probability can be chosen via the METHOD parameter. Unless there is a specific reason for choosing otherwise, ${\mathbf{METHOD}}=1$ should be used.
Dickey A D (1976) Estimation and hypothesis testing in nonstationary time series PhD Thesis Iowa State University, Ames, Iowa
Dickey A D and Fuller W A (1979) Distribution of the estimators for autoregressive time series with a unit root J. Am. Stat. Assoc. 74 366 427–431

## 5  Parameters

1:     $\mathrm{METHOD}$ – INTEGERInput
On entry: the method used to calculate the probability.
${\mathbf{METHOD}}=1$
The probability is interpolated from a look-up table, whose values were obtained via simulation.
${\mathbf{METHOD}}=2$
The probability is interpolated from a look-up table, whose values were obtained from Dickey (1976).
${\mathbf{METHOD}}=3$
The probability is obtained via simulation.
The probability calculated from the look-up table should give sufficient accuracy for most applications.
Suggested value: ${\mathbf{METHOD}}=1$.
Constraint: ${\mathbf{METHOD}}=1$, $2$ or $3$.
2:     $\mathrm{TYPE}$ – INTEGERInput
On entry: the type of test statistic, supplied in TS.
Constraint: ${\mathbf{TYPE}}=1$, $2$ or $3$.
3:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the length of the time series used to calculate the test statistic.
Constraints:
• if ${\mathbf{METHOD}}\ne 3$, ${\mathbf{N}}>0$;
• if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=1$, ${\mathbf{N}}>2$;
• if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=2$, ${\mathbf{N}}>3$;
• if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=3$, ${\mathbf{N}}>4$.
4:     $\mathrm{TS}$ – REAL (KIND=nag_wp)Input
On entry: the Dickey–Fuller test statistic for which the probability is required. If
${\mathbf{TYPE}}=1$
TS must contain $\tau$.
${\mathbf{TYPE}}=2$
TS must contain ${\tau }_{\mu }$.
${\mathbf{TYPE}}=3$
TS must contain ${\tau }_{\tau }$.
If the test statistic was calculated using G13AWF the value of TYPE and N must not change between calls to G01EWF and G13AWF.
5:     $\mathrm{NSAMP}$ – INTEGERInput
On entry: if ${\mathbf{METHOD}}=3$, the number of samples used in the simulation; otherwise NSAMP is not referenced and need not be set.
Constraint: if ${\mathbf{METHOD}}=3$, ${\mathbf{NSAMP}}>0$.
6:     $\mathrm{STATE}\left(*\right)$ – INTEGER arrayCommunication Array
Note: the actual argument supplied must be the array STATE supplied to the initialization routines G05KFF or G05KGF.
On entry: if ${\mathbf{METHOD}}=3$, STATE must contain information on the selected base generator and its current state; otherwise STATE is not referenced and need not be set.
On exit: if ${\mathbf{METHOD}}=3$, STATE contains updated information on the state of the generator otherwise a zero length vector is returned.
7:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{METHOD}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{METHOD}}=1$, $2$ or $3$.
${\mathbf{IFAIL}}=21$
On entry, ${\mathbf{TYPE}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{TYPE}}=1$, $2$ or $3$.
${\mathbf{IFAIL}}=31$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{METHOD}}\ne 3$, ${\mathbf{N}}>0$.
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=1$, ${\mathbf{N}}>2$.
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=2$, ${\mathbf{N}}>3$.
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{METHOD}}=3$ and ${\mathbf{TYPE}}=3$, ${\mathbf{N}}>4$.
${\mathbf{IFAIL}}=51$
On entry, ${\mathbf{NSAMP}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{METHOD}}=3$, ${\mathbf{NSAMP}}>0$.
${\mathbf{IFAIL}}=61$
On entry, ${\mathbf{METHOD}}=3$ and the STATE vector has been corrupted or not initialized.
${\mathbf{IFAIL}}=201$
The supplied input values were outside the range of at least one look-up table, therefore extrapolation was used.
${\mathbf{IFAIL}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

When ${\mathbf{METHOD}}=1$, the probability returned by this routine is unlikely to be accurate to more than $4$ or $5$ decimal places, for ${\mathbf{METHOD}}=2$ this accuracy is likely to drop to $2$ or $3$ decimal places (see Section 9 for details on how these probabilities are constructed). In both cases the accuracy of the probability is likely to be lower when extrapolation is used, particularly for small values of N (less than around $15$). When ${\mathbf{METHOD}}=3$ the accuracy of the returned probability is controlled by the number of simulations performed (i.e., the value of NSAMP used).

Not applicable.

## 9  Further Comments

When ${\mathbf{METHOD}}=1$ or $2$ the probability returned is constructed by interpolating from a series of look-up tables. In the case of ${\mathbf{METHOD}}=2$ the look-up tables are taken directly from Dickey (1976) and the interpolation is carried out using E01SAF and E01SBF . For ${\mathbf{METHOD}}=1$ the look-up tables were constructed as follows:
 (i) A sample size, $n$ was chosen. (ii) ${2}^{28}$ simulations were run. (iii) At each simulation, a time series was constructed as described in chapter five of Dickey (1976). The relevant test statistic was then calculated for each of these time series. (iv) A series of quantiles were calculated from the sample of ${2}^{28}$ test statistics. The quantiles were calculated at intervals of $0.0005$ between $0.0005$ and $0.9995$. (v) A spline was fit to the quantiles using E02BEF.
This process was repeated for $n=25,50,75,100,150,200,250,300,350,400,450,500,600,700,800,900,1000,1500,2000,2500,5000,10000$, resulting in $22$ splines.
Given the $\mathrm{22}$ splines, and a user-supplied sample size, $n$ and test statistic, $\tau$, an estimated $p$-value is calculated as follows:
 (i) Evaluate each of the $\mathrm{22}$ splines, at $\tau$, using E02BEF. If, for a particular spline, the supplied value of $\tau$ lies outside of the range of the simulated data, then a third-order Taylor expansion is used to extrapolate, with the derivatives being calculated using E02BCF. (ii) Fit a spline through these $22$ points using E01BEF. (iii) Estimate the $p$-value using E01BFF.

## 10  Example

See Section 10 in G13AWF.

G01EWF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual