public void PredictTest1()
{
// Data from: http://www.sph.emory.edu/~cdckms/CoxPH/prophaz2.html
double[,] data =
{
{ 50, 1, 0 },
{ 70, 2, 1 },
{ 45, 3, 0 },
{ 35, 5, 0 },
{ 62, 7, 1 },
{ 50, 11, 0 },
{ 45, 4, 0 },
{ 57, 6, 0 },
{ 32, 8, 0 },
{ 57, 9, 1 },
{ 60, 10, 1 },
};
double[] distHazards =
{
0, 0.0351683340828711, 0.0267358118285064, 0,
0.0103643094219679, 0, 0, 0, 0, 0.000762266794052363, 0
};
double[] distTimes =
{
11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
};
var regression = new ProportionalHazards(1, new EmpiricalHazardDistribution(distTimes, distHazards));
regression.Coefficients[0] = 0.37704239281494084;
regression.StandardErrors[0] = 0.25415755113043753;
regression.Offsets[0] = 51.181818;
double[][] inputs = data.GetColumn(0).ToJagged();
double[] time = data.GetColumn(1);
double[] expected =
{
0.000000000000, 0.919466527073, 0.000074105451, 0.000001707560,
0.657371730925, 0.046771996036, 0.000074105451, 0.006836271860,
0.000008042445, 0.339562971888, 2.029832541310
};
double[] actual = new double[inputs.Length];
for (int i = 0; i < inputs.Length; i++)
actual[i] = regression.Compute(inputs[i], time[i]);
for (int i = 0; i < actual.Length; i++)
Assert.AreEqual(expected[i], actual[i], 1e-6);
regression.Intercept = -regression.Coefficients.Dot(regression.Offsets);
actual = regression.Probability(inputs.Zip(time, Tuple.Create).ToArray());
Assert.IsTrue(actual.IsEqual(expected, 1e-6));
}