Java stddev std(double[] a)

Here you can find the source of std(double[] a)

Description

Returns the standard variance.

License

Apache License

Parameter

Parameter Description
a the array.

Return

the standard variance.

Declaration

public static double std(double[] a) 

Method Source Code

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

public class Main {
    /**/*  www  . j  a v a 2  s  .c o  m*/
     * Returns the standard variance.
     * 
     * @param a the array.
     * @return the standard variance.
     */
    public static double std(double[] a) {
        return std(a, a.length);
    }

    /**
     * Returns the standard variance.
     * 
     * @param a the array.
     * @param n the total number of elements.
     * @return the standard variance.
     */
    public static double std(double[] a, int n) {
        return Math.sqrt(variance(a, n));
    }

    /**
     * Returns the variance.
     * 
     * @param a the array.
     * @return the variance.
     */
    public static double variance(double[] a) {
        return variance(a, a.length);
    }

    /**
     * Returns the variance.
     * 
     * @param a the array.
     * @param n the total number of elements.
     * @return the variance.
     */
    public static double variance(double[] a, int n) {
        double avg = mean(a, n);
        double sq = 0.0;
        for (double v : a) {
            double d = v - avg;
            sq += d * d;
        }
        return sq / (n - 1.0);
    }

    /**
     * Returns the mean.
     * 
     * @param a the array.
     * @return the mean.
     */
    public static double mean(double[] a) {
        return mean(a, a.length);
    }

    /**
     * Returns the mean.
     * 
     * @param a the array.
     * @param n the total number of elements.
     * @return the mean.
     */
    public static double mean(double[] a, int n) {
        double avg = 0.0;
        for (double v : a) {
            avg += v;
        }
        return avg / n;
    }
}

Related

  1. getStandardDeviation(double meanValue, ArrayList values)
  2. standardDeviation(double[] data)
  3. standardDeviation(double[] data, int opt)
  4. std(Collection dist, boolean populationStd)
  5. std(double a[])
  6. std(double[] arr)
  7. std(double[] array)
  8. std(final double[] vec)
  9. std(final double[] x, final int begin, final int end)