table_twoway

Tallies observations into two-way frequency table.

Synopsis

#include <imsls.h>

float *imsls_f_table_twoway (int n_observations, float x[], float y[], int nx, int ny, ..., 0)

The type double function is imsls_d_table_twoway.

Required Arguments

int n_observations (Input)
Number of observations.

float x[] (Input)
Array of length n_observations containing the data for the first variable.

float y[] (Input)
Array of length n_observations containing the data for the second variable.

int nx (Input)
Number of intervals (bins) for variable x.

int ny (Input)
Number of intervals (bins) for variable y.

Return Value

Pointer to an array of size nx by ny containing the counts.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_table_twoway (int n_observations, float x[], float y[], int nx, int ny,

IMSLS_DATA_BOUNDS, float *xmin, float *xmax, float *ymin, float *ymax, or

IMSLS_KNOWN_BOUNDS, float xlo, float xhi, float ylo, float yhi, or

IMSLS_CUTPOINTS, float cx[], float cy[], or

IMSLS_CLASS_MARKS, float cx[], float cy[],

IMSLS_RETURN_USER, float table[],

0)

Optional Arguments

IMSLS_DATA_BOUNDS, float *xlo, float *xhi, float *ylo, float *yhi (Output)
If none is specified or if IMSLS_DATA_BOUNDS is specified, n_intervals intervals of equal length are used. Let xmin and xmax be the minimum and maximum values in x, respectively, with similar meanings for ymin and ymax. Then, table[0] is the tally of observations with the x value less than or equal to xmin + (xmax xmin)/nx, and the y value less than or equal to ymin + (ymax  ymin)/ny. When IMSLS_DATA_BOUNDS is explicitly specified, the minimum and maximum values in x and y are output in xmin, xmax, ymin, and ymax.

or

IMSLS_KNOWN_BOUNDS, float xlo, float xhi, float ylo, float yhi (Input)
Intervals of equal lengths are used just as in the case of IMSLS_DATA_BOUNDS, except the upper and lower bounds are taken as the user supplied variables xlo, xhi, ylo, and yhi, instead of the actual minima and maxima in the data. Therefore, the first and last intervals for both variables are semi-infinite in length. Arguments nx and ny must be greater than or equal to 3.

or

IMSLS_CUTPOINTS, float cx[], float cy[] (Input)
If IMSLS_CUTPOINTS is specified, cutpoints (boundaries) must be provided in the arrays cx and cy, of length (nx-1) and (ny-1) respectively. The tally in table[0] is the number of observations for which the x value is less than or equal to cx[0], and the y value is less than or equal to cy[0]. This option allows unequal interval lengths. Arguments nx and ny must be greater than or equal to 2.

or

IMSLS_CLASS_MARKS, float cx[], float cy[] (Input)
If IMSLS_CLASS_MARKS is specified, equally spaced class marks in ascending order must be provided in the arrays cx and cy. The class marks are the midpoints of each interval. Each interval is taken to have length cx[1] cx[0] in the x direction and cy[1]  cy[0] in the y direction. The total number of elements in table may be less than n_observations. Arguments nx and ny must be greater than or equal to 2.

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 size nx by ny, which is provided by the user.

Examples

Example 1

The data for x in this example are the same as those used in the examples for imsls_f_table_oneway. The data for y were created by adding small integers to the data in x. This example uses the default tally method, IMSLS_DATA_BOUNDS, which may be appropriate when the range of the data is unknown.

 

#include <imsls.h>

 

int main()

{

int nx = 5;

int ny = 6;

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};

float y[] = {1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37,

3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32,

1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96,

2.89, 2.90, 5.05};

table = imsls_f_table_twoway (n_observations, x, y, nx, ny, 0);

imsls_f_write_matrix("counts", nx, ny, table,

IMSLS_ROW_NUMBER_ZERO, IMSLS_COL_NUMBER_ZERO, 0);

}

Output

 

counts

0 1 2 3 4 5

0 4 2 4 2 0 0

1 0 4 3 2 1 0

2 0 0 1 2 0 1

3 0 0 0 0 1 2

4 0 0 0 0 0 1

Example 2

In this example, xlo, xhi, ylo, and yhi are chosen so that the intervals will be 0 to 1, 1 to 2, and so on for x, and 1 to 2, 2 to 3, and so on for y.

 

#include <imsls.h>

 

int main()

{

int nx = 5;

int ny = 6;

int n_observations=30;

float *table;

float xlo = 1.0;

float xhi = 4.0;

float ylo = 2.0;

float yhi = 6.0;

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};

float y[] = {1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37,

3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32,

1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96,

2.89, 2.90, 5.05};

table = imsls_f_table_twoway (n_observations, x, y, nx, ny,

IMSLS_KNOWN_BOUNDS, xlo, xhi, ylo, yhi, 0);

imsls_f_write_matrix("counts", nx, ny, table,

IMSLS_ROW_NUMBER_ZERO, IMSLS_COL_NUMBER_ZERO, 0);

}

Output

 

counts

0 1 2 3 4 5

0 3 2 4 0 0 0

1 0 5 5 2 0 0

2 0 0 1 3 2 0

3 0 0 0 0 0 2

4 0 0 0 0 1 0

Example 3

In this example, the class boundaries are input in cx and cy. The same intervals are chosen as in Example 2, where the first element of cx and cy specify the first cutpoint between classes.

 

#include <imsls.h>

 

int main()

{

int nx = 5;

int ny = 6;

int n_observations=30;

float *table;

float cmx[] = {0.5, 1.5, 2.5, 3.5, 4.5};

float cmy[] = {1.5, 2.5, 3.5, 4.5, 5.5, 6.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};

float y[] = {1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37,

3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32,

1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96,

2.89, 2.90, 5.05};

table = imsls_f_table_twoway (n_observations, x, y, nx, ny,

IMSLS_CLASS_MARKS, cmx, cmy, 0);

imsls_f_write_matrix("counts", nx, ny, table,

IMSLS_ROW_NUMBER_ZERO, IMSLS_COL_NUMBER_ZERO, 0);

}

Output

 

 

counts

0 1 2 3 4 5

0 3 2 4 0 0 0

1 0 5 5 2 0 0

2 0 0 1 3 2 0

3 0 0 0 0 0 2

4 0 0 0 0 1 0

Example 4

This example, uses the IMSLS_CUTPOINTS tally option with cutpoints such that the intervals are specified as in the previous examples.

 

#include <imsls.h>

int main()

{

int nx = 5;

int ny = 6;

int n_observations=30;

float *table;

float cpx[] = {1, 2, 3, 4};

float cpy[] = {2, 3, 4, 5, 6};

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};

float y[] = {1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37,

3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32,

1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96,

2.89, 2.90, 5.05};

table = imsls_f_table_twoway (n_observations, x, y, nx, ny,

IMSLS_CUTPOINTS, cpx, cpy, 0);

imsls_f_write_matrix("counts", nx, ny, table,

IMSLS_ROW_NUMBER_ZERO, IMSLS_COL_NUMBER_ZERO, 0);

}

Output

 

 

counts

0 1 2 3 4 5

0 3 2 4 0 0 0

1 0 5 5 2 0 0

2 0 0 1 3 2 0

3 0 0 0 0 0 2

4 0 0 0 0 1 0