Java List std stDev(final List list)

Here you can find the source of stDev(final List list)

Description

Gets the standard deviation.

License

GNU General Public License

Parameter

Parameter Description
list the list

Return

the double

Declaration

public static double stDev(final List<Double> list) 

Method Source Code

//package com.java2s;
/*/* ww w.  j a  v a  2s.  c  o  m*/
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009-2012, The University of Melbourne, Australia
 */

import java.util.List;

public class Main {
    /**
     * Gets the standard deviation.
     * 
     * @param list the list
     * @return the double
     */
    public static double stDev(final List<Double> list) {
        return Math.sqrt(variance(list));
    }

    /**
     * Variance.
     * 
     * @param list the list
     * @return the double
     */
    public static double variance(final List<Double> list) {
        long n = 0;
        double mean = mean(list);
        double s = 0.0;

        for (double x : list) {
            n++;
            double delta = x - mean;
            mean += delta / n;
            s += delta * (x - mean);
        }
        // if you want to calculate std deviation
        // of a sample change this to (s/(n-1))
        return s / (n - 1);
    }

    /**
     * Gets the average.
     * 
     * @param list the list
     * 
     * @return the average
     */
    public static double mean(final List<Double> list) {
        double sum = 0;
        for (Double number : list) {
            sum += number;
        }
        return sum / list.size();
    }
}

Related

  1. standardDeviationDouble(List list, boolean populationStandardDeviation)
  2. std(List iNumbers)
  3. std(List vector, Double avg)
  4. stdDev(List nums)
  5. stddev(List observations)
  6. stdev(List values)
  7. stdInt(List elements)
  8. varianceDouble(List list, boolean populationStandardDeviation)