Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.2
-
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());