Java List Variance variance(List data)

Here you can find the source of variance(List data)

Description

variance

License

Open Source License

Declaration

public static double variance(List<Integer> data) 

Method Source Code

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

import java.util.Collection;

import java.util.List;

public class Main {
    public static double variance(List<Integer> data) {
        int n = data.size();
        double sum = 0;
        double avg = sum(data) / ((double) n);
        for (int d : data) {
            sum += (d - avg) * (d - avg);
        }//from ww w .ja v a 2  s  . com
        return sum / n;
    }

    public static int sum(Collection<Integer> data) {
        int sum = 0;
        for (int d : data) {
            sum += d;
        }
        return sum;
    }
}

Related

  1. variance(ArrayList doubleArrayList)
  2. variance(final List list)
  3. variance(List data)
  4. variance(List observations)
  5. variance(List values)