StatBean Name: Correlations

Purpose: Computes product-moment and rank correlation coefficients between pairs of numeric columns.

DataSource: Any.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
columnNamesString arrayThe names of the columns to be analyzed.One or more strings.{""}
computeRankCorrelationsbooleanWhether to compute rank correlations as well as product-moment correlations.true,falsefalse
missingValueExclusionStringThe method for handling records which contain missing values."Columnwise","Casewise",
"Tablewise"
"Columnwise"

Other Public Methods
NameDescriptionArgumentsReturn Value
double getCorrelation(int columnNumber,int rowNumber)Returns product-moment correlation.Column number, row number (0 origin).Estimated correlation, or missingValueCode if n<2.
double getPValue(int columnNumber,int rowNumber)Returns P-value for two-sided test of null hypothesis that correlation = 0.Column number, row number (0 origin).P-value.
double getRankCorrelation(int columnNumber,int rowNumber)Returns Spearman rank correlation.Column number, row number (0 origin).Estimated correlation, or missingValueCode if n<2.
double getRankPValue(int columnNumber,int rowNumber)Returns P-value for two-sided test of null hypothesis that rank correlation = 0.Column number, row number (0 origin).P-value.
int getNumberOfVariables()Returns number of columns.None.Number of columns (and rows).
int getSampleSize(int columnNumber,int rowNumber)Returns number of pairs of data values used to calculate correlation.Column number, row number (0 origin).n

Code Sample

//create a filedatasource bean
FileDataSource fileDataSource1 = new FileDataSource();

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

//create a calculation bean
Correlations correlations1 = new Correlations();

//set missing value handling
correlations1.setMissingValueExclusion("Columnwise");

//set the column names
String[] temp = new String[5];
temp[0] = new String("mpg");
temp[1] = new String("weight");
temp[2] = new String("horsepower");
temp[3] = new String("displace");
temp[4] = new String("price");
correlations1.setColumnNames(temp);

//create a table bean
CorrelationsTable correlationsTable1 = new CorrelationsTable();

//set table size
correlationsTable1.setScaleRowsToFit(false);
correlationsTable1.setScaleColumnsToFit(false);
correlationsTable1.setNumberOfRowsInDisplay(15);
correlationsTable1.setNumberOfColumnsInDisplay(5);

//prevent some rows and columns from scrolling
correlationsTable1.setHoldRows(3);
correlationsTable1.setHoldColumns(1);

//add the table to the display panel
add(correlationsTable1);

//register the calculation StatBean as a listener to the datasource
fileDataSource1.addDataChangeListener(correlations1.listenerForDataChange);

//register the table StatBean as a listener to the calculation StatBean
correlations1.addDataChangeListener(correlationsTable1.listenerForDataChange);

//read the file
fileDataSource1.readData();

//notify all listeners
fileDataSource1.updateListeners();