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_nonpar_gofstat_anddar_exp (g08cl)

## Purpose

nag_nonpar_gofstat_anddar_exp (g08cl) calculates the Anderson–Darling goodness-of-fit test statistic and its probability for the case of an unspecified exponential distribution.

## Syntax

[ybar, a2, aa2, p, ifail] = g08cl(issort, y, 'n', n)
[ybar, a2, aa2, p, ifail] = nag_nonpar_gofstat_anddar_exp(issort, y, 'n', n)

## Description

Calculates the Anderson–Darling test statistic ${A}^{2}$ (see nag_nonpar_gofstat_anddar (g08ch)) and its upper tail probability for the small sample correction:
 $Adjusted ​ A2 = A2 1+0.6/n ,$
for $n$ observations.

## References

Anderson T W and Darling D A (1952) Asymptotic theory of certain ‘goodness-of-fit’ criteria based on stochastic processes Annals of Mathematical Statistics 23 193–212
Stephens M A and D'Agostino R B (1986) Goodness-of-Fit Techniques Marcel Dekker, New York

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{issort}$ – logical scalar
Set ${\mathbf{issort}}=\mathit{true}$ if the observations are sorted in ascending order; otherwise the function will sort the observations.
2:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, the $n$ observations.
Constraint: if ${\mathbf{issort}}=\mathit{true}$, values must be sorted in ascending order. Each ${y}_{i}$ must be greater than zero.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array y.
$n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.

### Output Parameters

1:     $\mathrm{ybar}$ – double scalar
The maximum likelihood estimate of mean.
2:     $\mathrm{a2}$ – double scalar
${A}^{2}$, the Anderson–Darling test statistic.
3:     $\mathrm{aa2}$ – double scalar
The adjusted ${A}^{2}$.
4:     $\mathrm{p}$ – double scalar
$p$, the upper tail probability for the adjusted ${A}^{2}$.
5:     $\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:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}>1$.
${\mathbf{ifail}}=3$
${\mathbf{issort}}=\mathit{true}$ and the data in y is not sorted in ascending order.
${\mathbf{ifail}}=9$
The data in y must be greater than zero.
${\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

Probabilities are calculated using piecewise polynomial approximations to values estimated by simulation.

None.

## Example

This example calculates the ${A}^{2}$ statistics for data assumed to arise from an unspecified exponential distribution and calculates the $p$-value.
```function g08cl_example

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

y = [0.4782745, 1.2858962, 1.1163891, 2.0410619, 2.2648109, 0.0833660, ...
1.2527554, 0.4031288, 0.7808981, 0.1977674, 3.2539440, 1.8113504, ...
1.2279834, 3.9178773, 1.4494309, 0.1358438, 1.8061778, 6.0441929, ...
0.9671624, 3.2035042, 0.8067364, 0.4179364, 3.5351774, 0.3975414, ...
0.6120960, 0.1332589];
% Let g08cl sort the data
issort = false;

% Calculate a-squared and probability
[ybar, a2, aa2, p, ifail] = g08cl( ...
issort, y);

% Results
fprintf('H0: data from exponential distribution with mean %10.4e\n', ybar);
fprintf('Test statistic, A-squared: %8.4f\n', a2);
fprintf('Upper tail probability:    %8.4f\n', p);

```
```g08cl example results

H0: data from exponential distribution with mean 1.5240e+00
Test statistic, A-squared:   0.1616