Java stddev stddev(int[] values, int start, int length)

Here you can find the source of stddev(int[] values, int start, int length)

Description

Computes the standard deviation of the supplied values.

License

Open Source License

Return

an array of three values: the mean, variance and standard deviation, in that order.

Declaration

public static float[] stddev(int[] values, int start, int length) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

public class Main {
    /**//w ww  .j av a2s.com
     * Computes the standard deviation of the supplied values.
     *
     * @return an array of three values: the mean, variance and standard
     * deviation, in that order.
     */
    public static float[] stddev(int[] values, int start, int length) {
        // first we need the mean
        float mean = 0f;
        for (int ii = start, end = start + length; ii < end; ii++) {
            mean += values[ii];
        }
        mean /= length;

        // next we compute the variance
        float variance = 0f;
        for (int ii = start, end = start + length; ii < end; ii++) {
            float value = values[ii] - mean;
            variance += value * value;
        }
        variance /= (length - 1);

        // the standard deviation is the square root of the variance
        return new float[] { mean, variance, (float) Math.sqrt(variance) };
    }
}

Related

  1. stdDev(double[] array)
  2. stdDev(double[] data)
  3. stddev(final double[] in, final int start, final int length)
  4. stddev(final int[] scores)
  5. stddev(float[] data)
  6. stdDev(Integer[] values)
  7. stddev(long[] samples)
  8. stddev(Number[] array, boolean isSample)
  9. stdDeviation(int[] data)