Java stddev stddev(final double[] in, final int start, final int length)

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

Description

Calculate the (population) standard deviation of an array of doubles.

License

Open Source License

Declaration

public static double stddev(final double[] in, final int start, final int length) 

Method Source Code

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

public class Main {
    /** Calculate the (population) standard deviation of an array of doubles. */
    public static double stddev(final double[] in, final int start, final int length) {
        return stddev(in, start, length, mean(in, start, length));
    }//from  ww w .  java2s .c o m

    /** Calculate the (population) standard deviation of an array of doubles. */
    public static double stddev(final double[] in, final int start, final int stop, final double mean) {
        if ((stop - start) <= 0)
            return Double.NaN;

        double total = 0;
        for (int i = start; i < stop; ++i) {
            total += (in[i] * in[i]);
        }

        return Math.sqrt((total / (stop - start)) - (mean * mean));
    }

    /** Calculate the mean of an array of doubles. */
    public static double mean(final double[] in, final int start, final int stop) {
        if ((stop - start) <= 0)
            return Double.NaN;

        double total = 0;
        for (int i = start; i < stop; ++i) {
            total += in[i];
        }

        return total / (stop - start);
    }
}

Related

  1. stddev(double[] a)
  2. stddev(double[] arr)
  3. stdDev(double[] array)
  4. stdDev(double[] data)
  5. stddev(double[] observations)
  6. stddev(final int[] scores)
  7. stddev(float[] data)
  8. stddev(int[] values, int start, int length)
  9. stdDev(Integer[] values)