public void RunTest()
{
// 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 },
};
var regression = new ProportionalHazards(1);
double[][] inputs = data.GetColumn(0).ToJagged();
double[] time = data.GetColumn(1);
SurvivalOutcome[] output = data.GetColumn(2).To<SurvivalOutcome[]>();
var target = new ProportionalHazardsNewtonRaphson(regression);
double error = target.Run(inputs, time, output);
double log = -2 * regression.GetPartialLogLikelihood(inputs, time, output);
// Tested against http://www.sph.emory.edu/~cdckms/CoxPH/prophaz2.html
Assert.AreEqual(0.3770, regression.Coefficients[0], 1e-4);
Assert.IsFalse(Double.IsNaN(regression.Coefficients[0]));
Assert.AreEqual(0.2542, regression.StandardErrors[0], 1e-4);
Assert.IsFalse(Double.IsNaN(regression.StandardErrors[0]));
double[] actual = new double[inputs.Length];
for (int i = 0; i < actual.Length; i++)
actual[i] = regression.Compute(inputs[i]);
double[] expected =
{
// Computed using R's predict(fit,type="risk")
0.640442743, 1206.226657448, 0.097217211, 0.002240107,
59.081223025, 0.640442743, 0.097217211, 8.968345353,
0.000722814, 8.968345353, 27.794227993
};
for (int i = 0; i < actual.Length; i++)
{
Assert.AreEqual(expected[i], actual[i], 1e-3);
Assert.IsFalse(Double.IsNaN(actual[i]));
}
}