Java stddev stdev(Collection values)

Here you can find the source of stdev(Collection values)

Description

stdev

License

Open Source License

Declaration

public static double stdev(Collection<Double> values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    public static double stdev(Collection<Double> values) {
        double ret = 0;
        double mean = average(values);
        for (Double val : values)
            ret += Math.pow(val - mean, 2);
        return Math.sqrt(ret / (values.size() - 1));
    }/*ww w  .  ja v  a 2s. c om*/

    public static double stdev(double[] values) {
        double ret = 0;
        double mean = average(values);
        for (int i = 0; i < values.length; i++)
            ret += Math.pow(values[i] - mean, 2);
        return Math.sqrt(ret / (values.length - 1));
    }

    public static double average(Collection<Double> values) {
        double ret = 0;
        for (Double val : values)
            ret += val;
        return ret / values.size();
    }

    public static double average(double[] values) {
        double ret = 0;
        for (int i = 0; i < values.length; i++)
            ret += values[i];
        return ret / values.length;
    }
}

Related

  1. stddev(long[] samples)
  2. stddev(Number[] array, boolean isSample)
  3. stdDev(T[] array)
  4. stdDeviation(int[] data)
  5. stdev(Collection values)
  6. stdev(double... array)
  7. stdev(double[] array)
  8. stdev(final double... values)
  9. stdev(long[] vals, long average)