public void prediction_interval()
{
CsvReader reader = CsvReader.FromText(Properties.Resources.logreg, true);
DataTable data = reader.ToTable();
double[][] inputs = data.ToArray("AGE");
double[] output = data.Columns["CHD"].ToArray();
var learner = new IterativeReweightedLeastSquares<LogisticRegression>();
var lr = learner.Learn(inputs, output);
Assert.AreEqual(0.111, lr.Weights[0], 5e-4);
Assert.AreEqual(-5.309, lr.Intercept, 5e-4);
Assert.AreEqual(1.1337, lr.StandardErrors[0], 5e-5);
Assert.AreEqual(0.0241, lr.StandardErrors[1], 5e-5);
double ll = lr.GetLogLikelihood(inputs, output);
Assert.AreEqual(-53.6765, ll, 1e-4);
double[] point = new double[] { 50 };
double y = lr.Score(point);
double[][] im = learner.GetInformationMatrix();
//double se = lr.GetStandardError(inputs, im);
var ci = lr.GetConfidenceInterval(point, inputs.Length, im);
Assert.AreEqual(0.435, ci.Min, 5e-3);
Assert.AreEqual(0.677, ci.Max, 5e-3);
var pi = lr.GetPredictionInterval(point, inputs.Length, im);
Assert.AreEqual(0.1405, pi.Min, 5e-3);
Assert.AreEqual(0.9075, pi.Max, 5e-3);
}
}