net.sourceforge.nite.datainspection.calc
Class CoincidenceMatrix

java.lang.Object
  extended by net.sourceforge.nite.datainspection.calc.CoincidenceMatrix

public class CoincidenceMatrix
extends java.lang.Object

CoincidenceMatrix has methods for comparing Two Classifications. Both classifications must contain exactly the same items in the same order.
The coincidence matrix accounts for Values (labels)
coincidence_matrix[Val1][Val2] is the number of times that one classification labeled some item Val1 the other Val2
coincidence_matrix is symmetrical along the main-diagonal.
the total over all entry numbers is 2*N, where N is the number of items judged (2*N values are given).
This class contains a method for computing kappa (a type of distance measure between classifications)
This distance uses a distance metric on the type of Values(class labels) assigned to the items(units).
Usually the Boolean Metric is used: distance = 0 iff values are equal otherwise it is 1.
If you think that some labels are more equal than others you may use a weighted kappa, that uses your
own DistanceMetric
kappaKrippendorf - returns the same value as alphaNominal with the standard BooleanMetric.
alphaNominal(DistanceMetric) - according to Krippendorff - requires a DistanceMetric defined on the values of the classification
kappaCohen is computed using the confusion matrix (this kappa may differ from kappa Krippendorff)
The implementation is based on "Computing Krippendorff's Alpha-Reliability"

See Also:
Classification, DistanceMetric

Constructor Summary
CoincidenceMatrix(Classification f, Classification s)
           
CoincidenceMatrix(ConfusionMatrix conf_m)
           
CoincidenceMatrix(int size)
          creates an empty coincidence matrix of given size with default values the numbers (0,1,...,size-1)
 
Method Summary
 double alphaNominal(DistanceMetric dist)
          computes alpha for nominal values using the given distance metric
the distance metric should be appropriate for the Values that occur in the Classification for which
this CoincidenceMatrix is computed at contruction
 double entry(int row, int col)
           
 double entry(Value rowValue, Value colValue)
           
 java.util.List getValues()
           
 double kappaKrippendorff()
          returns the same value as alpha when using the standard Boolean Metric.
static void main(java.lang.String[] args)
           
 int nrOfItems()
           
 int numberOfValues()
           
 void printMatrix(java.io.PrintWriter pw)
           
 void printMatrix(java.lang.String filename)
           
 void printValues(java.io.PrintWriter pw)
          print all Values that occur in first or second on SO
 void setDistanceMetrics(DistanceMetric dist)
          set the distance metric used
 void setEntry(int row, int col, double cv)
           
 void setEntry(Value rowValue, Value colValue, double cv)
          set coinm[rowValue][colValue] to cv
 void setValues(java.util.List vals)
          set the list of class labels used the order should be the same as the order of Values in the row and columns of the matrix
 void showDistanceMatrix(java.lang.String outFile)
           
 void showMatrix()
           
 void showValues()
          print all Values that occur in first or second on SO
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoincidenceMatrix

public CoincidenceMatrix(Classification f,
                         Classification s)
Parameters:
f - the first Classification
s - the second Classification required: f and s are classifications of the same ordered list of items/units classified the constructor computes the coincidence matrix

CoincidenceMatrix

public CoincidenceMatrix(int size)
creates an empty coincidence matrix of given size with default values the numbers (0,1,...,size-1)


CoincidenceMatrix

public CoincidenceMatrix(ConfusionMatrix conf_m)
Parameters:
conf_m - the confusion matrix from which this coincidence matrix is computed (CoinMatrix = ConfMatrix + ConfMatrix^T)
Method Detail

setValues

public void setValues(java.util.List vals)
set the list of class labels used the order should be the same as the order of Values in the row and columns of the matrix


entry

public double entry(int row,
                    int col)
Returns:
coinm[row][col]

entry

public double entry(Value rowValue,
                    Value colValue)
Returns:
coinm[Value r][Value c]

setEntry

public void setEntry(Value rowValue,
                     Value colValue,
                     double cv)
set coinm[rowValue][colValue] to cv


setEntry

public void setEntry(int row,
                     int col,
                     double cv)

getValues

public java.util.List getValues()

showMatrix

public void showMatrix()

printMatrix

public void printMatrix(java.lang.String filename)

printMatrix

public void printMatrix(java.io.PrintWriter pw)

showValues

public void showValues()
print all Values that occur in first or second on SO


printValues

public void printValues(java.io.PrintWriter pw)
print all Values that occur in first or second on SO


numberOfValues

public int numberOfValues()
Returns:
number of class labels used

nrOfItems

public int nrOfItems()

alphaNominal

public double alphaNominal(DistanceMetric dist)
computes alpha for nominal values using the given distance metric
the distance metric should be appropriate for the Values that occur in the Classification for which
this CoincidenceMatrix is computed at contruction

Returns:
alpha = 1.0 - (D_observed / D_chance )

kappaKrippendorff

public double kappaKrippendorff()
returns the same value as alpha when using the standard Boolean Metric. return kappa = (pa-pe)/(1-pe) with pa = 1-Dobserved() and pe = 1-Dchance()

Returns:
kappa according to Krippendorff's alpha method using the standard Boolean Metric

setDistanceMetrics

public void setDistanceMetrics(DistanceMetric dist)
set the distance metric used


showDistanceMatrix

public void showDistanceMatrix(java.lang.String outFile)

main

public static void main(java.lang.String[] args)