Package org.apache.commons.math.stat

Examples of org.apache.commons.math.stat.DescriptiveStatistics


       
        //FiXME: test all other NaN contract specs
    }

    public void testSkewAndKurtosis() {
        DescriptiveStatistics u = new StorelessDescriptiveStatisticsImpl();
       
        double[] testArray =
        { 12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3, 14.1,
          9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10, 8.8, 9, 12.3 };
        for( int i = 0; i < testArray.length; i++) {
            u.addValue( testArray[i]);
        }
       
        assertEquals("mean", 12.40455, u.getMean(), 0.0001);
        assertEquals("variance", 10.00236, u.getVariance(), 0.0001);
        assertEquals("skewness", 1.437424, u.getSkewness(), 0.0001);
        assertEquals("kurtosis", 2.37719, u.getKurtosis(), 0.0001);
    }
View Full Code Here


        // Initialize binStats ArrayList
        if (!binStats.isEmpty()) {
            binStats.clear();
        }
        for (int i = 0; i < binCount; i++) {
            DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
            binStats.add(i,stats);
        }
       
        // Pass the data again, filling data in binStats Array
        String str = null;
        double val = 0.0d;
        while ((str = in.readLine()) != null) {
            val = new Double(str).doubleValue();
           
            // Find bin and add value to binStats for the bin
            boolean found = false;
            int i = 0;
            while (!found) {
                if (i >= binCount) {
                    throw new RuntimeException("bin alignment error");
                }
                if (val <= binUpperBounds[i]) {
                    found = true;
                    DescriptiveStatistics stats = (DescriptiveStatistics)binStats.get(i);
                    stats.addValue(val);
                }
                i++;
            }
        }
        in.close();
View Full Code Here

        double x = Math.random();
      
        // Use this to select the bin and generate a Gaussian within the bin
        for (int i = 0; i < binCount; i++) {
           if (x <= upperBounds[i]) {
               DescriptiveStatistics stats = (DescriptiveStatistics)binStats.get(i);
               if (stats.getN() > 0) {
                   if (stats.getStandardDeviation() > 0) {  // more than one obs
                        return randomData.nextGaussian
                            (stats.getMean(),stats.getStandardDeviation());
                   } else {
                       return stats.getMean(); // only one obs in bin
                   }
               }
           }
        }
        throw new RuntimeException("No bin selected");
View Full Code Here

        double next = 0.0;
        double tolerance = 0.1;
        vs.computeDistribution();
        assertTrue("empirical distribution property",
            vs.getEmpiricalDistribution() != null);
        DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            next = vs.getNext();
            stats.addValue(next);
        }   
        assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
        assertEquals
         ("std dev", 1.0173699343977738, stats.getStandardDeviation(),
            tolerance);
       
        vs.computeDistribution(500);
        stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            next = vs.getNext();
            stats.addValue(next);
        }   
        assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
        assertEquals
         ("std dev", 1.0173699343977738, stats.getStandardDeviation(),
            tolerance);
       
    }
View Full Code Here

                   // really just checking to make sure we do not bomb
    }
   
    private void tstGen(double tolerance)throws Exception {
        empiricalDistribution.load(file);  
        DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            stats.addValue(empiricalDistribution.getNextValue());
        }
        //TODO: replace these with statistical tests -- refactor as necessary
        assertEquals("mean", stats.getMean(),5.069831575018909,tolerance);
        assertEquals
         ("std dev", stats.getStandardDeviation(),1.0173699343977738,tolerance);
    }
View Full Code Here

            double x = randomData.nextGaussian(0,0);
            fail("zero sigma -- IllegalArgumentException expected");
        } catch (IllegalArgumentException ex) {
            ;
        }
        DescriptiveStatistics u = new StorelessDescriptiveStatisticsImpl();
        for (int i = 0; i<largeSampleSize; i++) {
            u.addValue(randomData.nextGaussian(0,1));
        }
        double xbar = u.getMean();
        double s = u.getStandardDeviation();
        double n = (double) u.getN();
        /* t-test at .001-level TODO: replace with externalized t-test, with
         * test statistic defined in TestStatistic
         */
        assertTrue(Math.abs(xbar)/(s/Math.sqrt(n))< 3.29);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.stat.DescriptiveStatistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.