public class ContingencyTable
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
boolean |
diagonal |
int |
iterated |
double |
itsTotalSum |
int |
MatrixCols |
int |
MatrixRows |
int |
NUM_MAXITERATOR |
int |
PRECISIONMULT |
Constructor and Description |
---|
ContingencyTable(double[] col1)
standard constructor for the ContingencyTable class which installs values into column 1
|
ContingencyTable(double[][] theArray)
standard constructor for the ContingencyTable class
|
ContingencyTable(double[][] theArray,
boolean diagonal)
standard constructor for the ContingencyTable class
|
ContingencyTable(int MatrixCols,
int MatrixRows)
standard constructor for the ContingencyTable class
|
ContingencyTable(int MatrixCols,
int MatrixRows,
boolean diagonal)
standard constructor for the ContingencyTable class
|
ContingencyTable(int MatrixCols,
int MatrixRows,
boolean diagonal,
java.lang.String theName)
standard constructor for the ContingencyTable class
|
ContingencyTable(int MatrixCols,
int MatrixRows,
java.lang.String theName)
standard constructor for the ContingencyTable class
|
ContingencyTable(Matrix aMatrix,
boolean diagonal)
constructor for the ContingencyTable class with a JAMA Matrix provided
|
Modifier and Type | Method and Description |
---|---|
double[][] |
as2DdoubleArray()
returns the private array of data values for the ContingencyTable
|
java.lang.String[][] |
as2DStringArray()
returns the private array of data values for the ContingencyTable
|
Matrix |
asJAMAMatrix()
returns the private array of data values for the ContingencyTable
|
ContTableResults |
calcContingencyResults(ContingencyTable expectMatrix)
calculates the test of independence and returns ChiSquare and GValue
|
GoodnessOfFitResults |
calcGoodnessOfFitResults()
calculates the test of independence and returns ChiSquare and GValue
|
boolean |
checkDiagonal()
does the matrix have a diagonal?
|
boolean |
checkForColumnPs()
checks whether column probabilities have been set
|
boolean |
checkForZeros()
checks whether any column probabiities are zero
|
boolean |
checkMatchingMatrixDimensions(ContingencyTable BTable)
examine whether this matrix has the same dimensions as the one provided?
|
void |
checkMatrix()
examines the matrix for invalid entries
|
boolean |
checkMinimumN(int n)
checks whether enough data points are included
|
boolean |
checkSquare()
check whether matrix is square
|
void |
clearColumnPs()
clears the external probabilities
|
void |
clearPs()
clears the external probabilities
|
void |
clearSums()
zero the sums for rows, columns, and total of the ContingencyTable
|
void |
clearTable()
zero the sums for all individual cells of the ContingencyTable
|
void |
clearTablePs()
clears the external probabilities
|
java.lang.Object |
clone()
clone the object
|
java.lang.String |
colToString(int col)
returns the formatted object as a string
|
double |
DoWilliamsCorr()
calculates the William's correction
|
int |
fillPerms()
fills the array with all possible (or desired) permutations
|
void |
fillSums()
calculate sums for rows, columns and total of the ContingencyTable
|
DataTable |
fold(double[] cells,
int rows,
int cols,
boolean diag)
folds an array of doubles into a DataTable and returns the object
|
SpatialVector |
getCell(int xLoc,
int yLoc)
returns the double from one element of this matrix
|
double |
getCellValue(int xLoc,
int yLoc)
returns the double from one element of this matrix
|
java.lang.String |
getColLabel(int column)
returns a particular column label for the ContingencyTable
|
java.lang.String[] |
getColLabels()
returns column labels for the ContingencyTable
|
double |
getColSum(int col)
returns the sum for a particular row of the table
|
double[] |
getColSums()
returns the row sums of the table
|
double[] |
getColumnPs()
returns the dimensions of the Table
|
ContTableResults |
getContingencyTableResults()
returns the results for a test of independence with expected frequencies calculated from observed
|
ContTableResults |
getContingencyTableResults(ContingencyTable expectMatrix)
returns the results for a test of independence with the provided expected values
|
int |
getdf()
returns the degrees of freedom for the ContingencyTable
|
ContingencyTable |
getDifferenceTable(ContingencyTable bTable)
returns a matrix of dominance relationships between actor and receiver
|
double[][] |
getDominanceMatrix()
returns a matrix of dominance relationships between actor and receiver
|
ContingencyTable |
getExpectedMatrix()
returns a matrix of expected values for a test of independence
|
ContingencyTable |
getExpectedMatrix(boolean aDiagonal)
returns a matrix of expected values for a test of independence
|
DataTable |
getExpMatrixDia()
returns a matrix of expected values for a test of independence
|
DataTable |
getExpMatrixFromProbabilities()
returns a matrix of expected values for a test of independence
|
ContingencyTable |
getExpMatrixNoDia()
returns a matrix of expected values for a test of independence if the diagonal
is structurally zero
|
DataTable |
getFTukeyDeviates()
returns Freeman-Tukey deviates for a cell wise examination of the table
|
GoodnessOfFitResults |
getGoodnessOfFitResults()
coordinates a replicated goodness of fit test
|
double |
getMantelP(ContingencyTable BTable,
double actualMantelNumber)
performs Mantel's test with number of permutations limited by MaxPermutations
|
double |
getMantelZ(ContingencyTable BTable)
calculate Mantel's Z statistic for a matrix and a second matrix passed in
|
int |
getMatrixSize()
returns the dimensions of the Table
|
SpatialVector |
getMaxValueCell()
returns a matrix of dominance relationships between actor and receiver
|
SpatialVector |
getMinValueCell()
returns a matrix of dominance relationships between actor and receiver
|
java.lang.String |
getName()
returns the dimensions of the Table
|
int |
getNCells()
returns the total number of cells for the ContingencyTable
|
int |
getNCellsAboveEqualValue(double compVal)
returns the number of cells above or equal to a given value
|
int |
getNCellsAboveValue(double compVal)
returns the number of cells above a given value
|
int |
getNCellsBelowEqualValue(double compVal)
returns the number of cells below or equal to a given value
|
int |
getNCellsBelowValue(double compVal)
returns the number of cells below a given value
|
int |
getNCols()
returns the number of columns of the Table
|
int |
getNDiagonals()
returns the total number of diagonal cells for the ContingencyTable
|
double[][] |
getNoZeroCellMatrix()
returns the values from the matrix with a constant of 0.25 added to each cell
|
int |
getNRows()
returns the number of rows of the Table
|
ContingencyTable |
getPermutedTable(int[] permOrder)
gets a variant of the interactionTable with rows and columns switched with
a given permutation
|
ContingencyTable |
getPropMatrixDia()
returns a matrix of expected values for proportional fitting with diagonal
present
|
ContingencyTable |
getPropMatrixNoDia()
returns a matrix of expected values for proportional fitting with diagonal
absent (see Bishop et al., 1975; following Freeman, 1992)
|
java.lang.String |
getRowLabel(int row)
returns a particular row label for the ContingencyTable
|
java.lang.String[] |
getRowLabels()
returns row labels for the ContingencyTable
|
double |
getRowSum(int row)
returns the sum for a particular row of the table
|
double[] |
getRowSums()
returns the row sums of the table
|
double[][] |
getTablePs()
returns the dimensions of the Table
|
double |
getTauKr()
organize a TauKr test for a correlation between actor and receiver matrix
|
double |
getTauKrP(double actualKrNumber)
performs the Kr test with number of permutations limited by MaxPermutations
|
double[][] |
getTotalsMatrix()
returns a matrix in which cells from actor and receiver section
of the ContingencyTable have been summed into a total cell value
|
double |
getTotalSum()
returns the sum for a particular row of the table
|
int |
getZeroCells()
returns the number of empty cells for the ContingencyTable
|
int |
howManyPossiblePermutations()
calculates the number of possible permutations
|
void |
incrementCellValue(int xLoc,
int yLoc)
increments a single cell for this matrix by one
|
ContingencyTable |
invertTable()
inverts the table with rows to colums and colums to rows
|
boolean |
isMatchingMatrix(ContingencyTable BTable)
does this matrix have the same values as the provided one?
|
boolean |
isSquare()
is matrix square?
|
void |
listContingencyTableResults()
does the test and returns its results
|
void |
listExpectedTable()
lists a matrix of expected values
|
void |
listFTukeyDeviates()
lists Freeman-Tukey deviates for a cell wise examination of the table
|
void |
listGoodnessOfFitResults()
reports the results for a replicated goodness of fit test with external hypothesis probabilities
|
void |
listMantelZResults(ContingencyTable BTable)
lists Mantel's Z for the table
|
void |
listTable()
lists the table
|
void |
listTable(boolean doSums)
lists the table
|
void |
listTauKrResults()
lists the Tau Kr for the table
|
java.lang.String |
rowToString(int row)
returns the formated object as a string
|
void |
set2DArray(double[][] inMatrix)
sets a 2D array of doubles for the ContingencyTable
|
void |
setCellValue(int xLoc,
int yLoc,
double inValue)
sets a single element for this matrix with a double
|
void |
setColLabel(int column,
java.lang.String aString)
returns a particular column label for the ContingencyTable
|
void |
setColLabels(java.lang.String[] Labels)
sets new row and column labels for the ContingencyTable
|
void |
setColLabels(java.util.TreeMap<?,?> Labels)
sets new row and column labels for the ContingencyTable
|
void |
setColumnPs(double[] thePs)
sets the expected probabilities for different columns
|
void |
setDefaultRowColLabels()
sets default labels for row and column labels for the ContingencyTable
|
void |
setDiagonal(boolean diagonal)
sets the diagonal of the ContingencyTable and resets all cell values
|
void |
setMatrixDimensions(int MatrixCols,
int MatrixRows,
boolean diagonal)
sets new matrix dimensions for the ContingencyTable
|
void |
setMatrixSize(int MatrixSize)
sets the dimensions of the DominanceTable
|
void |
setName(java.lang.String theName)
sets the name for the ContingencyTable
|
void |
setRowColLabels(java.lang.String[] Labels)
sets new row and column labels for the ContingencyTable
|
void |
setRowColLabels(java.util.TreeMap<?,?> Labels)
sets new row and column labels for the ContingencyTable
|
void |
setRowLabel(int row,
java.lang.String aString)
returns a particular column label for the ContingencyTable
|
void |
setRowLabels(java.lang.String[] Labels)
sets new row and column labels for the ContingencyTable
|
void |
setRowLabels(java.util.TreeMap<?,?> Labels)
sets new row and column labels for the ContingencyTable
|
void |
setTablePs(double[][] theTPs)
sets the expected probabilities for different columns
|
double |
TauKr(ContingencyTable BTable)
calculate Kendal's tau statistic for a matrix and a second matrix passed in
|
void |
toFile(java.io.BufferedWriter bw)
writes a ContingencyTable into the writer for a file
|
java.lang.String |
toString(boolean doSums)
returns the formatted object as a string
|
ContingencyTable |
transpose()
transposes the table between X and Y dimensions
|
double[] |
unfold(boolean includeDiagonal,
boolean upperTriangleOnly)
unfold the table into an array of doubles
|
public final int NUM_MAXITERATOR
public int PRECISIONMULT
public int MatrixRows
public int MatrixCols
public double itsTotalSum
public boolean diagonal
public int iterated
public ContingencyTable(int MatrixCols, int MatrixRows, boolean diagonal, java.lang.String theName)
MatrixCols
- number of columns in the tableMatrixRows
- number of rows in the tablediagonal
- does the table have a diagonal?theName
- the name of the tablepublic ContingencyTable(int MatrixCols, int MatrixRows, boolean diagonal)
MatrixCols
- number of columns in the tableMatrixRows
- number of rows in the tablediagonal
- does the table have a diagonal?public ContingencyTable(int MatrixCols, int MatrixRows, java.lang.String theName)
MatrixCols
- number of columns in the tableMatrixRows
- number of rows in the tabletheName
- the name of the tablepublic ContingencyTable(int MatrixCols, int MatrixRows)
MatrixCols
- number of columns in the tableMatrixRows
- number of rows in the tablepublic ContingencyTable(double[] col1)
col1
- the array to install into column 1public ContingencyTable(double[][] theArray)
theArray
- the 2D array to install into the Tablepublic ContingencyTable(double[][] theArray, boolean diagonal)
theArray
- the array to install into the Tablediagonal
- does the table have a diagonal?public ContingencyTable(Matrix aMatrix, boolean diagonal)
aMatrix
- a JAMA matrixdiagonal
- does the table have a diagonal?public java.lang.String getName()
public void setName(java.lang.String theName)
theName
- the name of the tablepublic void setCellValue(int xLoc, int yLoc, double inValue)
xLoc
- x Capture in gridyLoc
- y Capture in gridinValue
- double value to setpublic void incrementCellValue(int xLoc, int yLoc)
xLoc
- x Capture in gridyLoc
- y Capture in gridpublic double getCellValue(int xLoc, int yLoc)
xLoc
- x Capture in gridyLoc
- y Capture in gridpublic SpatialVector getCell(int xLoc, int yLoc)
xLoc
- x Capture in gridyLoc
- y Capture in gridpublic void setTablePs(double[][] theTPs) throws java.lang.Exception
theTPs
- the array of probabilitiesjava.lang.Exception
- ...public void setColumnPs(double[] thePs) throws java.lang.Exception
thePs
- the array of probabilitiesjava.lang.Exception
- ...public void clearColumnPs()
public void clearTablePs()
public void clearPs()
public double[][] getTablePs()
public double[] getColumnPs()
public void setMatrixDimensions(int MatrixCols, int MatrixRows, boolean diagonal) throws java.lang.Exception
MatrixCols
- number of columns in the tableMatrixRows
- number of rows in the tablediagonal
- does the table have a diagonal?java.lang.Exception
- ...public int getMatrixSize()
public void setMatrixSize(int MatrixSize)
MatrixSize
- number of rows and columns in the tablepublic int getNRows()
public int getNCols()
public void setDiagonal(boolean diagonal)
diagonal
- does the table contain a diagonal?public void setDefaultRowColLabels()
public void setRowColLabels(java.util.TreeMap<?,?> Labels)
Labels
- the distinct IDs for columns and rowspublic void setRowColLabels(java.lang.String[] Labels)
Labels
- the distinct IDs for columns and rowspublic void setRowLabels(java.util.TreeMap<?,?> Labels)
Labels
- the distinct IDs for rowspublic void setRowLabels(java.lang.String[] Labels)
Labels
- the distinct IDs for rowspublic void setColLabels(java.util.TreeMap<?,?> Labels)
Labels
- the distinct IDs for columnspublic void setColLabels(java.lang.String[] Labels)
Labels
- the distinct IDs for rowspublic java.lang.String[] getRowLabels()
public java.lang.String[] getColLabels()
public void setColLabel(int column, java.lang.String aString)
column
- the column of the tableaString
- the string to setpublic java.lang.String getColLabel(int column)
column
- the column of the tablepublic void setRowLabel(int row, java.lang.String aString)
row
- the row of the tableaString
- the string to setpublic java.lang.String getRowLabel(int row)
row
- the row of the tablepublic void set2DArray(double[][] inMatrix) throws java.lang.Exception
inMatrix
- 2D array of doubles to fill the tablejava.lang.Exception
- if cell cannot be setpublic double[][] as2DdoubleArray()
public java.lang.String[][] as2DStringArray()
public Matrix asJAMAMatrix()
public void clearSums()
public void clearTable()
public void fillSums()
public double[] getRowSums()
public double getRowSum(int row)
row
- the rowpublic double[] getColSums()
public double getColSum(int col)
col
- the columnpublic double getTotalSum()
public ContingencyTable transpose() throws java.lang.Exception
java.lang.Exception
- if cannot construct table as requestedpublic java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if object cannot be clonedpublic double[][] getTotalsMatrix()
public double[][] getNoZeroCellMatrix()
public ContingencyTable getDifferenceTable(ContingencyTable bTable)
bTable
- the comparison tablepublic SpatialVector getMinValueCell()
public SpatialVector getMaxValueCell()
public double[][] getDominanceMatrix()
public DataTable getExpMatrixDia() throws java.lang.Exception
java.lang.Exception
- if ...public DataTable getExpMatrixFromProbabilities() throws java.lang.Exception
java.lang.Exception
- if ...public void listExpectedTable()
public ContingencyTable getExpectedMatrix()
public ContingencyTable getExpectedMatrix(boolean aDiagonal)
aDiagonal
- include diagonal?public ContingencyTable getExpMatrixNoDia() throws java.lang.Exception
java.lang.Exception
- if ...public ContingencyTable getPropMatrixDia() throws java.lang.Exception
java.lang.Exception
- if ...public ContingencyTable getPropMatrixNoDia() throws java.lang.Exception
java.lang.Exception
- if ...public void listFTukeyDeviates()
public DataTable getFTukeyDeviates() throws java.lang.Exception
java.lang.Exception
- if ...public int getdf()
public int getZeroCells()
public int getNCells()
public int getNDiagonals() throws java.lang.Exception
java.lang.Exception
- if ...public int getNCellsAboveValue(double compVal)
compVal
- the comparison valuepublic int getNCellsAboveEqualValue(double compVal)
compVal
- the comparison valuepublic int getNCellsBelowValue(double compVal)
compVal
- the comparison valuepublic int getNCellsBelowEqualValue(double compVal)
compVal
- the comparison valuepublic double DoWilliamsCorr()
public ContTableResults calcContingencyResults(ContingencyTable expectMatrix) throws java.lang.Exception
expectMatrix
- a ContingencyTable with
the matrix of expected valuesjava.lang.Exception
- if ...public ContTableResults getContingencyTableResults() throws java.lang.Exception
java.lang.Exception
- if ...public ContTableResults getContingencyTableResults(ContingencyTable expectMatrix) throws java.lang.Exception
expectMatrix
- a ContingencyTable with
the matrix of exp0ected valuesjava.lang.Exception
- if ...public void listContingencyTableResults()
public GoodnessOfFitResults calcGoodnessOfFitResults() throws java.lang.Exception
java.lang.Exception
- if ...public GoodnessOfFitResults getGoodnessOfFitResults() throws java.lang.Exception
java.lang.Exception
- if ...public void listGoodnessOfFitResults()
public ContingencyTable invertTable()
public double getTauKr()
public double TauKr(ContingencyTable BTable)
BTable
- second ContingencyTable for the TauKr valuepublic double getMantelZ(ContingencyTable BTable) throws java.lang.Exception
BTable
- second ContingencyTable for the correlationjava.lang.Exception
- if ...public double[] unfold(boolean includeDiagonal, boolean upperTriangleOnly) throws java.lang.Exception
includeDiagonal
- use diagonalupperTriangleOnly
- use upper triangle if symmetricaljava.lang.Exception
- if ...public DataTable fold(double[] cells, int rows, int cols, boolean diag) throws java.lang.Exception
cells
- the numbers to fill into the cells of the tablerows
- the number of rows for the tablecols
- the number of columns for the tablediag
- does the table have a diagonal?java.lang.Exception
- if ...public int howManyPossiblePermutations() throws java.lang.Exception
java.lang.Exception
- if ...public ContingencyTable getPermutedTable(int[] permOrder) throws java.lang.Exception
permOrder
- indicates a particular permutationjava.lang.Exception
- if ...public int fillPerms() throws java.lang.Exception
java.lang.Exception
- if ...public double getTauKrP(double actualKrNumber)
actualKrNumber
- empirically derived TauKrpublic double getMantelP(ContingencyTable BTable, double actualMantelNumber)
BTable
- second ContingencyTable for the TauKr valueactualMantelNumber
- empirically derived Mantels' zpublic void listTauKrResults()
public void listMantelZResults(ContingencyTable BTable)
BTable
- second ContingencyTable for the TauKr valuepublic java.lang.String rowToString(int row)
row
- the rowpublic java.lang.String colToString(int col)
col
- the columpublic java.lang.String toString(boolean doSums)
doSums
- include sums?public void listTable()
public void listTable(boolean doSums)
doSums
- specifies whether to include sumspublic void toFile(java.io.BufferedWriter bw) throws java.lang.Exception
bw
- the BufferedWriter to write intojava.lang.Exception
- if ...public boolean checkForColumnPs() throws java.lang.Exception
java.lang.Exception
- if ...public void checkMatrix() throws java.lang.Exception
java.lang.Exception
- if ...public boolean checkDiagonal() throws java.lang.Exception
java.lang.Exception
- if ...public boolean isSquare()
public boolean checkSquare() throws java.lang.Exception
java.lang.Exception
- if matrix is not squarepublic boolean checkMatchingMatrixDimensions(ContingencyTable BTable) throws java.lang.Exception
BTable
- a ContingencyTable to compare withjava.lang.Exception
- if matrices do not have the same dimensionspublic boolean isMatchingMatrix(ContingencyTable BTable) throws java.lang.Exception
BTable
- a ContingencyTable to compare withjava.lang.Exception
- if ...public boolean checkMinimumN(int n) throws java.lang.Exception
n
- the minimum sample sizejava.lang.Exception
- if ...public boolean checkForZeros() throws java.lang.Exception
java.lang.Exception
- if ...RH, 2017