commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r731398 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
Date Mon, 05 Jan 2009 01:01:16 GMT
Author: psteitz
Date: Sun Jan  4 17:01:16 2009
New Revision: 731398

URL: http://svn.apache.org/viewvc?rev=731398&view=rev
Log:
Changed covariance matrix computation to use QR decomp.

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java?rev=731398&r1=731397&r2=731398&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
Sun Jan  4 17:01:16 2009
@@ -139,13 +139,17 @@
      * </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());
     }
     
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java?rev=731398&r1=731397&r2=731398&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
Sun Jan  4 17:01:16 2009
@@ -156,10 +156,7 @@
                        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); 
     }
     
     /**



Mime
View raw message