Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 97873 invoked from network); 7 Jun 2007 13:09:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jun 2007 13:09:21 -0000 Received: (qmail 29982 invoked by uid 500); 7 Jun 2007 13:09:23 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 29921 invoked by uid 500); 7 Jun 2007 13:09:22 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 29910 invoked by uid 500); 7 Jun 2007 13:09:22 -0000 Received: (qmail 29907 invoked by uid 99); 7 Jun 2007 13:09:22 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2007 06:09:22 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2007 06:09:18 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3C3C01A981A; Thu, 7 Jun 2007 06:08:58 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r545161 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Date: Thu, 07 Jun 2007 13:08:58 -0000 To: commons-cvs@jakarta.apache.org From: brentworden@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070607130858.3C3C01A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: brentworden Date: Thu Jun 7 06:08:57 2007 New Revision: 545161 URL: http://svn.apache.org/viewvc?view=rev&rev=545161 Log: Removed dependency on DistributionFactory. Added settable t distribution field. Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java?view=diff&rev=545161&r1=545160&r2=545161 ============================================================================== --- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original) +++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Thu Jun 7 06:08:57 2007 @@ -19,8 +19,8 @@ import java.io.Serializable; import org.apache.commons.math.MathException; -import org.apache.commons.math.distribution.DistributionFactory; import org.apache.commons.math.distribution.TDistribution; +import org.apache.commons.math.distribution.TDistributionImpl; /** * Estimates an ordinary least squares regression model @@ -57,6 +57,9 @@ /** Serializable version identifier */ private static final long serialVersionUID = -3004689053607543335L; + /** the distribution used to compute inference statistics. */ + private TDistribution distribution; + /** sum of x values */ private double sumX = 0d; @@ -87,7 +90,18 @@ * Create an empty SimpleRegression instance */ public SimpleRegression() { + this(new TDistributionImpl(1.0)); + } + + /** + * Create an empty SimpleRegression using the given distribution object to + * compute inference statistics. + * @param t the distribution used to compute inference statistics. + * @since 1.2 + */ + public SimpleRegression(TDistribution t) { super(); + setDistribution(t); } /** @@ -119,6 +133,10 @@ sumX += x; sumY += y; n++; + + if (n > 2) { + distribution.setDegreesOfFreedom(n - 2); + } } /** @@ -455,7 +473,7 @@ throw new IllegalArgumentException(); } return getSlopeStdErr() * - getTDistribution().inverseCumulativeProbability(1d - alpha / 2d); + distribution.inverseCumulativeProbability(1d - alpha / 2d); } /** @@ -480,7 +498,7 @@ * @throws MathException if the significance level can not be computed. */ public double getSignificance() throws MathException { - return 2d* (1.0 - getTDistribution().cumulativeProbability( + return 2d * (1.0 - distribution.cumulativeProbability( Math.abs(getSlope()) / getSlopeStdErr())); } @@ -507,14 +525,18 @@ private double getRegressionSumSquares(double slope) { return slope * slope * sumXX; } - + /** - * Uses distribution framework to get a t distribution instance - * with df = n - 2 - * - * @return t distribution with df = n - 2 - */ - private TDistribution getTDistribution() { - return DistributionFactory.newInstance().createTDistribution(n - 2); + * Modify the distribution used to compute inference statistics. + * @param value the new distribution + * @since 1.2 + */ + public void setDistribution(TDistribution value) { + distribution = value; + + // modify degrees of freedom + if (n > 2) { + distribution.setDegreesOfFreedom(n - 2); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org