private static List <StatisticClass> CreateClasses(double classAmplitude, int classNumber, List <double> allElements) { var list = new List <StatisticClass>(); var classVariable = Math.Round(allElements[0], 3); var accumulatedFrequency = 0; for (var i = 0; i < classNumber; i++) { var myClass = new StatisticClass() { Begin = Math.Round(classVariable, 3), End = Math.Round(classVariable += classAmplitude, 3) }; myClass.DefineName(); foreach (var item in allElements) { if (item >= myClass.Begin && item < myClass.End) { myClass.Elements.Add(item); } } myClass.AbsolutFrequency = myClass.Elements.Count(); myClass.AccumulatedFrequency = accumulatedFrequency += myClass.AbsolutFrequency; myClass.MidPoint = ClassMidPointCalculator(myClass.End, myClass.Begin); list.Add(myClass); } return(list); }
private static double CalculateMedian(List <StatisticClass> values, double amplitude) { double medianPos = values.Count / 2; var medianClass = new StatisticClass(); foreach (var value in values) { if (!(medianPos < value.AccumulatedFrequency)) { continue; } medianClass = value; break; } var medianClassPos = values.FindIndex(a => a == medianClass); var previousMedianClassFrequency = PreviousFrequencyMedian(values, medianClassPos); var divisionTop = medianPos - previousMedianClassFrequency; var lowerLimitMiddleClass = medianClass.Begin; var absoluteFrequencyMiddleClass = medianClass.AbsolutFrequency; var median = lowerLimitMiddleClass + ((divisionTop / absoluteFrequencyMiddleClass) * amplitude); return(median); }