private LeastSquaresRegressionResult regress(
DoubleMatrix xDataMatrix,
DoubleArray yDataVector,
int nData,
int degree) {
Decomposition<QRDecompositionResult> qrComm = new QRDecompositionCommons();
DecompositionResult decompResult = qrComm.apply(xDataMatrix);
_qrResult = (QRDecompositionResult) decompResult;
DoubleMatrix qMatrix = _qrResult.getQ();
DoubleMatrix rMatrix = _qrResult.getR();
double[] betas = backSubstitution(qMatrix, rMatrix, yDataVector, degree);
double[] residuals = residualsSolver(xDataMatrix, betas, yDataVector);
for (int i = 0; i < degree + 1; ++i) {
ArgChecker.isFalse(Double.isNaN(betas[i]), "Input is too large or small");
}
for (int i = 0; i < nData; ++i) {
ArgChecker.isFalse(Double.isNaN(residuals[i]), "Input is too large or small");
}
return new LeastSquaresRegressionResult(betas, residuals, 0.0, null, 0.0, 0.0, null, null, true);
}