NAG Library Function Document
nag_prob_dickey_fuller_unit (g01ewc)
1 Purpose
nag_prob_dickey_fuller_unit (g01ewc) returns the probability associated with the lower tail of the distribution for the Dickey–Fuller unit root test statistic.
2 Specification
#include <nag.h> 
#include <nagg01.h> 
double 
nag_prob_dickey_fuller_unit (Nag_TS_URProbMethod method,
Nag_TS_URTestType type,
Integer n,
double ts,
Integer nsamp,
Integer state[],
NagError *fail) 

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. nag_prob_dickey_fuller_unit (g01ewc) is designed to be called after
nag_tsa_dickey_fuller_unit (g13awc) 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
is fit and the test statistic $\tau $ constructed as
where $\nabla $ is the difference operator, with $\nabla {y}_{t}={y}_{t}{y}_{t1}$, and where ${\hat{\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
is fit and the test statistic ${\tau}_{\mu}$ constructed as

3. 
To test for a unit root with drift and deterministic time trend the regression model
is fit and the test statistic ${\tau}_{\tau}$ constructed as

All three test statistics:
$\tau $,
${\tau}_{\mu}$ and
${\tau}_{\tau}$ can be calculated using
nag_tsa_dickey_fuller_unit (g13awc).
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 nag_prob_dickey_fuller_unit (g01ewc) also allows the probability to be interpolated from a lookup 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 argument. Unless there is a specific reason for choosing otherwise,
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$ should be used.
4 References
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 Arguments
 1:
$\mathbf{method}$ – Nag_TS_URProbMethodInput

On entry: the method used to calculate the probability.
 ${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$
 The probability is interpolated from a lookup table, whose values were obtained via simulation.
 ${\mathbf{method}}=\mathrm{Nag\_ViaLookUpOriginal}$
 The probability is interpolated from a lookup table, whose values were obtained from Dickey (1976).
 ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$
 The probability is obtained via simulation.
The probability calculated from the lookup table should give sufficient accuracy for most applications.
Suggested value:
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$.
Constraint:
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$, $\mathrm{Nag\_ViaLookUpOriginal}$ or $\mathrm{Nag\_ViaSimulation}$.
 2:
$\mathbf{type}$ – Nag_TS_URTestTypeInput

On entry: the type of test statistic, supplied in
ts.
Constraint:
${\mathbf{type}}=\mathrm{Nag\_UnitRoot}$, $\mathrm{Nag\_UnitRootWithDrift}$ or $\mathrm{Nag\_UnitRootWithDriftAndTrend}$.
 3:
$\mathbf{n}$ – IntegerInput

On entry: $n$, the length of the time series used to calculate the test statistic.
Constraints:
 if ${\mathbf{method}}\ne \mathrm{Nag\_ViaSimulation}$, ${\mathbf{n}}>0$;
 if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRoot}$, ${\mathbf{n}}>2$;
 if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDrift}$, ${\mathbf{n}}>3$;
 if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDriftAndTrend}$, ${\mathbf{n}}>4$.
 4:
$\mathbf{ts}$ – doubleInput

On entry: the Dickey–Fuller test statistic for which the probability is required. If
 ${\mathbf{type}}=\mathrm{Nag\_UnitRoot}$
 ts must contain $\tau $.
 ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDrift}$
 ts must contain ${\tau}_{\mu}$.
 ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDriftAndTrend}$
 ts must contain ${\tau}_{\tau}$.
If the test statistic was calculated using
nag_tsa_dickey_fuller_unit (g13awc) the value of
type and
n must not change between calls to nag_prob_dickey_fuller_unit (g01ewc) and
nag_tsa_dickey_fuller_unit (g13awc).
 5:
$\mathbf{nsamp}$ – IntegerInput

On entry: if
${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$, the number of samples used in the simulation; otherwise
nsamp is not referenced and need not be set.
Constraint:
if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$, ${\mathbf{nsamp}}>0$.
 6:
$\mathbf{state}\left[\mathit{dim}\right]$ – IntegerCommunication Array

Note: the dimension,
$\mathit{dim}$, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument
state in the previous call to
nag_rand_init_repeatable (g05kfc) or
nag_rand_init_nonrepeatable (g05kgc).
On entry: if
${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$,
state must contain information on the selected base generator and its current state; otherwise
state is not referenced and may be
NULL.
On exit: if
${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$,
state contains updated information on the state of the generator otherwise a zero length vector is returned.
 7:
$\mathbf{fail}$ – NagError *Input/Output

The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
 NE_BAD_PARAM

On entry, argument $\u2329\mathit{\text{value}}\u232a$ had an illegal value.
 NE_INT

On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{method}}\ne \mathrm{Nag\_ViaSimulation}$, ${\mathbf{n}}>0$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRoot}$, ${\mathbf{n}}>2$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDriftAndTrend}$, ${\mathbf{n}}>4$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and ${\mathbf{type}}=\mathrm{Nag\_UnitRootWithDrift}$, ${\mathbf{n}}>3$.
 NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
 NE_INVALID_STATE

On entry,
${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$ and the
state vector has been corrupted or not initialized.
 NE_NO_LICENCE

Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
 NE_SAMPLE

On entry, ${\mathbf{nsamp}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{method}}=\mathrm{Nag\_ViaSimulation}$, ${\mathbf{nsamp}}>0$.

The supplied input values were outside the range of at least one lookup table, therefore extrapolation was used.
7 Accuracy
When
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$, the probability returned by this function is unlikely to be accurate to more than
$4$ or
$5$ decimal places, for
${\mathbf{method}}=\mathrm{Nag\_ViaLookUpOriginal}$ 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}}=\mathrm{Nag\_ViaSimulation}$ the accuracy of the returned probability is controlled by the number of simulations performed (i.e., the value of
nsamp used).
8 Parallelism and Performance
nag_prob_dickey_fuller_unit (g01ewc) is not threaded in any implementation.
When
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$ or
$\mathrm{Nag\_ViaLookUpOriginal}$ the probability returned is constructed by interpolating from a series of lookup tables. In the case of
${\mathbf{method}}=\mathrm{Nag\_ViaLookUpOriginal}$ the lookup tables are taken directly from
Dickey (1976) and the interpolation is carried out using
nag_2d_triang_interp (e01sjc) and
nag_2d_triang_eval (e01skc).
For
${\mathbf{method}}=\mathrm{Nag\_ViaLookUp}$ the lookup 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 nag_1d_spline_fit (e02bec). 
This process was repeated for $\mathrm{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 usersupplied sample size,
$n$ and test statistic,
$\tau $, an estimated
$p$value is calculated as follows:
10 Example
See
Section 10 in nag_tsa_dickey_fuller_unit (g13awc).