All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.davidbracewell.apollo.stat.measure.Agreement Maven / Gradle / Ivy

The newest version!
package com.davidbracewell.apollo.stat.measure;

import com.davidbracewell.guava.common.base.Preconditions;
import lombok.NonNull;

/**
 * @author David B. Bracewell
 */
public enum Agreement implements ContingencyTableCalculator {
   Cohen_Kappa {
      @Override
      public double calculate(@NonNull ContingencyTable table) {
         Preconditions.checkArgument(table.columnCount() == 2
                                        && table.rowCount() == 2,
                                     "Only 2x2 tables supported");
         double sum = table.getSum();
         double sumSq = sum * sum;
         double Po = (table.get(0, 0) + table.get(1, 1)) / sum;
         double Pe = ((table.columnSum(0) * table.rowSum(0)) / sumSq)
                        + ((table.columnSum(1) * table.rowSum(1)) / sumSq);
         return (Po - Pe) / (1.0 - Pe);
      }
   };


}// END OF Agreement




© 2015 - 2025 Weber Informatics LLC | Privacy Policy