Java stddev stdDeviation(int[] data)

Here you can find the source of stdDeviation(int[] data)

Description

Returns standard deviation of array of ints

License

Open Source License

Parameter

Parameter Description
x a parameter

Declaration

public static double stdDeviation(int[] data) 

Method Source Code

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

public class Main {
    /**//from w  ww .ja va  2s  .  co  m
     * Returns standard deviation of array of ints
     * 
     * @param x
     * @return
     */
    public static double stdDeviation(int[] data) {
        double mean = mean(data);
        double sum = 0;

        for (int i = 0; i < data.length; i++) {
            sum += Math.pow(data[i] - mean, 2);
        }

        return Math.sqrt((sum) / (data.length - 1));
    }

    /**
     * Returns mean of array of ints
     * 
     * @param data
     * @return
     */
    public static double mean(int[] data) {
        int sum = 0;
        for (int i = 0; i < data.length; i++) {
            sum += data[i];
        }
        return (sum / data.length);
    }
}

Related

  1. stddev(int[] values, int start, int length)
  2. stdDev(Integer[] values)
  3. stddev(long[] samples)
  4. stddev(Number[] array, boolean isSample)
  5. stdDev(T[] array)
  6. stdev(Collection values)
  7. stdev(Collection values)
  8. stdev(double... array)
  9. stdev(double[] array)