Here you can find the source of variance(List
public static double variance(List<Double> observations)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static double variance(List<Double> observations) { double mean = average(observations); double varSum = 0.0; for (double d : observations) { varSum += (d - mean) * (d - mean); }// w ww. j a v a2s. c o m 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; } }