using System.Collections.Generic; using System.Linq; namespace DTS.Utilities { public class StandardDev { public static double StandardDeviation(IEnumerable values) { double standardDeviation = 0; if (!values.Any()) return standardDeviation; // Compute the average. double avg = values.Average(); // Perform the Sum of (value-avg)_2_2. double sum = values.Sum(d => System.Math.Pow(d - avg, 2)); // Put it all together. standardDeviation = System.Math.Sqrt((sum) / (values.Count() - 1)); return standardDeviation; } } }