public void KappaTestConstructorTest1()
{
// Example from Ientilucci, Emmett (2006). "On Using and Computing the Kappa Statistic".
// Available on: http://www.cis.rit.edu/~ejipci/Reports/On_Using_and_Computing_the_Kappa_Statistic.pdf
// This paper uses the delta method approximation
// for computing the kappa variance.
int[,] matrix1 =
{
{ 317, 23, 0, 0 },
{ 61, 120, 0, 0 },
{ 2, 4, 60, 0 },
{ 35, 29, 0, 8 },
};
int[,] matrix2 =
{
{ 377, 79, 0, 0 },
{ 2, 72, 0, 0 },
{ 33, 5, 60, 0 },
{ 3, 20, 0, 8 },
};
GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix1);
GeneralConfusionMatrix b = new GeneralConfusionMatrix(matrix2);
Assert.AreEqual(0.7663, a.OverallAgreement, 1e-4);
Assert.AreEqual(0.7845, b.OverallAgreement, 1e-4);
Assert.AreEqual(0.4087, a.ChanceAgreement, 1e-4);
Assert.AreEqual(0.47986, b.ChanceAgreement, 1e-4);
double kA = a.Kappa;
double kB = b.Kappa;
double varA = KappaTest.DeltaMethodKappaVariance(a);
double varB = KappaTest.DeltaMethodKappaVariance(b);
TwoMatrixKappaTest target = new TwoMatrixKappaTest(kA, varA, kB, varB);
Assert.AreEqual(TwoSampleHypothesis.ValuesAreDifferent, target.Hypothesis);
Assert.AreEqual(DistributionTail.TwoTail, target.Tail);
// Compare Kappas
Assert.AreEqual(0.605, target.EstimatedValue1, 1e-3);
Assert.IsFalse(double.IsNaN(a.Kappa));
Assert.AreEqual(0.586, target.EstimatedValue2, 1e-3);
Assert.IsFalse(double.IsNaN(b.Kappa));
// Compare variances:
Assert.AreEqual(0.00073735, target.Variance1, 1e-7);
Assert.IsFalse(double.IsNaN(a.Variance));
Assert.AreEqual(0.00087457, target.Variance2, 1e-7);
Assert.IsFalse(double.IsNaN(b.Variance));
Assert.AreEqual(0.475, target.Statistic, 1e-3);
Assert.IsFalse(double.IsNaN(target.Statistic));
Assert.IsFalse(target.Significant);
}