Java List std calculateStandardDeviation(List doubleList)

Here you can find the source of calculateStandardDeviation(List doubleList)

Description

calculate Standard Deviation

License

LGPL

Declaration

public static Double calculateStandardDeviation(List<Double> doubleList) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.List;

public class Main {
    public static Double calculateStandardDeviation(List<Double> doubleList) {
        if (doubleList.size() > 1) {
            double mean = calculateMeanOfArrayListDouble(doubleList);
            double sumOfSquaredResiduals = 0;
            for (double a : doubleList) {
                double residual = mean - a;
                sumOfSquaredResiduals += Math.pow(residual, 2);
            }/*from   ww  w .j a v a 2s .  co m*/
            // n-1 observations are redundant
            return Math.sqrt(sumOfSquaredResiduals / (doubleList.size() - 1));
        } else {
            return Double.NaN;
        }

    }

    public static Double calculateStandardDeviation(List<Double> doubleList, double true_value) {
        if (doubleList.size() > 1) {

            double sumOfSquaredResiduals = 0;
            for (double a : doubleList) {
                double residual = true_value - a;
                sumOfSquaredResiduals += Math.pow(residual, 2);
            }
            // n-1 observations are redundant
            return Math.sqrt(sumOfSquaredResiduals / (doubleList.size() - 1));
        } else {
            return Double.NaN;
        }
    }

    public static double calculateMeanOfArrayListDouble(List<Double> dList) {

        double sum = 0;
        for (double x : dList) {
            sum += x;
        }

        return sum / dList.size();
    }
}

Related

  1. getStandardDeviation(List data)
  2. getStandardDeviation(List list)
  3. getStandardDeviation(List values)
  4. getStdDeviation(List numbers)