Accord.Tests.Statistics.EmpiricalHazardDistributionTest.DistributionFunctionTest2 C# (CSharp) Method

DistributionFunctionTest2() private method

private DistributionFunctionTest2 ( ) : void
return void
        public void DistributionFunctionTest2()
        {

            double[] values = 
            {
               0.0000000000000000, 0.0351683340828711, 0.0267358118285064,
               0.0000000000000000, 0.0103643094219679, 0.0000000000000000,
               0.0000000000000000, 0.0000000000000000, 0.0000000000000000,
               0.000762266794052363, 0.000000000000000
            };

            double[] times =
            {
                11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
            };


            var target = new EmpiricalHazardDistribution(times, values);

            double[] expected = 
            {
                1.000000000000000,	
                0.999238023657475,	
                0.999238023657475,	
                0.999238023657475,	
                0.999238023657475,	
                0.999238023657475,	
                0.98893509519066469,	
                0.98893509519066469,
                0.96284543081744489,
                0.92957227114936058,	
                0.92957227114936058,	
            };


            double[] hazardFunction = new double[expected.Length];
            double[] survivalFunction = new double[expected.Length];

            for (int i = 0; i < 11; i++)
                hazardFunction[i] = target.CumulativeHazardFunction(i + 1);

            for (int i = 0; i < 11; i++)
                survivalFunction[i] = target.ComplementaryDistributionFunction(i + 1);


            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], survivalFunction[i], 1e-5);

                // Ho = -log(So)
                Assert.AreEqual(hazardFunction[i], -Math.Log(survivalFunction[i]), 1e-5);

                // So = exp(-Ho)
                Assert.AreEqual(survivalFunction[i], Math.Exp(-hazardFunction[i]), 1e-5);
            }

            Assert.AreEqual(1, target.ComplementaryDistributionFunction(0));
            Assert.AreEqual(0, target.ComplementaryDistributionFunction(Double.PositiveInfinity));
        }