Currently I have a dependency to commons-math 2.1 but I want to upgrade it to commons-math 3.6. Unfortunately there are some testcases that are not working any longer. I know what is causing my problem, but I don't know how to change the testcase accordingly to test the correct behavior as before.
I have following test code:
@Test
public void testIdentityMatrix() {
double[][] x = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 1 } };
double[] y = { 1, 2, 3, 4 };
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
regression.setNoIntercept(true);
regression.newSampleData(y, x);
double[] b = regression.estimateRegressionParameters();
for (int i = 0; i < y.length; i++)
{
assertEquals(b[i], y[i], 0.001);
}
}
After the upgrade to commons-math 3.6 the OLSMultipleLinearRegression checks the given matrix x and vector y for valid contents. And this validation fails with the message:
not enough data (4 rows) for this many predictors (4 predictors)
What do I need to change to correct that test case?
This is a bug in Commons Math 3.x. When there is no intercept in the model, as long as the design matrix is not singular, the number of observations equal to the number of regressors should be OK. In your example, I think you mean for the third x row to be {0,0,1,0} (otherwise the design matrix is singular). With this change to your data and the code patch applied in the Hipparchus fix your test succeeds. This bug is being tracked as MATH-1392 in Commons Math.