Here you can find the source of std(double[] a, double mean, boolean isUnbiasedEstimator)
public static double std(double[] a, double mean, boolean isUnbiasedEstimator)
//package com.java2s; //License from project: Open Source License public class Main { public static double std(double[] a, double mean, boolean isUnbiasedEstimator) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); }// w w w. j a v a 2s.c o m int N = a.length; int divisor = isUnbiasedEstimator ? N - 1 : N; double sum = 0.0; for (int n = 0; n < N; n++) { sum += (a[n] - mean) * (a[n] - mean); } return Math.sqrt(sum / divisor); } /** Default is the unbiased estimator std. The one where the divisor is N-1 **/ public static double std(double[] a, double mean) { return std(a, mean, true); } public static double std(double[] a, boolean isUnbiasedEstimator) { return std(a, mean(a), isUnbiasedEstimator); } public static double std(double[] a) { return std(a, mean(a), true); } public static double std(int[] a, double mean, boolean isUnbiasedEstimator) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } int N = a.length; int divisor = isUnbiasedEstimator ? N - 1 : N; double sum = 0.0; for (int n = 0; n < N; n++) { sum += (a[n] - mean) * (a[n] - mean); } return Math.sqrt(sum / divisor); } /** Default is the unbiased estimator std. The one where the divisor is N-1 **/ public static double std(int[] a, double mean) { return std(a, mean, true); } public static double std(int[] a, boolean isUnbiasedEstimator) { return std(a, mean(a), isUnbiasedEstimator); } public static double std(int[] a) { return std(a, mean(a), true); } public static Double std(Double[] a, Double mean, boolean isUnbiasedEstimator) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } int N = a.length; int divisor = isUnbiasedEstimator ? N - 1 : N; Double sum = 0.0; for (int n = 0; n < N; n++) { sum += (a[n] - mean) * (a[n] - mean); } return Math.sqrt(sum / divisor); } /** Default is the unbiased estimator std. The one where the divisor is N-1 **/ public static Double std(Double[] a, Double mean) { return std(a, mean, true); } public static Double std(Double[] a, boolean isUnbiasedEstimator) { return std(a, mean(a), isUnbiasedEstimator); } public static Double std(Double[] a) { return std(a, mean(a), true); } public static Double std(Integer[] a, Double mean, boolean isUnbiasedEstimator) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } int N = a.length; int divisor = isUnbiasedEstimator ? N - 1 : N; Double sum = 0.0; for (int n = 0; n < N; n++) { sum += (a[n] - mean) * (a[n] - mean); } return Math.sqrt(sum / divisor); } /** Default is the unbiased estimator std. The one where the divisor is N-1 **/ public static Double std(Integer[] a, Double mean) { return std(a, mean, true); } public static Double std(Integer[] a, boolean isUnbiasedEstimator) { return std(a, mean(a), isUnbiasedEstimator); } public static Double std(Integer[] a) { return std(a, mean(a), true); } public static Double mean(Double[] a) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } Double sum = 0.0; for (int n = 0; n < a.length; n++) { sum += a[n]; } return sum / a.length; } public static double mean(double[] a) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } double sum = 0.0; for (int n = 0; n < a.length; n++) { sum += a[n]; } return sum / a.length; } public static Double mean(Integer[] a) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } Double[] a_d = new Double[a.length]; for (int n = 0; n < a_d.length; n++) { a_d[n] = Double.valueOf(a[n]); } return mean(a_d); } public static double mean(int[] a) { if (a.length == 0) { throw new IllegalArgumentException("The entered array is empty."); } double[] a_d = new double[a.length]; for (int n = 0; n < a_d.length; n++) { a_d[n] = a[n]; } return mean(a_d); } }