List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics setVarianceImpl
public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
Sets the implementation for the variance.
From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java
/** * The sample variance can be calculated in two ways: if the dataset is considered as the entire population then the * sample variance is simply the second central moment: * /*from w ww . ja va2s.co m*/ * <pre> * sum((x_i - m)^2)/N * where {x_i} are set of N population values and m is the mean * m = sum(x_i)/N * </pre> * * Otherwise, if the dataset is a set of samples (with replacement) from the population then * * <pre> * sum((x_i - m)^2)/(N-1) * where {x_i} are set of N sample values and m is the unbiased estimate of the mean * m = sum(x_i)/N * </pre> * * Note that the second definition is also the unbiased estimator of population variance. * * @param isDatasetWholePopulation * @return sample variance */ public Number variance(boolean isDatasetWholePopulation) { SummaryStatistics stats = getStatistics(); if (isDatasetWholePopulation) { StorelessUnivariateStatistic oldVar = stats.getVarianceImpl(); stats.setVarianceImpl(new Variance(false)); Number var = stats.getVariance(); stats.setVarianceImpl(oldVar); return var; } return stats.getVariance(); }