PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_plot_histogram (g01aj)
Purpose
nag_stat_plot_histogram (g01aj) prints a histogram on a character printing device, allowing you control over size, positioning, and the range of data values included.
Syntax
[
xstep,
n1,
multy,
ifail,
nstepx,
nstepy,
ispace,
xmin,
xmax] = g01aj(
x,
nstepx,
nstepy, 'n',
n, 'itype',
itype, 'ispace',
ispace, 'xmin',
xmin, 'xmax',
xmax)
[
xstep,
n1,
multy,
ifail,
nstepx,
nstepy,
ispace,
xmin,
xmax] = nag_stat_plot_histogram(
x,
nstepx,
nstepy, 'n',
n, 'itype',
itype, 'ispace',
ispace, 'xmin',
xmin, 'xmax',
xmax)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
xmin was made optional (default 0); xmax was made optional (default 0); ispace was made optional (default 0); itype was made optional (default 0); output parameters were reordered |
Description
A histogram is printed using vertical bars consisting of * characters. The output is directed to the current advisory message unit. It may be redirected by a call to
nag_file_set_unit_advisory (x04ab) before calling
nag_stat_plot_histogram (g01aj).
The following options are available:
(a) |
inclusion of all data values, or only of those lying within a specified range; |
(b) |
specification of the size of the histogram in the vertical and horizontal directions, and of positioning in the horizontal direction; |
(c) |
calculation of frequencies or cumulative frequencies in the histogram. |
The maximum and minimum data values used, the (integral) number of observations represented by each * in the histogram, and the step size per character position in the horizontal direction, are returned.
The histogram is headed FREQUENCY or CUM.FREQ. depending on the option selected. Each line is annotated with the minimum frequency which a bar reaching that line represents. The data maximum and minimum are printed under the histogram, unless either exceeds in modulus, in which case they are not printed (although they are still returned).
References
None.
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The data values.
- 2:
– int64int32nag_int scalar
-
The number of character positions to be used in the horizontal direction, i.e., the number of categories in the histogram.
- 3:
– int64int32nag_int scalar
-
The number of character positions to be used in the vertical direction, i.e., the maximum height of a histogram bar.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x.
The number of data values.
Constraint:
.
- 2:
– int64int32nag_int scalar
Default:
Indicates whether a histogram of frequencies or cumulative frequencies is required.
for frequencies.
for cumulative frequencies.
The second option effectively displays the distribution function of the data rather than the density function.
- 3:
– int64int32nag_int scalar
Default:
Indicates how many spaces are to be inserted at the beginning of each output line.
If on input, is used
If , then is used.
The second condition imposes an effective line length limit of characters.
- 4:
– double scalar
- 5:
– double scalar
Default:
If
, only those values in
x such that
, for
, are included in the histogram.
If , all the data are included.
Output Parameters
- 1:
– double scalar
-
The width of each class interval.
- 2:
– int64int32nag_int scalar
-
The total number of observations actually included in the histogram.
- 3:
– int64int32nag_int scalar
-
The number of observations represented by each * in the histogram.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
- 5:
– int64int32nag_int scalar
-
If
on entry,
nstepx is reset to
.
If
on entry,
nstepx is reset to
.
Otherwise,
nstepx is unchanged on exit.
- 6:
– int64int32nag_int scalar
-
If
on entry,
nstepy is reset to
.
If
on entry,
nstepy is reset to
.
Otherwise,
nstepy is unchanged on exit.
- 7:
– int64int32nag_int scalar
Default:
Unchanged unless
or
, in which case
ispace is set to
.
- 8:
– double scalar
- 9:
– double scalar
Default:
If
on entry, then
xmin and
xmax are unchanged.
If
then
xmin and
xmax contain the minimum and maximum data values respectively.
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Accuracy is limited by the number of plotting positions available.
Further Comments
The time taken by
nag_stat_plot_histogram (g01aj) increases with
n,
nstepx and
nstepy.
A total of character positions are used in the horizontal direction, not including the carriage control character. It is important that this total does not exceed the maximum line length available on the output device.
A total of
output lines are normally generated, one less if
xmin and/or
xmax is too large in modulus to be printed.
Example
A sample of
random numbers form the data, which correspond to a Normal distribution with mean and standard deviation both equal to
. A histogram of the entire sample is drawn first, followed by a cumulative histogram of all data values lying between
and
. The first histogram is indented
character positions. Note the use of
nag_file_set_unit_advisory (x04ab) to direct the output to unit number
.
Open in the MATLAB editor:
g01aj_example
function g01aj_example
fprintf('g01aj example results\n\n');
x = [ 2.68 8.23 0.11 1.39 -2.77 -1.17 3.49 7.39 ...
5.22 5.44 7.06 6.17 -4.44 5.98 14.02 8.06 ...
10.96 0.99 7.87 4.85 9.76 3.3 4.45 7.02 ...
5.43 3.57 1.98 3.09 -2.66 5.04 14.52 -0.61 ...
5.04 6.85 3.94 4.87 3.82 5.93 7.89 9.48 ...
6.81 6.91 7.76 6.21 0.55 -2.44 18.09 6.19 ...
9.19 10.55];
nstepx = int64(10);
nstepy = int64(10);
ispace = int64(10);
[xstep, n1, multy, ifail, nstepx, nstepy, ispace, xmin, xmax] = ...
g01aj( ...
x, nstepx, nstepy, 'ispace', ispace);
itype = int64(1);
ispace = int64(0);
xmin = -10;
xmax = 5;
[xstep, n1, multy, ifail, nstepx, nstepy, ispace, xmin, xmax] = ...
g01aj( ...
x, nstepx, nstepy, 'itype', itype, 'ispace', ispace, ...
'xmin', xmin, 'xmax', xmax);
g01aj example results
FREQUENCY
20 . . 20
18 . . 18
16 . . 16
14 . . 14
12 . * . 12
10 . ** . 10
8 . *** . 8
6 . *** . 6
4 .* ***** . 4
2 .******* * . 2
------------
-4.44 18.09
CUM. FREQ.
30 . . 30
27 . . 27
24 . . 24
21 . *. 21
18 . *. 18
15 . **. 15
12 . **. 12
9 . ***. 9
6 . ****. 6
3 . ******. 3
------------
-10.00 5.00
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015