commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/inference ChiSquareTestImpl.java
Date Sun, 20 Jun 2004 02:54:05 GMT
psteitz     2004/06/19 19:54:05

  Modified:    math/src/java/org/apache/commons/math/stat/inference
                        ChiSquareTestImpl.java
  Log:
  Javadoc, formatting.
  
  Revision  Changes    Path
  1.7       +19 -10    jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
  
  Index: ChiSquareTestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ChiSquareTestImpl.java	14 Jun 2004 23:26:53 -0000	1.6
  +++ ChiSquareTestImpl.java	20 Jun 2004 02:54:05 -0000	1.7
  @@ -29,6 +29,9 @@
       /** Cached DistributionFactory used to create ChiSquaredDistribution instances */
       private DistributionFactory distributionFactory = null;
     
  +    /**
  +     * Construct a ChiSquareTestImpl 
  +     */
       public ChiSquareTestImpl() {
           super();
       }
  @@ -45,7 +48,8 @@
           double sumSq = 0.0d;
           double dev = 0.0d;
           if ((expected.length < 2) || (expected.length != observed.length)) {
  -            throw new IllegalArgumentException("observed, expected array lengths incorrect");
  +            throw new IllegalArgumentException(
  +                    "observed, expected array lengths incorrect");
           }
           if (!isPositive(expected) || !isNonNegative(observed)) {
               throw new IllegalArgumentException(
  @@ -68,8 +72,10 @@
       public double chiSquareTest(double[] expected, long[] observed)
           throws IllegalArgumentException, MathException {
           ChiSquaredDistribution chiSquaredDistribution =
  -            getDistributionFactory().createChiSquareDistribution((double) expected.length
- 1);
  -        return 1 - chiSquaredDistribution.cumulativeProbability(chiSquare(expected, observed));
  +            getDistributionFactory().createChiSquareDistribution(
  +                    (double) expected.length - 1);
  +        return 1 - chiSquaredDistribution.cumulativeProbability(
  +                chiSquare(expected, observed));
       }
   
       /**
  @@ -81,10 +87,11 @@
        * @throws IllegalArgumentException if preconditions are not met
        * @throws MathException if an error occurs performing the test
        */
  -    public boolean chiSquareTest(double[] expected, long[] observed, double alpha)
  -        throws IllegalArgumentException, MathException {
  +    public boolean chiSquareTest(double[] expected, long[] observed, 
  +            double alpha) throws IllegalArgumentException, MathException {
           if ((alpha <= 0) || (alpha > 0.5)) {
  -            throw new IllegalArgumentException("bad significance level: " + alpha);
  +            throw new IllegalArgumentException(
  +                    "bad significance level: " + alpha);
           }
           return (chiSquareTest(expected, observed) < alpha);
       }
  @@ -118,8 +125,8 @@
           for (int row = 0; row < nRows; row++) {
               for (int col = 0; col < nCols; col++) {
                   expected = (rowSum[row] * colSum[col]) / total;
  -                sumSq += (((double) counts[row][col] - expected) * ((double) counts[row][col]
- expected))
  -                    / expected; 
  +                sumSq += (((double) counts[row][col] - expected) * 
  +                        ((double) counts[row][col] - expected)) / expected; 
               }
           } 
           return sumSq;
  @@ -162,7 +169,7 @@
        * throwing IllegalArgumentException if any of these checks fail.
        * 
        * @param in input 2-way table to check
  -     * @throws IllegalArgumentException
  +     * @throws IllegalArgumentException if the array is not valid
        */
       private void checkArray(long[][] in) throws IllegalArgumentException {
           
  @@ -187,6 +194,8 @@
       //---------------------  Protected methods ---------------------------------
       /**
        * Gets a DistributionFactory to use in creating ChiSquaredDistribution instances.
  +     * 
  +     * @return a DistributionFactory
        */
       protected DistributionFactory getDistributionFactory() {
           if (distributionFactory == null) {
  
  
  

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


Mime
View raw message