Java stddev stddev(double[] observations)

Here you can find the source of stddev(double[] observations)

Description

stddev

License

Open Source License

Declaration

public static double stddev(double[] observations) 

Method Source Code


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

import java.util.*;

public class Main {
    public static double stddev(double[] observations) {
        return Math.sqrt(variance(observations));
    }/*from  w  ww .  j  av a 2  s.  c  om*/

    public static double variance(List<Double> observations) {
        double mean = average(observations);
        double varSum = 0.0;
        for (double d : observations) {
            varSum += (d - mean) * (d - mean);
        }
        return varSum / observations.size();
    }

    public static double variance(double[] observations) {
        double mean = average(observations);
        double varSum = 0.0;
        for (double d : observations) {
            varSum += (d - mean) * (d - mean);
        }
        // use bessel's correction
        return varSum / (observations.length - 1);
    }

    public static double average(List<Double> observations) {
        double total = 0.0;
        for (double d : observations) {
            total += d;
        }
        return total / observations.size();
    }

    public static double average(double[] data) {
        double total = 0.0;
        for (double d : data) {
            total += d;
        }
        return total / data.length;
    }
}

Related

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