Class TableTwoWay
- All Implemented Interfaces:
Serializable,Cloneable
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:
- equal width class intervals based upon the smallest and largest observations,
- equal width class intervals based upon a user provided minimum and maximum,
- class intervals defined from user provided class midpoints, and
- 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:
-
Constructor Summary
ConstructorsConstructorDescriptionTableTwoWay(double[] x, int xIntervals, double[] y, int yIntervals) Constructor forTableTwoWay. -
Method Summary
Modifier and TypeMethodDescriptiondouble[][]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 class marks.double[][]getFrequencyTableUsingCutpoints(double[] cx, double[] cy) Returns the two-way frequency table using cutpoints.doubleReturns the maximum value of x.doubleReturns the maximum value of y.doubleReturns the minimum value of x.doubleReturns the minimum value of y.
-
Constructor Details
-
TableTwoWay
public TableTwoWay(double[] x, int xIntervals, double[] y, int yIntervals) Constructor forTableTwoWay.- Parameters:
x- Adoublearray containing the data for the first variable.xIntervals- Anintscalar containing the number of intervals (bins) for variable x.y- Adoublearray containing the data for the second variable.yIntervals- Anintscalar containing the number of intervals (bins) for variable y.
-
-
Method Details
-
getMinimumX
public double getMinimumX()Returns the minimum value of x.- Returns:
- a
doublecontaining the minimum data bound for x.
-
getMinimumY
public double getMinimumY()Returns the minimum value of y.- Returns:
- a
doublecontaining the minimum data bound for y.
-
getMaximumX
public double getMaximumX()Returns the maximum value of x.- Returns:
- a
doublecontaining the maximum data bound for x.
-
getMaximumY
public double getMaximumY()Returns the maximum value of y.- Returns:
- a
doublecontaining the maximum data bound for y.
-
getFrequencyTable
public double[][] getFrequencyTable()Returns the two-way frequency table. Intervals of equal length are used. Letxminandxmaxbe the minimum and maximum values in x, respectively, with similiar meanings foryminandymax. Then, the first row of the output table is the tally of observations with the x value less than or equal toxmin + (xmax - xmin)/xIntervals, and the y value less than or equal toymin + (ymax - ymin)/yIntervals.- Returns:
- A two-dimensional
doublearray 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 arrayscxandcy, 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 tocx[0], and the y value is less than or equal tocy[0]. This option allows unequal interval lengths. Argumentscxandcymust be greater than or equal to 2.- Parameters:
cx-doublearray containing the cutpoints forx.cy-doublearray containing the cutpoints fory.- Returns:
- A two dimensional
doublearray containing the two-way frequency table.
-
getFrequencyTableUsingClassmarks
public double[][] getFrequencyTableUsingClassmarks(double[] cx, double[] cy) Returns the two-way frequency table using class marks. Class marks are the midpoints ofxIntervalsandyIntervals. Equally spaced class marks in ascending order must be provided in the arrayscxandcy. The class marks are the midpoints of each interval. Each interval is taken to have lengthcx[1] - cx[0]in the x direction andcy[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. ArgumentsxIntervalsandyIntervalsmust be greater than or equal to 2 for this option.- Parameters:
cx-doublearray containing the class marks forx.cy-doublearray containing the class marks fory.- Returns:
- A two dimensional
doublearray 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.xIntervalsandyIntervalsmust be greater than or equal to 3.- Parameters:
xLowerBound-doublespecifies the right endpoint forx.xUpperBound-doublespecifies the left endpoint forx.yLowerBound-doublespecifies the right endpoint fory.yUpperBound-doublespecifies the left endpoint fory.- Returns:
- A two dimensional
doublearray containing the two-way frequency table.
-