Java List std stdInt(List elements)

Here you can find the source of stdInt(List elements)

Description

std Int

License

Open Source License

Parameter

Parameter Description
iNumbers - integers

Return

the standard deviation

Declaration

public static Double stdInt(List<Integer> elements) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from ww w  .j  a  v a  2 s. c  o m*/
     *    
     * @param iNumbers - integers
     * @return the standard deviation
     */
    public static Double stdInt(List<Integer> elements) {
        List<Double> doubles = new ArrayList<Double>(elements.size());
        for (Integer n : elements) {
            doubles.add(new Double(n));
        }
        return std(doubles);
    }

    /**
     *    
     * @param iNumbers - doubles
     * @return the standard deviation
     */
    public static double std(List<Double> iNumbers) {

        double result = 0;
        double mu = average(iNumbers);
        for (Double number : iNumbers)
            result += Math.pow(number - mu, 2);

        result /= iNumbers.size();

        return Math.sqrt(result);
    }

    /**
     *    
     * @param iNumbers - doubles
     * @param mu - the average
     * @return the standard deviation
     */
    public static double std(List<Double> iNumbers, double mu) {

        double result = 0;

        for (Double number : iNumbers)
            result += Math.pow(number - mu, 2);

        result /= iNumbers.size();

        return Math.sqrt(result);
    }

    /**
     *    
     * @param numbers - doubles
     * @return their average
     */
    public static double average(List<Double> numbers) {

        double sum = 0;
        for (Double number : numbers)
            sum += number;
        return sum / numbers.size();
    }
}

Related

  1. std(List vector, Double avg)
  2. stdDev(List nums)
  3. stddev(List observations)
  4. stDev(final List list)
  5. stdev(List values)
  6. varianceDouble(List list, boolean populationStandardDeviation)