From aba7e04d4430e2f9786b97d19a22ccb536419687 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Mon, 13 Sep 2010 02:01:42 +0000 Subject: [PATCH] Made intercept/noIntercept configurable in multiple regression classes. JIRA: MATH-409. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@996404 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractMultipleLinearRegression.java | 54 ++++++++--- .../OLSMultipleLinearRegression.java | 80 +++++++++------ src/site/xdoc/changes.xml | 8 +- src/test/R/multipleOLSRegressionTestCases | 66 ++++++++++++- .../MultipleLinearRegressionAbstractTest.java | 10 ++ .../OLSMultipleLinearRegressionTest.java | 97 +++++++++++++++++-- 6 files changed, 257 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java b/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java index b069f4175..b85dcc193 100644 --- a/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java +++ b/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java @@ -39,6 +39,23 @@ public abstract class AbstractMultipleLinearRegression implements /** Y sample data. */ protected RealVector Y; + /** Whether or not the regression model includes an intercept. True means no intercept. */ + private boolean noIntercept = false; + + /** + * @return true if the model has no intercept term; false otherwise + */ + public boolean isNoIntercept() { + return noIntercept; + } + + /** + * @param noIntercept true means the model is to be estimated without an intercept term + */ + public void setNoIntercept(boolean noIntercept) { + this.noIntercept = noIntercept; + } + /** *

Loads model x and y sample data from a flat input array, overriding any previous sample. *

@@ -55,7 +72,9 @@ public abstract class AbstractMultipleLinearRegression implements * *

*

Note that there is no need to add an initial unitary column (column of 1's) when - * specifying a model including an intercept term. + * specifying a model including an intercept term. If {@link #isNoIntercept()} is true, + * the X matrix will be created without an initial column of "1"s; otherwise this column will + * be added. *

*

Throws IllegalArgumentException if any of the following preconditions fail: *