Chapter 1: Basic Statistics

.p>.CSCH1.DOC!TABLE_ONEWAY;table_oneway

Tallies observations into a one-way frequency table.

Synopsis

#include <imsls.h>

float *imsls_f_table_oneway (int n_observations, float x[],
int n_intervals, ..., 0)

The type double function is imsls_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 <imsls.h>

float *imsls_f_table_oneway (int n_observations, float x[], int n_intervals,
IMSLS_DATA_BOUNDS, float *minimum, float *maximum, or
IMSLS_KNOWN_BOUNDS, float lower_bound, float upper_bound, or
IMSLS_CUTPOINTS, float cutpoints[], or
IMSLS_CLASS_MARKS, float class_marks[],
IMSLS_RETURN_USER, float table[],
0)

Optional Arguments

IMSLS_DATA_BOUNDS, float *minimum, float *maximum   (Output)
If none is specified or if IMSLS_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 IMSLS_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 length (maximum  minimum)/n_intervals.

or

IMSLS_KNOWN_BOUNDS, float lower_bound, float upper_bound   (Input)
If IMSLS_KNOWN_BOUNDS is specified, two semi-infinite intervals are used as the initial and last intervals. 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 3 for this option.

or

IMSLS_CUTPOINTS, float cutpoints[]   (Input)
If IMSLS_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. Argument n_interval must be greater than or equal to 3 for this option.

or

IMSLS_CLASS_MARKS, float class_marks[]   (Input)
If IMSLS_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. Each interval is assumed to have length class_marks [1 class_marks [0]. Argument n_intervals must be greater than or equal to 2 for this option.

            None or exactly one of the four optional arguments described above can be specified in order to define the intervals or bins for the one-way table.

IMSLS_RETURN_USER, float table[]   (Output)
Counts are stored in the array table of length n_intervals, which is provided by the user.

Examples

Example 1

The data for this example is from Hinkley (1977) and Velleman and Hoaglin (1981). The measurements (in inches) are for precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.

#include <imsls.h>
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 = imsls_f_table_oneway (n_observations, x, n_intervals, 0);
    imsls_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

In this example, IMSLS_KNOWN_BOUNDS is used, and lower_bound = 0.5 and upper_bound = 4.5 are set 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, 4.5], and (4.5, ].

#include <imsls.h>
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 = imsls_f_table_oneway (n_observations, x, n_intervals,
                                IMSLS_KNOWN_BOUNDS, lower_bound,
                                upper_bound,
                                0);
    imsls_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

In this example, 10 class marks, 0.25, 0.75, 1.25, ..., 4.75, are input. 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 <imsls.h>
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 = imsls_d_table_oneway (n_observations, x, n_intervals,
                                IMSLS_CLASS_MARKS, class_marks,
                                0);
    imsls_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

In this example, cutpoints, 0.5, 1.0, 1.5, 2.0, ..., 4.5, are input to define the same 10 intervals as in Example 2. Here again, the initial and last intervals are semi-infinite intervals.

#include <imsls.h>
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 = imsls_d_table_oneway (n_observations, x, n_intervals,
                                IMSLS_CUTPOINTS, cutpoints,
                                0);
    imsls_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


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260