IMSL C Math Library
table_oneway
Tallies observations into a one-way frequency table.
Synopsis
#include <imsl.h>
float *imsl_f_table_oneway (int n_observations, float x[], int n_intervals, , 0)
The type double function is imsl_d_table_oneway.
Required Arguments
int n_observations (Input)
Number of observations.
float x[] (Input)
Array of length n_observations containing the observations.
int n_intervals (Input)
Number of intervals (bins).
Return Value
Pointer to an array of length n_intervals containing the counts.
Synopsis with Optional Arguments
#include <imsl.h>
float *imsl_f_table_oneway (int n_observations, float x[], int n_intervals,
IMSL_DATA_BOUNDS, float *minimum, float *maximum,
IMSL_KNOWN_BOUNDS, float lower_bound, float upper_bound,
IMSL_CUTPOINTS, float cutpoints[],
IMSL_CLASS_MARKS, float class_marks[],
IMSL_RETURN_USER, float table_oneway[],
0)
Optional Arguments
IMSL_DATA_BOUNDS, float *minimum, float *maximum (Output)
or
IMSL_KNOWN_BOUNDS, float lower_bound, float upper_bound (Input)
or
IMSL_CUTPOINTS, float cutpoints[] (Input)
or
IMSL_CLASS_MARKS, float class_marks[] (Input)
None, or exactly one, of these four optional arguments can be specified in order to define the intervals or bins for the one-way table. If none is specified, or if IMSL_DATA_BOUNDS is specified, n_intervals, intervals of equal length, are used with the initial interval starting with the minimum value in x and the last interval ending with the maximum value in x. The initial interval is closed on the left and right. The remaining intervals are open on the left and closed on the right. When IMSL_DATA_BOUNDS is explicitly specified, the minimum and maximum values in x are output in minimum and maximum. With this option, each interval is of (maximumminimum)n_intervals length. If IMSL_KNOWN_BOUNDS is specified, two semi-infinite intervals are used as the initial and last interval. The initial interval is closed on the right and includes lower_bound as its right endpoint. The last interval is open on the left and includes all values greater than upper_bound. The remaining n_intervals  2 intervals are each of length
and are open on the left and closed on the right. Argument n_intervals must be greater than or equal to three for this option. If IMSL_CLASS_MARKS is specified, equally spaced class marks in ascending order must be provided in the array class_marks of length n_intervals. The class marks are the midpoints of each of the n_intervals, and each interval is taken to have length class_marks[1]  class_marks[0]. The argument n_intervals must be greater than or equal to two for this option. If IMSL_CUTPOINTS is specified, cutpoints (boundaries) must be provided in the array cutpoints of length n_intervals  1. This option allows unequal interval lengths. The initial interval is closed on the right and includes the initial cutpoint as its right endpoint. The last interval is open on the left and includes all values greater than the last cutpoint. The remaining n_intervals  2 intervals are open on the left and closed on the right. The argument n_interval must be greater than or equal to three for this option.
IMSL_RETURN_USER, float table[] (Output)
Counts are stored in the user-supplied array table of length n_intervals.
Examples
Example 1
The data for this example is from Hinkley (1977) and Velleman and Hoaglin (1981). They are the measurements (in inches) of precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.
 
#include <imsl.h>
int main()
{
int n_intervals=10;
int n_observations=30;
float *table;
float x[] = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05};
table = imsl_f_table_oneway (n_observations, x, n_intervals, 0);
imsl_f_write_matrix("counts", 1, n_intervals, table, 0);
}
Output
 
Counts
1 2 3 4 5 6
4 8 5 5 3 1
 
7 8 9 10
3 0 0 1
Example 2
This example selects IMSL_KNOWN_BOUNDS and sets lower_bound = 0.5 and upper_bound = 4.5 so that the eight interior intervals each have width (4.5  0.5)/(10  2) = 0.5. The 10 intervals are (−∞ 0.5], (0.5, 1.0], , (4.0, .5], and (4.5, ].
 
#include <imsl.h>
int main()
{
int n_observations=30;
int n_intervals=10;
float *table;
float lower_bound=0.5, upper_bound=4.5;
float x[] = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05};
table = imsl_f_table_oneway (n_observations, x, n_intervals,
IMSL_KNOWN_BOUNDS, lower_bound,
upper_bound, 0);
imsl_f_write_matrix("counts", 1, n_intervals, table, 0);
}
Output
 
Counts
1 2 3 4 5 6
2 7 6 6 4 2
 
7 8 9 10
2 0 0 1
Example 3
This example inputs 10 class marks 0.25, 0.75, 1.25, , 4.75. This defines the class intervals (0.0, 0.5], (0.5, 1.0], , (4.0, 4.5], (4.5, 5.0]. Note that unlike the previous example, the initial and last intervals are the same length as the remaining intervals.
 
#include <imsl.h>
int main()
{
int n_intervals=10;
int n_observations=30;
double *table;
double x[] = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43,
3.37, 2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62,
1.31, 0.32, 0.59, 0.81, 2.81, 1.87, 1.18, 1.35,
4.75, 2.48, 0.96, 1.89, 0.90, 2.05};
double class_marks[] = {0.25, 0.75, 1.25, 1.75, 2.25, 2.75,
3.25, 3.75, 4.25, 4.75};
table = imsl_d_table_oneway (n_observations, x, n_intervals,
IMSL_CLASS_MARKS, class_marks,
0);
imsl_d_write_matrix("counts", 1, n_intervals, table, 0);
}
Output
 
Counts
1 2 3 4 5 6
2 7 6 6 4 2
 
7 8 9 10
2 0 0 1
Example 4
This example inputs nine cutpoints 0.5, 1.0, 1.5, 2.0, , 4.5 to define the same 10 intervals as in Example 3. Here again, the initial and last intervals are semi-infinite intervals.
 
#include <imsl.h>
int main()
{
int n_intervals=10;
int n_observations=30;
double *table;
double x[] = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43,
3.37, 2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62,
1.31, 0.32, 0.59, 0.81, 2.81, 1.87, 1.18, 1.35,
4.75, 2.48, 0.96, 1.89, 0.90, 2.05};
double cutpoints[] = {0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0,
4.5};
table = imsl_d_table_oneway (n_observations, x, n_intervals,
IMSL_CUTPOINTS, cutpoints,
0);
imsl_d_write_matrix("counts", 1, n_intervals, table, 0);
}
Output
 
counts
1 2 3 4 5 6
2 7 6 6 4 2
 
7 8 9 10
2 0 0 1