Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_prob_dickey_fuller_unit (g01ew)

## Purpose

nag_stat_prob_dickey_fuller_unit (g01ew) returns the probability associated with the lower tail of the distribution for the Dickey–Fuller unit root test statistic.

## Syntax

[pvalue, state, ifail] = g01ew(type, n, ts, 'method', method, 'nsamp', nsamp, 'state', state)
[pvalue, state, ifail] = nag_stat_prob_dickey_fuller_unit(type, n, ts, 'method', method, 'nsamp', nsamp, 'state', state)

## 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_stat_prob_dickey_fuller_unit (g01ew) is designed to be called after nag_tsa_uni_dickey_fuller_unit (g13aw) 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 nag_tsa_uni_dickey_fuller_unit (g13aw).
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_stat_prob_dickey_fuller_unit (g01ew) 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 Further Comments. 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}}=1$ should be used.

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{type}$int64int32nag_int scalar
The type of test statistic, supplied in ts.
Constraint: ${\mathbf{type}}=1$, $2$ or $3$.
2:     $\mathrm{n}$int64int32nag_int scalar
$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$.
3:     $\mathrm{ts}$ – double scalar
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 nag_tsa_uni_dickey_fuller_unit (g13aw) the value of type and n must not change between calls to nag_stat_prob_dickey_fuller_unit (g01ew) and nag_tsa_uni_dickey_fuller_unit (g13aw).

### Optional Input Parameters

1:     $\mathrm{method}$int64int32nag_int scalar
Default: $1$
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.
Constraint: ${\mathbf{method}}=1$, $2$ or $3$.
2:     $\mathrm{nsamp}$int64int32nag_int scalar
Default: $100000$
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$.
3:     $\mathrm{state}\left(:\right)$int64int32nag_int array
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.

### Output Parameters

1:     $\mathrm{pvalue}$ – double scalar
2:     $\mathrm{state}\left(:\right)$int64int32nag_int array
If ${\mathbf{method}}=3$, state contains updated information on the state of the generator otherwise a zero length vector is returned.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=11$
Constraint: ${\mathbf{method}}=1$, $2$ or $3$.
${\mathbf{ifail}}=21$
Constraint: ${\mathbf{type}}=1$, $2$ or $3$.
${\mathbf{ifail}}=31$
Constraint: if ${\mathbf{method}}\ne 3$, ${\mathbf{n}}>0$.
Constraint: if ${\mathbf{method}}=3$ and ${\mathbf{type}}=1$, ${\mathbf{n}}>2$.
Constraint: if ${\mathbf{method}}=3$ and ${\mathbf{type}}=2$, ${\mathbf{n}}>3$.
Constraint: if ${\mathbf{method}}=3$ and ${\mathbf{type}}=3$, ${\mathbf{n}}>4$.
${\mathbf{ifail}}=51$
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.
W  ${\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$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

When ${\mathbf{method}}=1$, the probability returned by this function 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 Further Comments 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).

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 nag_interp_2d_scat (e01sa) and nag_interp_2d_scat_eval (e01sb) . 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 nag_fit_1dspline_auto (e02be).
This process was repeated for $n=25,50,75,100,150,200,250,300,350,400,450,500,600,700,800,\phantom{\rule{0ex}{0ex}}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 nag_fit_1dspline_auto (e02be). 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 nag_fit_1dspline_deriv (e02bc). (ii) Fit a spline through these $22$ points using nag_interp_1d_monotonic (e01be). (iii) Estimate the $p$-value using nag_interp_1d_monotonic_eval (e01bf).

## Example

See Example in nag_tsa_uni_dickey_fuller_unit (g13aw).
```function g01ew_example

fprintf('g01ew example results\n\n');

% Test type
type = int64(1);

% Order of the AR process
p = int64(1);

% Time series
y = [ -217; -177; -166; -136; -110;  -95;  -64;  -37;  -14;  -25;
-51;  -62;  -73;  -88; -113; -120;  -83;  -33;  -19;   21;
17;   44;   44;   78;   88;  122;  126;  114;   85;   64];

% Calculate the Dickey-Fuller test statistic
[ts,ifail] = g13aw(type,p,y);

% The p-value routine can issue a warning, but still return
% sensible results, so save current warning state and turn warnings on
warn_state = nag_issue_warnings();
nag_issue_warnings(true);

% Get the associated p-value
n = int64(size(y,1));
[pvalue,~,ifail] = g01ew(type,n,ts);

% Reset the warning state to its initial value
nag_issue_warnings(warn_state);

% Print the results
fprintf('Dickey-Fuller test statistic     = %6.3f\n', ts);
fprintf('associated p-value               = %6.3f\n', pvalue);

```
```g01ew example results

Dickey-Fuller test statistic     = -2.540
associated p-value               =  0.013
```