JMSLTM Numerical Library 5.0.1

com.imsl.stat
Class TableTwoWay

java.lang.Object
  extended by com.imsl.stat.TableTwoWay
All Implemented Interfaces:
Serializable, Cloneable

public class TableTwoWay
extends Object
implements Serializable, Cloneable

Class TableTwoWay calculates a two-dimensional frequency table for a data array based upon two variables.

A two-way frequency table can be used to visualize the shape of the bivariate distribution and look for anomalies in the data. There are many approaches to constructing two-way frequency tables. Four approaches are implemented in this class:

  1. equal width class intervals based upon the smallest and largest observations,
  2. equal width class intervals based upon a user provided minimum and maximum,
  3. class intervals defined from user provided class midpoints, and
  4. class intervals defined from user provided class boundaries.

The TableTwoWay class implements the first two approaches by overloading the getFrequencyTable method. If getFrequencyTable() is used without input arguments, xIntervals intervals of equal length are formed between the minimum and maximum values in x, and similarly, yIntervals intervals are formed for y. The frequency table returned from this method contains tallies of the number of observations in each interval. The data minimum and maximum can be obtained using getMinimumX, getMinimumY, getMaximumX and getMaximumY.

Instead of using the minimum and maximum to define the boundaries of the smallest and largest classes, specified boundaries can be used by calling getFrequencyTable(xLowerBound, xUpperBound, yLowerBound, yUpperBound)). This method tallies all data less than or equal to the xLowerBound and yLowerBound into the first class, and all data greater than or equal to xUpperBound and YUpperBround into the last class

The third approach is implemented using the getFrequencyTableUsingClassmarks method. Equally spaced intervals can be defined using class marks. In this approach two double precision arrays of length xIntervals and yIntervals containing the class midpoints for x and y respectively are passed to the getFrequencyTableUsingClassmarks(cx[], cy[]). The class marks, or midpoints, must be equally spaced.

Finally in those applications where unequal length intervals are preferred, the getFrequencyTableUsingCutpoints(cx[], cy[]) method can be used. The double precision arrays cx and cy with lengths xIntervals-1 and yIntervals-1 respectively contain the class boundaries listed in ascending order. The first cut point defines the first class which is used to tally all data less than or equal to the first cut point value. The last cut point defines the last class which is used to tally all data greater than or equal to the last cut point value.

See Also:
Example, Serialized Form

Constructor Summary
TableTwoWay(double[] x, int xIntervals, double[] y, int yIntervals)
          Constructor for TableTwoWay.
 
Method Summary
 double[][] getFrequencyTable()
          Returns the two-way frequency table.
 double[][] getFrequencyTable(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound)
          Compute a two-way frequency table using intervals of equal length and user supplied upper and lower bounds, xLowerBound, xUpperBound, yLowerBound, yUpperBound.
 double[][] getFrequencyTableUsingClassmarks(double[] cx, double[] cy)
          Returns the two-way frequency table using either cutpoints or class marks.
 double[][] getFrequencyTableUsingCutpoints(double[] cx, double[] cy)
          Returns the two-way frequency table using cutpoints.
 double getMaximumX()
          Returns the maximum value of x.
 double getMaximumY()
          Returns the maximum value of y.
 double getMinimumX()
          Returns the minimum value of x.
 double getMinimumY()
          Returns the minimum value of y.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableTwoWay

public TableTwoWay(double[] x,
                   int xIntervals,
                   double[] y,
                   int yIntervals)
Constructor for TableTwoWay.

Parameters:
x - A double array containing the data for the first variable.
xIntervals - An int scalar containing the number of intervals (bins) for variable x.
y - A double array containing the data for the second variable.
yIntervals - An int scalar containing the number of intervals (bins) for variable y.
Method Detail

getFrequencyTable

public double[][] getFrequencyTable()
Returns the two-way frequency table. Intervals of equal length are used. Let xmin and xmax be the minimum and maximum values in x, respectively, with similiar meanings for ymin and ymax. Then, the first row of the output table is the tally of observations with the x value less than or equal to xmin + (xmax - xmin)/xIntervals, and the y value less than or equal to ymin + (ymax - ymin)/yIntervals.

Returns:
A two-dimensional double array containing the two-way frequency table.

getFrequencyTable

public double[][] getFrequencyTable(double xLowerBound,
                                    double xUpperBound,
                                    double yLowerBound,
                                    double yUpperBound)
Compute a two-way frequency table using intervals of equal length and user supplied upper and lower bounds, xLowerBound, xUpperBound, yLowerBound, yUpperBound. The first and last intervals for both variables are semi-infinite in length. xIntervals and yIntervals must be greater than or equal to 3.

Parameters:
xLowerBound - double specifies the right endpoint for x.
xUpperBound - double specifies the left endpoint for x.
yLowerBound - double specifies the right endpoint for y.
yUpperBound - double specifies the left endpoint for y.
Returns:
A two dimensional double array containing the two-way frequency table.

getFrequencyTableUsingClassmarks

public double[][] getFrequencyTableUsingClassmarks(double[] cx,
                                                   double[] cy)
Returns the two-way frequency table using either cutpoints or class marks. Cutpoints are boundaries and class marks are the midpoints of xIntervals and yIntervals. 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 the output table may be less than the number of observations of input data. Arguments xIntervals and yIntervals must be greater than or equal to 2 for this option.

Parameters:
cx - double array containing either the cutpoints or the class marks for x.
cy - double array containing either the cutpoints or the class marks for y.
Returns:
A two dimensional double array containing the two-way frequency table.

getFrequencyTableUsingCutpoints

public double[][] getFrequencyTableUsingCutpoints(double[] cx,
                                                  double[] cy)
Returns the two-way frequency table using cutpoints. The cutpoints (boundaries) must be provided in the arrays cx and cy, of length (xIntervals-1) and (yIntervals-1) respectively. The first row of the output table is the tally 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 cx and cy must be greater than or equal to 2.

Parameters:
cx - double array containing either the cutpoints or the class marks for x.
cy - double array containing either the cutpoints or the class marks for y.
Returns:
A two dimensional double array containing the two-way frequency table.

getMaximumX

public double getMaximumX()
Returns the maximum value of x.

Returns:
a double containing the maximum data bound for x.

getMaximumY

public double getMaximumY()
Returns the maximum value of y.

Returns:
a double containing the maximum data bound for y.

getMinimumX

public double getMinimumX()
Returns the minimum value of x.

Returns:
a double containing the minimum data bound for x.

getMinimumY

public double getMinimumY()
Returns the minimum value of y.

Returns:
a double containing the minimum data bound for y.

JMSLTM Numerical Library 5.0.1

Copyright © 1970-2008 Visual Numerics, Inc.
Built July 8 2008.