Java List std getStandardDeviation(List data)

Here you can find the source of getStandardDeviation(List data)

Description

get Standard Deviation

License

Open Source License

Declaration

public static double getStandardDeviation(List<Double> data) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import java.util.List;

public class Main {
    public static double getStandardDeviation(List<Double> data) {
        // sd is sqrt of sum of (values-mean) squared divided by n - 1 
        // Calculate the mean 
        double mean = 0;
        final int n = data.size();
        if (n < 2) {
            return Double.NaN;
        }/*  www  .  ja  v  a 2s.c  o  m*/
        for (int i = 0; i < n; i++) {
            mean += data.get(i);
        }
        mean /= n;
        // calculate the sum of squares
        double sum = 0;
        for (int i = 0; i < n; i++) {
            final double v = data.get(i) - mean;
            sum += v * v;
        }
        // Change to ( n - 1 ) to n if you have complete data instead of a sample.
        return Math.sqrt(sum / (n - 1));
    }
}

Related

  1. calculateStandardDeviation(List doubleList)
  2. getStandardDeviation(List list)
  3. getStandardDeviation(List values)
  4. getStdDeviation(List numbers)
  5. standardDeviation(List data)