You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Paul Brennan <pa...@mailblocks.com> on 2005/01/22 01:09:39 UTC

[Math] Contributions Adding Adjusted R-Squared to Simple regression

Hi,

Just wanted to add Adjusted R-Squared to the simple regression in the 
Simple Regression of stat.

Also is anyone working on Multiple regressions for the Math(s) library?

Yours

Paul Brennan


--- 
commons-math/src/java/org/apache/commons/math/stat/regression/SimpleRegressi
on.java 2005-01-21 04:07:35.000000000 -0800
+++ 
jakarta/commons-math-1.0/src/java/org/apache/commons/math/stat/regression/Si
mpleRegression.java     2005-01-21 15:47:28.000000000 -0800
@@ -344,6 +344,25 @@
         return getRSquare(getSlope());
     }

+    /**
+     * Returns the <a href="http://www.xycoon.com/r2adj1.htm">
+     * coefficient of determination Adjusted</a>,
+     * usually denoted Adjusted r-square.
+     * <p>
+     * <strong>Preconditions</strong>: <ul>
+     * <li>At least two observations (with at least two different x 
values)
+     * must have been added before invoking this method. If this 
method is
+     * invoked before a model can be estimated, 
<code>Double,NaN</code> is
+     * returned.
+     * </li></ul>
+     *
+     * @return Adjusted r-square
+     */
+    public double getAdjRSquare() {
+        // k is always two as we are estimating the slope and the 
intercept
+        return (1.0-(1.0-getRSquare())*((n-1)/(n-2)));
+    }
+
     /**
      * Returns the <a href="http://www.xycoon.com/standarderrorb0.htm">
      * standard error of the intercept estimate</a>,


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org