public void ComputeTest2()
{
double[][] inputs;
int[] outputs;
MultinomialLogisticRegressionTest.CreateInputOutputsExample2(out inputs, out outputs);
var analysis = new MultinomialLogisticRegressionAnalysis(inputs, outputs);
int inputCount = 5;
int outputCount = 3;
int coeffCount = inputCount + 1;
var mlr = analysis.regression;
Assert.AreEqual(inputCount, mlr.Inputs);
Assert.AreEqual(outputCount, mlr.Categories);
Assert.AreEqual(inputCount, analysis.Inputs.Length);
Assert.AreEqual(outputCount, analysis.OutputNames.Length);
analysis.Iterations = 100;
analysis.Tolerance = 1e-6;
analysis.Compute();
Assert.AreEqual(outputCount - 1, analysis.CoefficientValues.Length);
Assert.AreEqual(outputCount - 1, analysis.StandardErrors.Length);
Assert.AreEqual(outputCount - 1, analysis.WaldTests.Length);
Assert.AreEqual(outputCount - 1, analysis.Confidences.Length);
for (int i = 0; i < analysis.CoefficientValues.Length; i++)
{
Assert.AreEqual(coeffCount, analysis.CoefficientValues[i].Length);
Assert.AreEqual(coeffCount, analysis.StandardErrors[i].Length);
Assert.AreEqual(coeffCount, analysis.WaldTests[i].Length);
Assert.AreEqual(coeffCount, analysis.Confidences[i].Length);
for (int j = 0; j < analysis.CoefficientValues[i].Length; j++)
{
Assert.IsFalse(double.IsNaN(analysis.CoefficientValues[i][j]));
Assert.IsFalse(double.IsNaN(analysis.StandardErrors[i][j]));
}
}
var coefficients = analysis.CoefficientValues;
// brand 2
Assert.AreEqual(-11.774655, coefficients[0][0], 1e-3); // intercept
Assert.AreEqual(0.523814, coefficients[0][1], 1e-3); // female
Assert.AreEqual(0.368206, coefficients[0][2], 1e-3); // age
// brand 3
Assert.AreEqual(-22.721396, coefficients[1][0], 1e-3); // intercept
Assert.AreEqual(0.465941, coefficients[1][1], 1e-3); // female
Assert.AreEqual(0.685908, coefficients[1][2], 1e-3); // age
var standard = analysis.StandardErrors;
Assert.AreEqual(-702.97, analysis.LogLikelihood, 1e-2);
Assert.AreEqual(185.85, analysis.ChiSquare.Statistic, 1e-2);
Assert.AreEqual(1405.9414080469473, analysis.Deviance, 1e-5);
}