public void DistributionFunctionTest() { double[] values = { 1.0000000000000000, 0.8724284533876597, 0.9698946958777951, 1.0000000000000000, 0.9840887140861863, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 0.9979137773216293, 1.0000000000000000 }; double[] times = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; EmpiricalHazardDistribution target = EmpiricalHazardDistribution .FromSurvivalValues(times, values); // Data from: http://www.sph.emory.edu/~cdckms/CoxPH/prophaz2.html double[] expectedBaselineSurvivalFunction = { 1.0000, 0.9979, 0.9979, 0.9979, 0.9979, 0.9979, 0.9820, 0.9820, 0.9525, 0.8310, 0.8310, }; double[] hazardFunction = new double[expectedBaselineSurvivalFunction.Length]; double[] survivalFunction = new double[expectedBaselineSurvivalFunction.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 < expectedBaselineSurvivalFunction.Length; i++) { Assert.AreEqual(expectedBaselineSurvivalFunction[i], survivalFunction[i], 0.01); // Ho = -log(So) Assert.AreEqual(hazardFunction[i], -Math.Log(survivalFunction[i]), 0.01); // So = exp(-Ho) Assert.AreEqual(survivalFunction[i], Math.Exp(-hazardFunction[i]), 0.01); } }