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_plot_scatter_normal (g01ah)

## Purpose

nag_stat_plot_scatter_normal (g01ah) performs a Normal probability plot on a character printing device, with a chosen number of character positions in each direction.

## Syntax

[ifail, xbar, xstd, work, xsort] = g01ah(x, nstepx, nstepy, 'nobs', nobs, 'istand', istand)
[ifail, xbar, xstd, work, xsort] = nag_stat_plot_scatter_normal(x, nstepx, nstepy, 'nobs', nobs, 'istand', istand)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: only the first nobs elements of work are returned; istand was made optional (default 1); lwork is no longer an input parameter; output parameters were reordered

## Description

In a Normal probability plot, the data $\left(x\right)$ are plotted against Normal scores $\left(y\right)$. The degree of linearity in the resultant plot provides a visual indication of the Normality of distribution of a set of residuals from some fitting process, such as multiple regression.
The data values are sorted into descending order prior to plotting, and may also be standardized to zero mean and unit standard deviation, if requested.
The plot is produced on a character printing device, using a chosen number of character positions in each direction. The output is directed to the current advisory message unit number. This number may be changed by an appropriate call to nag_file_set_unit_advisory (x04ab) before calling nag_stat_plot_scatter_normal (g01ah).
Axes are drawn and annotated and data points are plotted on the nearest character position. An appropriate step size for each axis is computed from the list
• $\left(0.1,0.15,0.2,0.25,0.4,0.5,0.6,0.75,0.8\right)×\text{}$ power of $10$.
Points are plotted using the digits $1$ to $9$ to indicate the equivalent number of observations at a particular character position, a letter A–Z for $10–35$ occurrences, or * if there are $36$ or more coincident occurrences. Zero axes are marked if included in the plotting area.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{nobs}}\right)$ – double array
The vector of data values.
Constraint: all data values must not be equal.
2:     $\mathrm{nstepx}$int64int32nag_int scalar
The number of steps (character positions) to be plotted in the $x$-direction. If the supplied value of nstepx is less than $10$, the value $10$ will be used by nag_stat_plot_scatter_normal (g01ah). The maximum value for nstepx is the number of character positions available on the chosen output device less $15$, up to a maximum of $133$. If nstepx exceeds $133$ on input, the value $133$ will be used by the function.
3:     $\mathrm{nstepy}$int64int32nag_int scalar
The number of steps (character positions) to be plotted in the $y$-direction. If the supplied value of nstepy is less than $10$, the value $10$ will be used by nag_stat_plot_scatter_normal (g01ah). There is no maximum value for nstepy, but you should bear in mind that (${\mathbf{nstepy}}+5$) records (lines) of output are generated by the function.

### Optional Input Parameters

1:     $\mathrm{nobs}$int64int32nag_int scalar
Default: the dimension of the array x.
The number of data values.
Constraint: ${\mathbf{nobs}}\ge 2$.
2:     $\mathrm{istand}$int64int32nag_int scalar
Default: $1$
Indicates whether the residuals are to be standardized prior to plotting.
If ${\mathbf{istand}}>0$, the elements of x are standardized to zero mean and unit standard deviation.

### Output Parameters

1:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).
2:     $\mathrm{xbar}$ – double scalar
The mean of the data values.
3:     $\mathrm{xstd}$ – double scalar
The standard deviation of the data values.
4:     $\mathrm{work}\left({\mathbf{nobs}}\right)$ – double array
The dimension of the array work will be ${\mathbf{nobs}}$
$\mathit{lwork}=\left(5×{\mathbf{nobs}}\right)/2$.
the Normal scores in ascending magnitude.
5:     $\mathrm{xsort}\left({\mathbf{nobs}}\right)$ – double array
The data values, sorted into descending order, and standardized if istand was positive on entry.

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{nobs}}<2$.
${\mathbf{ifail}}=2$
All the supplied data values are equal.
${\mathbf{ifail}}=3$
 On entry, $\mathit{lwork}<\left(5×{\mathbf{nobs}}\right)/2$, i.e., the array work is too small.
${\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

Accuracy is limited by the number of plotting positions available.

For details of timing see nag_stat_plot_scatter_2var (g01ag) and nag_stat_normal_scores_exact (g01da).
No blank records are output before or after the plot.
You must make sure that it is permissible to write records containing nstepx characters to the current advisory message unit.

## Example

The data are residuals from a linear regression. The $25$ values are standardized and plotted against the Normal scores, and are seen to follow a straight line fairly closely, indicating that Normality assumptions are justified.
```function g01ah_example

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

x = [ 0.35     0.1      0.95    -0.53     0.33     0.3      0.39     0.26 ...
-0.45     0.12    -1.58     0.9      0.53    -0.58     0.54    -0.09 ...
0.79    -0.41     0.54     0.48    -0.28    -0.71    -1.1     -0.41 ...
-0.44];

nstepx = int64(50);
nstepy = int64(40);

fprintf('Plot of normal scores (Y) against standardised residuals (X)\n\n');

[ifail, xbar, xstd, work, xsort] = g01ah( ...
x, nstepx, nstepy);

```
```g01ah example results

Plot of normal scores (Y) against standardised residuals (X)

+....+....+....+....+....+....+....+....+....+....+.
2.000+                             +              1     +
.                             .                    .
.                             .                    .
.                             .                    .
.                             .                    .
1.500+                             +             1      +
.                             .                    .
.                             .           1        .
.                             .                    .
.                             .        1           .
1.000+                             +                    +
.                             .        1           .
.                             .       1            .
.                             .                    .
.                             .       1            .
0.500+                             +     1              +
.                             .     1              .
.                             .    1               .
.                             .    1               .
.                             .   1                .
0.000+....+....+....+....+....+....+.1..+....+....+....++
.                             . 1                  .
.                            1.                    .
.                         1   .                    .
.                       1     .                    .
-0.500+                       1     +                    +
.                      1      .                    .
.                             .                    .
.                      1      .                    .
.                     1       .                    .
-1.000+                             +                    +
.                    1        .                    .
.                             .                    .
.                  1          .                    .
.                             .                    .
-1.500+            1                +                    +
.                             .                    .
.                             .                    .
.                             .                    .
.                             .                    .
-2.000+    1                        +                    +
+....+....+....+....+....+....+....+....+....+....+.
-3.000    -2.000    -1.000     0.000     1.000     2.000
-2.500    -1.500    -0.500     0.500     1.500
```