NAG Library Routine Document
G01ARF
1 Purpose
G01ARF produces a stem and leaf display for a single sample of observations.
2 Specification
SUBROUTINE G01ARF ( |
RANGE, PRT, N, Y, NSTEPX, NSTEPY, UNIT, PLOT, LDPLOT, LINES, SORTY, IWORK, IFAIL) |
INTEGER |
N, NSTEPX, NSTEPY, LDPLOT, LINES, IWORK(N), IFAIL |
REAL (KIND=nag_wp) |
Y(N), UNIT, SORTY(N) |
CHARACTER(1) |
RANGE, PRT, PLOT(LDPLOT,NSTEPX) |
|
3 Description
G01ARF produces a stem and leaf display for a single sample of observations. The stem and leaf display shows data values separated into the form of a ‘stem’ and a ‘leaf’. For example, a value of could be represented as where the stem is and the leaf is . The data is scaled using a value known as the ‘leaf digit unit’. In the above example the leaf digit unit would be .
The following example illustrates a stem and leaf display.
For the
observations:
the stem and leaf display is:
1 1 8
3 1 99
5 2 00
5 2 111
2 2
2 2 3
1 2 4
where the leaf digit unit is
so that
represents
(i.e.,
). The leaf digit unit distinguishes between the numbers
,
,
, etc. which may otherwise all be represented by
.
Included in the above display is an initial column specifying the cumulative count of values, up to and including that particular line, from either the top or bottom of the display, whichever is smaller. An exception to this is when the line on which the median lies is reached, in which case the actual count of values on that line is displayed, rather than a cumulative count, and this is highlighted by enclosing the count in parentheses. In this case the median is and thus falls between the two lines at which the cumulative count has reached where is the number of observations.
Some of the other features of the stem and leaf display are illustrated by the following two examples.
the stem and leaf display may be:
1 1. 9
1 1*
1 -0.
3 -0* 13
15 +0* 012233344444
15 +0. 55556667788
5 1* 011
2 1. 3
1 2
1 2.
1 3 1
In the above display all the data are plotted and the leaf digit unit is
. Also in this display different leaves, that is different digits, may be plotted on a particular line. In this case we have
possible digits per line, that is
lines per stem, and these are represented as follows:
- * indicates that the line may contain the digits to 4;
- . indicates that the line may contain the digits to .
Alternatively the stem and leaf display may look like:
LO -19
2 -0* 3
3 +0T 1
5 +0* 01
10 +0T 22333
( 9) +0F 444445555
11 +0* 66677
6 +0T 8
5 1* 011
2 1T 3
HI 31
Again the leaf digit unit is but in this display just the data between the fences, which are the hinges the inter-hinge range, are plotted. Any data points that fall outside the fences are presented separately in the display under the headings LO for those points below the lower fence and HI for those points above the upper fence.
Again in this display different leaves, that is different digits, may be plotted on a particular line. However in this case we have
possible digits per line, that is
lines per stem, and these are represented as follows
- * indicates that the line may contain the digits or ;
- T indicates that the line may contain the digits or ;
- F indicates that the line may contain the digits or ;
- S indicates that the line may contain the digits or ;
- . indicates that the line may contain the digits or .
A display may also allow different digits ( to ) per line, that is line per stem, or just digit per line, that is lines per stem, as in the first of the three examples above.
Note that the median here is . This falls between two lines in the first display but is highlighted on the second display since it lies on a particular line.
Finally if there are positive and negative numbers on the display these are highlighted by a or sign where the distinction is required, that is near the zero-point.
If there are too many leaves to fit in the plot width allowed, G01ARF plots as many leaves as possible and places an asterisk to the right to indicate that some leaves are not displayed. If this occurs and you wish to be able to plot all the leaves then the width of the plot may be adjusted.
Options also allow the leaf unit and the height of the display to be specified by you or calculated by G01ARF. These parameters may be used to control the type of the display you wish to obtain. Fixing the unit and changing the height of the display may alter the number of lines used per stem, that is the number of different digits per line. G01ARF will choose a display for the fixed unit that attempts to make as much use of the available height as possible, thus increasing the height may allow for more lines per stem whereas decreasing the height may force the display to use fewer lines per stem. Similarly you may wish to fix the height and vary the leaf digit unit used on the display. See
Section 8 for further details.
The display is returned in a character array with the option of printing the display.
4 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
Velleman P F and Hoaglin D C (1981) Applications, Basics, and Computing of Exploratory Data Analysis Duxbury Press, Boston, MA
5 Parameters
- 1: RANGE – CHARACTER(1)Input
On entry: indicates whether you wish to scale the plot to the extremes of the data or to the fences.
- The display is a plot to the extremes, that is a plot of all the data.
- The display is a plot of the data between the fences.
Constraint:
must be one of 'E' or 'F'.
- 2: PRT – CHARACTER(1)Input
On entry: indicates whether the stem and leaf display is to be output to an external file.
- The display is not output to an external file.
- The display is output to the current advisory message unit as defined by X04ABF. Only the first characters of each line are actually printed.
Constraint:
must be one of 'P' or 'N'.
- 3: N – INTEGERInput
On entry: , the number of observations.
Constraint:
.
- 4: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations.
- 5: NSTEPX – INTEGERInput
On entry: the number of character positions to be plotted horizontally.
Constraint:
.
- 6: NSTEPY – INTEGERInput
On entry: the maximum number of character positions to be plotted vertically.
If
a suitable value will be used by G01ARF for the number of character positions to be plotted vertically. This will clearly be less than or equal to the value of
LDPLOT.
Constraint:
or .
- 7: UNIT – REAL (KIND=nag_wp)Input/Output
On entry: indicates the leaf digit unit to be used.
If and is not a power of ten, it will be converted to the nearest power of ten below the input value for unit.
If , the optimum unit will be used. This is based on the range of the data to be plotted and the number of lines available for the display.
On exit: contains the actual unit used in the stem and leaf display.
- 8: PLOT(LDPLOT,NSTEPX) – CHARACTER(1) arrayOutput
On exit: the stem and leaf display.
- 9: LDPLOT – INTEGERInput
On entry: the first dimension of the array
PLOT as declared in the (sub)program from which G01ARF is called.
Constraint:
.
- 10: LINES – INTEGEROutput
On exit: the actual number of lines needed for the display.
- 11: SORTY(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the observations sorted into ascending order.
- 12: IWORK(N) – INTEGER arrayWorkspace
- 13: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, | , |
or | , |
or | , |
or | , |
or | . |
On entry, | or , |
or | or . |
The number of lines needed to produce the display exceeds the maximum number of lines allowed. You may wish to increase
NSTEPY.
One of the observations is too large and causes a value to exceed the maximum integer allowed.
7 Accuracy
Accuracy is limited by the number of significant figures that may be represented on the display which will depend on the data, the number of lines available and the unit used.
G01ARF uses integer representations of the data. If very large data values are being used they should be scaled before using this routine. The largest integer can be found by calling
X02BBF.
If an asterisk is plotted at the end of a line to indicate that some leaves are not displayed you should increase
NSTEPX if they wish to be able to print the rest of the leaves on that line.
Note that if you request G01ARF to print the plot only the first
characters of each line are printed. The full plot is stored in the array
PLOT so you do have the option of printing a plot which has more than
characters on a line.
When the leaf digit unit is set, the number of lines per stem is decided as follows:
Let
be the range of the data to be plotted:
- = largest observation – smallest observation: if all the data to both extremes are to be plotted (that is if ),
- = upper fence – lower fence: if only the data between the fences are to be plotted (that is if ).
Let
be the number of lines available for the plot:
- if ,
- if .
- The lines are subtracted to allow space for the display headings. If only the data between the fences are to be plotted then must be further reduced to allow space to present those values outside the fences. This will involve a minimum of another lines.
Let
,
- then the number of lines per stem is:
The time taken by the routine increases with .
9 Example
A program to produce two stem and leaf displays for a sample of observations. The first illustrates a plot produced automatically by G01ARF and the second shows how to print the display under your control.
9.1 Program Text
Program Text (g01arfe.f90)
9.2 Program Data
Program Data (g01arfe.d)
9.3 Program Results
Program Results (g01arfe.r)