Inheritance: Accord.Statistics.Testing.ZTest
示例#1
0
        public void KappaTestConstructorTest()
        {
            // Example from http://vassarstats.net/kappa.html

            // Checked against http://graphpad.com/quickcalcs/Kappa2.cfm     (OK)

            int[,] matrix =
            {
                { 44,  5,  1 },
                {  7, 20,  3 },
                {  9,  5,  6 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(a.RowTotals[0], 50);
            Assert.AreEqual(a.RowTotals[1], 30);
            Assert.AreEqual(a.RowTotals[2], 20);

            Assert.AreEqual(a.ColumnTotals[0], 60);
            Assert.AreEqual(a.ColumnTotals[1], 30);
            Assert.AreEqual(a.ColumnTotals[2], 10);


            Assert.AreEqual(0.4915, a.Kappa, 1e-4);
            Assert.IsFalse(double.IsNaN(a.Kappa));

            double var = a.Variance;
            double var0 = a.VarianceUnderNull;
            double varD = Accord.Statistics.Testing.KappaTest.DeltaMethodKappaVariance(a);

            double se = System.Math.Sqrt(var);
            double se0 = System.Math.Sqrt(var0);
            double seD = System.Math.Sqrt(varD);

            Assert.AreEqual(0.072, a.StandardError, 0.0005);

            // Create a test of the null hypothesis (actual k = 0)
            KappaTest target = new KappaTest(a, hypothesizedKappa: 0);

            // Std. Error is computed differently under the null hypothesis:
            Assert.AreEqual(0.073509316753225237, target.StandardError, 1e-5);
            Assert.IsFalse(double.IsNaN(target.StandardError));
        }
示例#2
0
        public void KappaTestConstructorTest2()
        {
            // Example from: M. Reichenheim (2004). Confidence intervals for the
            // kappa statistic. The Stata Journal (2004) 4, Number 4, pp. 421–428.
            // http://www.stata-journal.com/sjpdf.html?articlenum=st0076

            int[,] matrix = // (pg 599)
            {
                { 48,  12 },
                { 16, 160 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            // Reichenheim's paper shows:
            // Agreement | Expected Agreement | Kappa  | Std. Error |   Z
            //   88.14%  |       61.25%       | 0.6938 |   0.0650   | 10.67

            Assert.AreEqual(88.14, a.OverallAgreement * 100, 1e-2);
            Assert.AreEqual(61.25, a.ChanceAgreement * 100, 1e-2);
            Assert.AreEqual(0.6938, a.Kappa, 1e-4);
            Assert.AreEqual(0.0650, a.StandardErrorUnderNull, 1e-4);

            KappaTest target = new KappaTest(a);

            Assert.AreEqual(OneSampleHypothesis.ValueIsGreaterThanHypothesis, target.Hypothesis);

            Assert.AreEqual(10.67, target.Statistic, 1e-3);
            Assert.AreEqual(7.0849733798130419E-27, target.PValue);
        }
示例#3
0
        public void KappaTestConstructorTest5()
        {
            // Example from Statistical Methods for Rates and Proportions
            // for kappa variance under the null hypothesis

            // Checked against Statistical Methods for Rates and Proportions (OK)


            int[,] matrix = // (pg 599)
            {
                { 75,  1, 4  },
                {  5,  4, 1  },
                {  0,  0, 10 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(100, a.Samples);

            Assert.AreEqual(80, a.RowTotals[0]);
            Assert.AreEqual(10, a.RowTotals[1]);
            Assert.AreEqual(10, a.RowTotals[2]);

            Assert.AreEqual(80, a.ColumnTotals[0]);
            Assert.AreEqual(5, a.ColumnTotals[1]);
            Assert.AreEqual(15, a.ColumnTotals[2]);

            double[,] proportions = // (pg 599)
            {
                { 0.75, 0.01, 0.04 },
                { 0.05, 0.04, 0.01 },
                { 0.00, 0.00, 0.10 },
            };

            Assert.IsTrue(proportions.IsEqual(a.ProportionMatrix));

            // Test under null hypothesis
            KappaTest target = new KappaTest(a, hypothesizedKappa: 0,
                alternate: OneSampleHypothesis.ValueIsGreaterThanHypothesis);

            Assert.AreEqual(0.68, target.EstimatedValue, 0.01); // pg 605
            Assert.AreEqual(a.Kappa, target.EstimatedValue);
            Assert.IsFalse(double.IsNaN(target.EstimatedValue));

            Assert.AreEqual(0.076, target.StandardError, 0.001);
            Assert.IsFalse(double.IsNaN(target.StandardError));

            Assert.AreEqual(8.95, target.Statistic, 0.08);

            Assert.IsTrue(target.Significant);
        }
示例#4
0
        public void KappaTestConstructorTest4()
        {
            // Example from Statistical Methods for Rates and Proportions

            // Checked against http://graphpad.com/quickcalcs/Kappa2.cfm     (OK)
            // Checked against Statistical Methods for Rates and Proportions (OK)
            // Checked against http://vassarstats.net/kappa.html           (FAIL)

            int[,] matrix = // (pg 599)
            {
                { 75,  1, 4  },
                {  5,  4, 1  },
                {  0,  0, 10 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(100, a.Samples);

            Assert.AreEqual(80, a.RowTotals[0]);
            Assert.AreEqual(10, a.RowTotals[1]);
            Assert.AreEqual(10, a.RowTotals[2]);

            Assert.AreEqual(80, a.ColumnTotals[0]);
            Assert.AreEqual(5, a.ColumnTotals[1]);
            Assert.AreEqual(15, a.ColumnTotals[2]);

            double[,] proportions = // (pg 599)
            {
                { 0.75, 0.01, 0.04 },
                { 0.05, 0.04, 0.01 },
                { 0.00, 0.00, 0.10 },
            };

            Assert.IsTrue(proportions.IsEqual(a.ProportionMatrix));


            double expectedVar = a.Variance;

            // Test against non-null hypothesis
            KappaTest target = new KappaTest(a, hypothesizedKappa: 0.8);

            // Fleiss   reports 0.68  (page 606)
            // Graphpad reports 0.676
            Assert.AreEqual(0.68, target.EstimatedValue, 0.01);
            Assert.AreEqual(a.Kappa, target.EstimatedValue);
            Assert.IsFalse(double.IsNaN(target.EstimatedValue));

            // Fleiss   reports 0.087 (page 607)
            // Graphpad reports 0.088
            Assert.AreEqual(0.087, target.StandardError, 0.001);
            Assert.IsFalse(double.IsNaN(target.StandardError));

            Assert.AreEqual(-1.38, target.Statistic, 0.029);
            Assert.AreEqual(0.1589, target.PValue, 0.0001);

            Assert.IsFalse(target.Significant);
        }
示例#5
0
        public void KappaTestConstructorTest()
        {
            int[,] matrix =
            {
                { 44,  5,  1},
                {  7, 20,  3 },
                {  9,  5,  6 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(0.4915, a.Kappa, 1e-4);
            Assert.IsFalse(double.IsNaN(a.Kappa));

            KappaTest target = new KappaTest(a);

            Assert.AreEqual(0.0777, target.StandardError, 1e-2);
            Assert.IsFalse(double.IsNaN(target.StandardError));

            Assert.AreEqual(0.3393, target.Confidence.Min, 1e-2);
            Assert.AreEqual(0.6437, target.Confidence.Max, 1e-2);
        }
示例#6
0
        public void KappaTestConstructorTest3()
        {
            int[,] matrix =
            {
                { 377,  79,  0,  0 },
                {   2,  72,  0,  0 },
                {  33,   5, 60,  0 },
                {   3,  20,  0,  8 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(0.7845, a.OverralAgreement, 1e-4);
            Assert.IsFalse(double.IsNaN(a.OverralAgreement));

            Assert.AreEqual(0.47986, a.ChanceAgreement, 1e-5);
            Assert.IsFalse(double.IsNaN(a.ChanceAgreement));

            Assert.AreEqual(0.586, a.Kappa, 1e-3);
            Assert.IsFalse(double.IsNaN(a.Kappa));

            KappaTest target = new KappaTest(a);


            Assert.AreEqual(0.586, target.Kappa, 1e-3);
            Assert.AreEqual(a.Kappa, target.Kappa);
            Assert.IsFalse(double.IsNaN(target.Kappa));

            Assert.AreEqual(0.00087457, target.Variance, 1e-5);
            Assert.IsFalse(double.IsNaN(target.Variance));

            Assert.AreEqual(19.806, target.Statistic, 0.1);
            Assert.IsFalse(double.IsNaN(target.Statistic));


            Assert.AreEqual(0.644, target.Confidence.Max, 1e-3);
            Assert.AreEqual(0.528, target.Confidence.Min, 1e-3);

            Assert.AreEqual(0.0, target.PValue, 1e-6);
            Assert.IsFalse(double.IsNaN(target.PValue));

            Assert.IsTrue(target.Significant);
        }
示例#7
0
        public void KappaTestConstructorTest2()
        {
            int[,] matrix =
            {
                { 317,  23,  0,  0 },
                {  61, 120,  0,  0 },
                {   2,   4, 60,  0 },
                {  35,  29,  0,  8 },
            };

            GeneralConfusionMatrix a = new GeneralConfusionMatrix(matrix);

            Assert.AreEqual(0.7663, a.OverralAgreement, 1e-4);
            Assert.IsFalse(double.IsNaN(a.OverralAgreement));

            Assert.AreEqual(0.4087, a.ChanceAgreement, 1e-5);
            Assert.IsFalse(double.IsNaN(a.ChanceAgreement));

            KappaTest target = new KappaTest(a);

            Assert.AreEqual(0.605, target.Kappa, 1e-3);
            Assert.AreEqual(a.Kappa, target.Kappa);
            Assert.IsFalse(double.IsNaN(target.Kappa));

            Assert.AreEqual(0.00073735, target.Variance, 1e-5);
            Assert.IsFalse(double.IsNaN(target.Variance));



            Assert.AreEqual(22.272, target.Statistic, 0.15);
            Assert.IsFalse(double.IsNaN(target.Statistic));


            Assert.AreEqual(0.658, target.Confidence.Max, 1e-3);
            Assert.AreEqual(0.552, target.Confidence.Min, 1e-3);

            Assert.AreEqual(0.0, target.PValue, 1e-6);
            Assert.IsFalse(double.IsNaN(target.PValue));

            Assert.IsTrue(target.Significant);
        }