Accord.Tests.Statistics.NewtonRaphsonCoxLearningTest.BaselineHazardTest C# (CSharp) Méthode

BaselineHazardTest() private méthode

private BaselineHazardTest ( ) : void
Résultat void
        public void BaselineHazardTest()
        {
            double[,] data = 
            {
               // t   c  in
                { 8,  0, -1.2372626521865966    },
                { 4,  1,  0.22623087329625477   },
                { 12, 0, -0.8288458543774289    },
                { 6,  0,  0.49850873850236665   },
                { 10, 0, -0.38639432341749696   },
                { 8,  1,  1.0430644689145904    },
                { 5,  0, -1.6797141831465285    },
                { 5,  0,  1.0770992020653544    },
                { 3,  1,  1.0770992020653544    },
                { 14, 1, -0.38639432341749696   },
                { 8,  0, -0.8969153206789568    },
                { 11, 0,  1.6897243987791061    },
                { 7,  0, -1.2712973853373605    },
                { 7,  0, -0.38639432341749696   },
                { 7,  1, -0.45446378971902495   },
                { 12, 0,  0.4644740053516027    },
                { 8,  0,  1.4514812667237584    },
            };

            double[] time = data.GetColumn(0);
            SurvivalOutcome[] censor = data.GetColumn(1).To<SurvivalOutcome[]>();
            double[][] inputs = data.GetColumn(2).ToJagged();

            var regression = new ProportionalHazards(1);

            var target = new ProportionalHazardsNewtonRaphson(regression);

            target.Normalize = false;
            target.Lambda = 0;
            regression.Coefficients[0] = 0.47983261821350764;

            double error = target.Run(inputs, time, censor);

            /* Tested against http://statpages.org/prophaz2.html
                13, 8,  0
                56, 4,  1
                25, 12, 0
                64, 6,  0
                38, 10, 0
                80, 8,  1
                0 , 5,  0
                81, 5,  0
                81, 3,  1
                38, 14, 1
                23, 8,  0
                99, 11, 0
                12, 7,  0
                38, 7,  0
                36, 7,  1
                63, 12, 0
                92, 8,  0
             */

            double[] baseline =
            {
                regression.Survival(3),  // 0.9465           
                regression.Survival(4),  // 0.8919
                regression.Survival(7),  // 0.8231
                regression.Survival(8),  // 0.7436
                regression.Survival(12), // 0.7436
                regression.Survival(14), // 0.0000
            };

            Assert.AreEqual(0.9465, baseline[0], 1e-4);
            Assert.AreEqual(0.8919, baseline[1], 1e-4);
            Assert.AreEqual(0.8231, baseline[2], 1e-4);
            Assert.AreEqual(0.7436, baseline[3], 1e-4);
            Assert.AreEqual(0.7436, baseline[4], 1e-4);
            Assert.AreEqual(0.0000, baseline[5], 1e-4);

            // The value of the baseline must be exact the same if it was computed
            // after the Newton-Raphson or in a standalone EmpiricalHazard computation
            double[] outputs = inputs.Apply(x => regression.Compute(x));
            var empirical = EmpiricalHazardDistribution.Estimate(time, censor, outputs);

            baseline = new[]
            {
                empirical.ComplementaryDistributionFunction(3),  // 0.9465           
                empirical.ComplementaryDistributionFunction(4),  // 0.8919
                empirical.ComplementaryDistributionFunction(7),  // 0.8231
                empirical.ComplementaryDistributionFunction(8),  // 0.7436
                empirical.ComplementaryDistributionFunction(12), // 0.7436
                empirical.ComplementaryDistributionFunction(14), // 0.0000
            };

            Assert.AreEqual(0.9465, baseline[0], 1e-4);
            Assert.AreEqual(0.8919, baseline[1], 1e-4);
            Assert.AreEqual(0.8231, baseline[2], 1e-4);
            Assert.AreEqual(0.7436, baseline[3], 1e-4);
            Assert.AreEqual(0.7436, baseline[4], 1e-4);
            Assert.AreEqual(0.0000, baseline[5], 1e-4);
        }