StatBean Name: Crosstabulation

Purpose: Cross-tabulates 2 columns of data. For categorical data, finds the frequency of all unique values. For numeric data, finds the frequency within specified intervals. Also computes summary statistics for the resulting two-way table.

DataSource: any.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
byColumndoubleWidth of intervals (continuous data only).Any double value > 0.0.1
byRowdoubleWidth of intervals (continuous data only).Any double value > 0.0.1
caseSensitiveColumnbooleanWhether placing data values into classes is case sensitive.true,falsefalse
caseSensitiveRowbooleanWhether placing data values into classes is case sensitive.true,falsefalse
dataTypeColumnStringThe type of data to be tabulated. If Categorical, shows unique values. If Discrete, shows all integer values. If Continuous, shows number of values within intervals."Categorical",
"Discrete",
"Continuous"
"Categorical"
dataTypeRowStringThe type of data to be tabulated. If Categorical, shows unique values. If Discrete, shows all integer values. If Continuous, shows number of values within intervals."Categorical",
"Discrete",
"Continuous"
"Categorical"
fromColumndoubleLower limit for first interval (numeric data only).Any double value.0.0
fromRowdoubleLower limit for first interval (numeric data only).Any double value.0.0
toColumndoubleUpper limit for last interval (numeric data only).Double value > from.1.0
toRowdoubleUpper limit for last interval (numeric data only).Double value > from.1.0
rowVariableNameStringThe name of the row variable with data values to be tabulated.Any string."X"
columnVariableNameStringThe name of the column variable with data values to be tabulated.Any string.""

Other Public Methods
NameDescriptionArgumentsReturn Value
int getCountAboveColumn()For Continuous datatype, the number of data values greater than the last class.None.Number of values.
int getCountAboveRow()For Continuous datatype, the number of data values greater than the last class.None.Number of values.
int getCountBelowColumn()For Continuous datatype, the number of data values less than the first class.None.Number of values.
int getCountBelowRow()For Continuous datatype, the number of data values less than the first class.None.Number of values.
double getFrequencyCell(int row,int column)The number of data values in the selected row and column.Row and column numbers (0 origin).Number of values.
String getLabelsColumn()Returns the labels for each column class, separated by a tab character.None.Labels.
String getLabelsRow()Returns the labels for each row class, separated by a tab character.None.Labels.
double getLowerLimitColumn()For Continuous and Discrete datatypes, the lower limit of the first class.None.Lower limit.
double getLowerLimitRow()For Continuous and Discrete datatypes, the lower limit of the first class.None.Lower limit.
int getMeanColumn()For Continuous and Discrete datatypes, the sample mean for the column variable.None.Mean.
int getMeanRow()For Continuous and Discrete datatypes, the sample mean for the row variable.None.Mean.
int getNumberOfClassesColumn()Returns the number of classes k into which the data was tabulated.None.Number of classes.
int getNumberOfClassesRow()Returns the number of classes k into which the data was tabulated.None.Number of classes.
double getPercentageCellOfColumn(int row,int column)The percentage of data values in the selected row and column with respect to its column.Row and column numbers (0 origin).Percentage.
double getPercentageCellOfRow(int row,int column)The percentage of data values in the selected row and column with respect to its row.Row and column numbers (0 origin).Percentage.
double getPercentageCellOfTable(int row,int column)The percentage of data values in the selected row and column with respect to the entire table.Row and column numbers (0 origin).Percentage.
int getSigmaColumn()For Continuous and Discrete datatypes, the sample standard deviation for the column variable.None.Standard deviation.
int getSigmaRow()For Continuous and Discrete datatypes, the sample standard deviation for the row variable.None.Standard deviation.
int getTotalCount()Returns the sum of the frequencies.None.Total count.
double getUpperLimitColumn()For Continuous and Discrete datatypes, the upper limit of the last class.None.Upper limit.
double getUpperLimitRow()For Continuous and Discrete datatypes, the upper limit of the last class.None.Upper limit.

Output Variables
NameDescription
FrequencyColumnNumbers of data values in each class for the column variable.
FrequencyRowNumbers of data values in each class for the row variable.
LabelColumnLabels for each class.
LabelRowLabels for each class.
PercentageColumnPercentage of data values in each class for the row variable.
PercentageRowPercentage of data values in each class for the column variable.

Code Sample

//create a datasource bean
FileDataSource fileDataSource1 = new STATBEANS.FileDataSource();

//set the file name to be read
fileDataSource1.setFileName("c:\\statbeans\\samples\\cardata.txt");

//create a calculation bean
Crosstabulation crosstabulation1 = new STATBEANS.Crosstabulation();

//set the variables
crosstabulation1.setColumnVariableName("year");
crosstabulation1.setDataTypeColumn("discrete");
crosstabulation1.setRowVariableName("mpg");
crosstabulation1.setDataTypeRow("continuous");
crosstabulation1.setFromRow(10.0);
crosstabulation1.setToRow(50.0);
crosstabulation1.setByRow(10.0);

//create a table bean
TwowayTable twowayTable1 = new STATBEANS.TwowayTable();
twowayTable1.setBackground(Color.yellow);
twowayTable1.setBounds(10,30,520,200);
twowayTable1.setNumberOfColumnsInDisplay(7);
twowayTable1.setNumberOfRowsInDisplay(14);
add(twowayTable1);

//create a plot bean
TwowayBarchart twowayBarchart1 = new STATBEANS.TwowayBarchart();
twowayBarchart1.setBounds(10,230,260,200);
twowayBarchart1.setBackground(Color.yellow);
add(twowayBarchart1);

//create a second plot bean
MosaicPlot mosaicPlot1 = new STATBEANS.MosaicPlot();
mosaicPlot1.setBounds(270,230,260,200);
mosaicPlot1.setBackground(Color.yellow);
add(mosaicPlot1);

//create a third plot bean
SkyChart skyChart1 = new STATBEANS.SkyChart();
skyChart1.setBounds(140,430,260,200);
skyChart1.setBackground(Color.yellow);
skyChart1.setBarWidthY(100);
add(skyChart1);

//calculate some statistics
ContingencyTableStats stats1=new ContingencyTableStats();

//make the crosstabulation bean a listener for changes in the FileDataSource bean
fileDataSource1.addDataChangeListener(crosstabulation1.listenerForDataChange);

//make the other beans listeners for changes in the calculation bean
crosstabulation1.addDataChangeListener(twowayTable1.listenerForDataChange);
crosstabulation1.addDataChangeListener(twowayBarchart1.listenerForDataChange);
crosstabulation1.addDataChangeListener(mosaicPlot1.listenerForDataChange);
crosstabulation1.addDataChangeListener(skyChart1.listenerForDataChange);
crosstabulation1.addDataChangeListener(stats1.listenerForDataChange);

//instruct the fileDataSource bean to read the file
fileDataSource1.readData();

//retrieve the statistics
double chisquared=stats1.getChiSquared();
double p=stats1.getChiSquaredPValue();
int df=stats1.getChiSquaredDf();