# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g01asf ( prt, m, n, x, ldx, plot,
 Integer, Intent (In) :: m, n(m), ldx, nstepx, nstepy, ldplot Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: iwork(ldx) Real (Kind=nag_wp), Intent (In) :: x(ldx,m) Real (Kind=nag_wp), Intent (Out) :: fivept(5*m) Character (1), Intent (In) :: prt Character (1), Intent (Inout) :: plot(ldplot,nstepx)
#include nagmk26.h
 void g01asf_ (const char *prt, const Integer *m, const Integer n[], const double x[], const Integer *ldx, const Integer *nstepx, const Integer *nstepy, char plot[], const Integer *ldplot, double fivept[], Integer iwork[], Integer *ifail, const Charlen length_prt, const Charlen length_plot)

## 3Description

g01asf 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 x04abf.
An axis corresponding to the $y$ axis is drawn and annotated and data points are plotted to the nearest character position.

## 4References

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

## 5Arguments

1:     $\mathbf{prt}$ – Character(1)Input
On entry: 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 x04abf.
Constraint: ${\mathbf{prt}}=\text{'P'}$ or $\text{'N'}$.
2:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of data batches that are to be represented.
Constraint: ${\mathbf{m}}>0$.
3:     $\mathbf{n}\left({\mathbf{m}}\right)$ – Integer arrayInput
On entry: ${\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$.
4:     $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: 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}}$.
5:     $\mathbf{ldx}$ – IntegerInput
On entry: the first dimension of the array x and the dimension of the array iwork as declared in the (sub)program from which g01asf is called.
Constraint: ${\mathbf{ldx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{\mathbf{n}}\left(i\right)\right\}$.
6:     $\mathbf{nstepx}$ – IntegerInput
On entry: 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)$.
7:     $\mathbf{nstepy}$ – IntegerInput
On entry: the number of character positions to be plotted in the $y$-direction.
Constraint: ${\mathbf{nstepy}}\ge 9$.
8:     $\mathbf{plot}\left({\mathbf{ldplot}},{\mathbf{nstepx}}\right)$ – Character(1) arrayOutput
On exit: contains the box and whisker plots.
9:     $\mathbf{ldplot}$ – IntegerInput
On entry: the first dimension of the array plot as declared in the (sub)program from which g01asf is called.
Constraint: ${\mathbf{ldplot}}\ge {\mathbf{nstepy}}$.
10:   $\mathbf{fivept}\left(5×{\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{fivept}}\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.
11:   $\mathbf{iwork}\left({\mathbf{ldx}}\right)$ – Integer arrayWorkspace
12:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, at least one element of ${\mathbf{n}}<5$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{nstepx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nstepx}}\ge 19$.
On entry, ${\mathbf{nstepx}}=〈\mathit{\text{value}}〉$ is too small for $〈\mathit{\text{value}}〉$ plots.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{nstepy}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nstepy}}\ge 9$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{ldplot}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nstepy}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldplot}}\ge {\mathbf{nstepy}}$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{prt}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{prt}}=\text{'P'}$ or $\text{'N'}$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=7$
On entry, all batches have ${\mathbf{n}}<5$.
${\mathbf{ifail}}=8$
On entry, the data values are all identical.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

g01asf is not threaded in any implementation.

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

## 10Example

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.

### 10.1Program Text

Program Text (g01asfe.f90)

### 10.2Program Data

Program Data (g01asfe.d)

### 10.3Program Results

Program Results (g01asfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017