You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/11/27 21:35:17 UTC
svn commit: r1206838 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
site/xdoc/userguide/stat.xml
test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
Author: psteitz
Date: Sun Nov 27 20:35:16 2011
New Revision: 1206838
URL: http://svn.apache.org/viewvc?rev=1206838&view=rev
Log:
Javadoc, test improvements, user guide update. JIRA: MATH-649.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
commons/proper/math/trunk/src/site/xdoc/userguide/stat.xml
commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=1206838&r1=1206837&r2=1206838&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java Sun Nov 27 20:35:16 2011
@@ -48,11 +48,16 @@ import org.apache.commons.math.util.Prec
* different x coordinates are required to estimate a bivariate regression
* model.
* </li>
- * <li> getters for the statistics always compute values based on the current
+ * <li> Getters for the statistics always compute values based on the current
* set of observations -- i.e., you can get statistics, then add more data
* and get updated statistics without using a new instance. There is no
* "compute" method that updates all statistics. Each of the getters performs
- * the necessary computations to return the requested statistic.</li>
+ * the necessary computations to return the requested statistic.
+ * </li>
+ * <li> The intercept term may be suppressed by passing {@code false} to
+ * the {@link #SimpleRegression(boolean)} constructor. When the
+ * {@code hasIntercept} property is false, the model is estimated without a
+ * constant term and {@link #getIntercept()} returns {@code 0}.</li>
* </ul></p>
*
* @version $Id$
@@ -97,8 +102,15 @@ public class SimpleRegression implements
this(true);
}
/**
- * Secondary constructor which allows the user the ability to include/exclude const
- * @param includeIntercept boolean flag, true includes an intercept
+ * Create a SimpleRegression instance, specifying whether or not to estimate
+ * an intercept.
+ *
+ * <p>Use {@code false} to estimate a model with no intercept. When the
+ * {@code hasIntercept} property is false, the model is estimated without a
+ * constant term and {@link #getIntercept()} returns {@code 0}.</p>
+ *
+ * @param includeIntercept whether or not to include an intercept term in
+ * the regression model
*/
public SimpleRegression(boolean includeIntercept) {
super();
@@ -332,7 +344,8 @@ public class SimpleRegression implements
}
/**
- * Returns the intercept of the estimated regression line.
+ * Returns the intercept of the estimated regression line, if
+ * {@link #hasIntercept()} is true; otherwise 0.
* <p>
* The least squares estimate of the intercept is computed using the
* <a href="http://www.xycoon.com/estimation4.htm">normal equations</a>.
@@ -345,16 +358,19 @@ public class SimpleRegression implements
* returned.
* </li></ul></p>
*
- * @return the intercept of the regression line
+ * @return the intercept of the regression line if the model includes an
+ * intercept; 0 otherwise
+ * @see #SimpleRegression(boolean)
*/
public double getIntercept() {
return hasIntercept ? getIntercept(getSlope()) : 0.0;
}
/**
- * Returns true if a constant has been included false otherwise.
+ * Returns true if the model includes an intercept term.
*
- * @return true if constant exists, false otherwise
+ * @return true if the regression includes an intercept; false otherwise
+ * @see #SimpleRegression(boolean)
*/
public boolean hasIntercept() {
return hasIntercept;
Modified: commons/proper/math/trunk/src/site/xdoc/userguide/stat.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/userguide/stat.xml?rev=1206838&r1=1206837&r2=1206838&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/userguide/stat.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/userguide/stat.xml Sun Nov 27 20:35:16 2011
@@ -365,10 +365,12 @@ System.out.println(f.getCumPct("z")); /
<code> y = intercept + slope * x </code>
</p>
<p>
- or
+ or
+ </p>
<p>
- <code> y = slope * x </code>
+ <code> y = slope * x </code>
</p>
+ <p>
Standard errors for <code>intercept</code> and <code>slope</code> are
available as well as ANOVA, r-square and Pearson's r statistics.
</p>
@@ -390,6 +392,11 @@ System.out.println(f.getCumPct("z")); /
and get updated statistics without using a new instance. There is no
"compute" method that updates all statistics. Each of the getters performs
the necessary computations to return the requested statistic.</li>
+ <li> The intercept term may be suppressed by passing <code>false</code> to the
+ <a href="../apidocs/org/apache/commons/math/stat/regression/SimpleRegression.html#SimpleRegression(boolean)">
+ SimpleRegression(boolean)</a> constructor. When the <code>hasIntercept</code>
+ property is false, the model is estimated without a constant term and
+ <code>getIntercept()</code> returns <code>0</code>.</li>
</ul>
</p>
<p>
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java?rev=1206838&r1=1206837&r2=1206838&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Sun Nov 27 20:35:16 2011
@@ -162,6 +162,7 @@ public final class SimpleRegressionTest
regression.addData(noint2[0][1], noint2[0][0]);
regression.addData(noint2[1][1], noint2[1][0]);
regression.addData(noint2[2][1], noint2[2][0]);
+ Assert.assertEquals("intercept", 0, regression.getIntercept(), 0);
Assert.assertEquals("slope", 0.727272727272727,
regression.getSlope(), 10E-12);
Assert.assertEquals("slope std err", 0.420827318078432E-01,
@@ -183,6 +184,7 @@ public final class SimpleRegressionTest
for (int i = 0; i < noint1.length; i++) {
regression.addData(noint1[i][1], noint1[i][0]);
}
+ Assert.assertEquals("intercept", 0, regression.getIntercept(), 0);
Assert.assertEquals("slope", 2.07438016528926, regression.getSlope(), 10E-12);
Assert.assertEquals("slope std err", 0.165289256198347E-01,
regression.getSlopeStdErr(),10E-12);