Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-691

Statistics.setVarianceImpl makes getStandardDeviation produce NaN

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.2
    • 3.0
    • None
    • None
    • Windows 7 64-bit, java version 1.6.0_23

    Description

      Invoking SummaryStatistics.setVarianceImpl(new Variance(true/false) makes getStandardDeviation produce NaN. The code to reproduce it:

      int[] scores = {1, 2, 3, 4};
      SummaryStatistics stats = new SummaryStatistics();
      stats.setVarianceImpl(new Variance(false)); //use "population variance"
      for(int i : scores) {
        stats.addValue(i);
      }
      double sd = stats.getStandardDeviation();
      System.out.println(sd);
      

      A workaround suggested by Mikkel is:

        double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN());
      

      Attachments

        Activity

          People

            psteitz Phil Steitz
            warrentang Warren Tang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5h
                5h
                Remaining:
                Remaining Estimate - 5h
                5h
                Logged:
                Time Spent - Not Specified
                Not Specified