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_box_whisker (g01as)

## Purpose

nag_stat_plot_box_whisker (g01as) produces a specified number of box and whisker plots on a character printing device, with a chosen number of character positions in each direction.

## Syntax

[ifail, plot, work] = g01as(n, x, nstepx, nstepy, 'prt', prt, 'm', m)
[ifail, plot, work] = nag_stat_plot_box_whisker(n, x, nstepx, nstepy, 'prt', prt, 'm', m)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: prt was made optional (default 'P'); output parameters were reordered

## Description

nag_stat_plot_box_whisker (g01as) produces a series of box and whisker plots representing $m$ data batches each of size ${n}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$. A box and whisker plot is a diagrammatic representation of the five-point summary of a data batch. The plot consists of a box spanning the hinges with the median indicated by a third line and two whiskers to represent the extreme values. The five-point summary is calculated internally and is returned in the workspace array.
The plot is returned in the character array plot. The size of the plot may be controlled using the arguments nstepx and nstepy. Optionally the plot can be output to an external file, in which case output is directed to the current advisory message unit as defined by nag_file_set_unit_advisory (x04ab).
An axis corresponding to the $y$ axis is drawn and annotated and data points are plotted to the nearest character position.

## References

Erickson B H and Nosanchuk T A (1985) Understanding Data Open University Press, Milton Keynes
Tukey J W (1977) Exploratory Data Analysis Addison–Wesley

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}\left({\mathbf{m}}\right)$int64int32nag_int array
${\mathbf{n}}\left(\mathit{i}\right)$ contains the number of observations in the $\mathit{i}$th batch, ${n}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$.
If ${n}_{i}<5$ the $i$th batch is omitted from the plot.
Constraint: at least one ${\mathbf{n}}\left(\mathit{i}\right)$ must be greater than or equal to $5$, for $\mathit{i}=1,2,\dots ,m$.
2:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{m}}\right)$ – double array
ldx, the first dimension of the array, must satisfy the constraint $\mathit{ldx}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{\mathbf{n}}\left(i\right)\right\}$.
The $i$th column of x must contain the data for the $\mathit{i}$th batch, that is ${\mathbf{x}}\left(\mathit{j},\mathit{i}\right)$ must contain the $\mathit{j}$th observation of the $\mathit{i}$th batch, for $\mathit{i}=1,2,\dots ,m$ and $\mathit{j}=1,2,\dots ,{n}_{\mathit{i}}$.
3:     $\mathrm{nstepx}$int64int32nag_int scalar
The number of character positions to be plotted in the $x$-direction.
Constraint: ${\mathbf{nstepx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(19,\left(15×{\mathbf{m}}/4+9\right)\right)$.
4:     $\mathrm{nstepy}$int64int32nag_int scalar
The number of character positions to be plotted in the $y$-direction.
Constraint: ${\mathbf{nstepy}}\ge 9$.

### Optional Input Parameters

1:     $\mathrm{prt}$ – string (length ≥ 1)
Default: $\text{'P'}$
Indicates whether the box and whisker plot is to be output to an external file.
${\mathbf{prt}}=\text{'N'}$
The box and whisker plot is not output to an external file.
${\mathbf{prt}}=\text{'P'}$
The box and whisker plot is output to the current advisory message unit as defined by nag_file_set_unit_advisory (x04ab).
Constraint: ${\mathbf{prt}}=\text{'P'}$ or $\text{'N'}$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the array n and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
$m$, the number of data batches that are to be represented.
Constraint: ${\mathbf{m}}>0$.

### 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{plot}\left(\mathit{ldplot},{\mathbf{nstepx}}\right)$ – cell array of strings
Contains the box and whisker plots.
3:     $\mathrm{work}\left(5×{\mathbf{m}}\right)$ – double array
${\mathbf{work}}\left(\mathit{j}\right)$, for $\mathit{j}=\left(i-1\right)×5+1,\dots ,\left(i-1\right)×5+5$, contains the five-point summary of the $i$th batch.

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}\left(\mathit{i}\right)<5$ for some $\mathit{i}$, for $\mathit{i}=1,2,\dots ,m$. For each batch where this occurs, $5$ crosses are plotted in a vertical line to indicate that insufficient data was provided to produce a five-point summary and box-plot for that particular batch.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{nstepx}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(19,15×{\mathbf{m}}/4+9\right)$. This indicates that the data region defined by nstepx is too small to produce the required plot.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{nstepy}}<9$.
${\mathbf{ifail}}=4$
 On entry, $\mathit{ldplot}<{\mathbf{nstepy}}$.
${\mathbf{ifail}}=5$
 On entry, ${\mathbf{prt}}\ne \text{'P'}$ or $\text{'N'}$.
${\mathbf{ifail}}=6$
On entry, $\mathit{ldx}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}}\left(i\right)\right)$, for $i=1,2,\dots ,m$.
${\mathbf{ifail}}=7$
The number of observations in all batches is less than $5$.
${\mathbf{ifail}}=8$
On entry, the data values are all identical.
${\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

If the range of observations in a particular batch is too small to allow each item of the five-point summary to be plotted separately, then a sequence of stars are plotted at the median point of the batch to indicate that the full box-plot could not be plotted.

The time taken by nag_stat_plot_box_whisker (g01as) increases with $m$ and ${n}_{i}$, for $\mathit{i}=1,2,\dots ,m$.

## Example

The following program produces a box and whisker plot for each one of $5$ data batches of sizes $5$, $6$, $8$, $8$ and $7$ respectively and prints the $5$ box and whisker plots on the current advisory message unit.
```function g01as_example

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

n = int64([  5;    6;    8;   8;   7]);
x =         [ -9,   -5.6, -9,  12,  -5;
-7.3, 12,   12,  10,   8;
-4.9, -9,   -6,  10,   1.5;
-2.4, -3.9, -3,   8,  -3.2;
-0.6, -2.4,  0,   6,  -3.2;
0,   -7.3,  3,   4,   6.2;
0,    0,    6,   4,   6.2;
0,    0,    9,  -9,   0];

nstepx = int64(55);
nstepy = int64(21);
[ifail, plot, work] = g01as( ...
n, x, nstepx, nstepy);

```
```g01as example results

0.1E+02+           ---      ---      ---
:            :        :        :
:            :        :      -----
0.8E+01+            :        :      :   :
:            :      -----    :   :     ---
:            :      :   :    :---:      :
:            :      :   :    :   :    -----
0.4E+01+            :      :   :    :   :    :   :
:            :      :   :    -----    :   :
:            :      :   :      :      :   :
:            :      :---:      :      :---:
:            :      :   :      :      :   :
-0.6E+00+  ---       :      :   :      :      :   :
:   :        :      :   :      :      :   :
: -----    -----    :   :      :      -----
: :   :    :   :    :   :      :        :
-0.5E+01+ :---:    :---:    -----      :       ---
: :   :    :   :      :        :
: -----    -----      :        :
:   :        :        :        :
-0.9E+01+  ---      ---      ---      ---
```