int p = getX().getColumns();
// If there are no free degrees, there should be no error in the
// regression.
if (n - p == 0) {
mStandardErrorsPerCoefficient = new Matrix(p, 1);
mStandardErrorsPerCoefficient.flood(0.0);
// Free the possibly huge standardErrorMatrix.
setStandardErrorMatrix(null);
return mStandardErrorsPerCoefficient.copy();
}
for (int i = 0; i < n; i++) {
double temp = getY().getElement(i, 0);
standardErrorSESquare += temp * temp;
}
for (int j = 0; j < p; j++) {
double temp = 0.0;
for (int i = 0; i < n; i++) {
temp += getX().getElement(i, j) * getY().getElement(i, 0);
}
temp *= getB().getElement(j, 0);
standardErrorSESquare -= temp;
}
standardErrorSESquare /= n - p;
if (getStandardErrorMatrix() == null) {
setStandardErrorMatrix(getX().transpose().mult(getX()).solve());
}
// Calculate standard errors.
mStandardErrorsPerCoefficient = new Matrix(p, 1);
for (int i = 0; i < p; i++) {
mStandardErrorsPerCoefficient.setElement(
i,
0,
Math.sqrt(standardErrorSESquare