Java Standard Deviation Calculate calcStdDeviation(int sampleCount, long total, long sumOfSquares)

Here you can find the source of calcStdDeviation(int sampleCount, long total, long sumOfSquares)

Description

calc Std Deviation

License

Open Source License

Declaration

static public double calcStdDeviation(int sampleCount, long total, long sumOfSquares) 

Method Source Code

//package com.java2s;
/*//from   w w  w .ja v a  2 s  .  c o  m
 *   Copyright 2008-2011 Follett Software Company 
 *
 *   This file is part of PerfMon4j(tm).
 *
 *    Perfmon4j is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License, version 3,
 *    as published by the Free Software Foundation.  This program is distributed
 *    WITHOUT ANY WARRANTY OF ANY KIND, WITHOUT AN IMPLIED WARRANTY OF MERCHANTIBILITY,
 *    OR FITNESS FOR A PARTICULAR PURPOSE.  You should have received a copy of the GNU Lesser General Public 
 *    License, Version 3, along with this program.  If not, you can obtain the LGPL v.s at 
 *    http://www.gnu.org/licenses/
 *    
 *    perfmon4j@fsc.follett.com
 *    David Deuchert
 *    Follett Software Company
 *    1391 Corporate Drive
 *    McHenry, IL 60050
 * 
*/

public class Main {
    static public double calcStdDeviation(int sampleCount, long total, long sumOfSquares) {
        double result = 0;

        double variance = calcVariance(sampleCount, total, sumOfSquares);
        if (variance > 0) {
            result = Math.sqrt(variance);
        }

        return result;
    }

    static public double calcVariance(int sampleCount, long total, long sumOfSquares) {
        double result = 0;

        if (sampleCount > 1) {
            result = ((sumOfSquares - ((total * total) / (double) sampleCount)) / ((double) sampleCount - 1));
        }

        return result;
    }
}

Related

  1. calcStdDeviation(double[] population)
  2. computeStddev(double[] array, double mean)
  3. computeStdDev(double[] results, double mean)
  4. computeStddev(float[] array, float mean)