Changed covariance matrix computation to use QR decomp.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@731398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2009-01-05 01:01:16 +00:00
parent e7911e6efa
commit e7ffb6ebc9
2 changed files with 8 additions and 7 deletions

View File

@ -139,13 +139,17 @@ public class OLSMultipleLinearRegression extends AbstractMultipleLinearRegressio
* </p>
* <p>Var(b) = (X<sup>T</sup>X)<sup>-1</sup>
* </p>
* <p>Uses QR decomposition to reduce (X<sup>T</sup>X)<sup>-1</sup>
* to (R<sup>T</sup>R)<sup>-1</sup>, with only the top p rows of
* R included, where p = the length of the beta vector.</p>
*
* @return The beta variance
*/
protected RealMatrix calculateBetaVariance() {
//TODO: find a way to use QR decomp to avoid inverting XX' here
RealMatrix XTX = X.transpose().multiply(X);
return new LUDecompositionImpl(XTX).getSolver().getInverse();
int p = X.getColumnDimension();
RealMatrix Raug = qr.getR().getSubMatrix(0, p - 1 , 0, p - 1);
RealMatrix Rinv = new LUDecompositionImpl(Raug).getSolver().getInverse();
return Rinv.multiply(Rinv.transpose());
}

View File

@ -156,10 +156,7 @@ public class OLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs
0.488399681651699,
0.214274163161675,
0.226073200069370,
455.478499142212}, errors, 1E-2); // Ugh..
// Bad accuracy is in intercept std error estimate. Could be due to
// Current impl inverting XX' to get standard errors.
455.478499142212}, errors, 1E-6);
}
/**