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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]