Created
February 20, 2018 12:22
-
-
Save wolframalpha/2df84bc71d28400598877f391c55f2b0 to your computer and use it in GitHub Desktop.
Override the function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override string Finalize() | |
| { | |
| //Calculating the summary statistics | |
| sum = rowvalue.Sum(); | |
| min = rowvalue.Min(); | |
| max = rowvalue.Max(); | |
| count = rowvalue.Count(); | |
| mean=rowvalue.Average(); | |
| range=max-min; | |
| cumReciprocal = rowvalue.Sum(x=>1.0/x); | |
| HarmonicMean = rowvalue.Count()/cumReciprocal; | |
| GeometricMean= Math.Exp(rowvalue.Average(x=>Math.Log(x))); | |
| SumOfError=rowvalue.Sum(x=>Math.Abs(x-mean)); | |
| SumOfErrorSquare=rowvalue.Sum(x=>Math.Pow(Math.Abs(x-mean),2)); | |
| Variance=SumOfErrorSquare/((double)count-1); | |
| StdDev=Math.Sqrt(Variance); | |
| SkewCum=rowvalue.Sum(x=>Math.Pow((x-mean)/StdDev,3)); | |
| m4=rowvalue.Sum(x=>Math.Pow((x-mean)/StdDev,4)); | |
| Skewness=((count)/((count-1)*(count-2)))*SkewCum; | |
| Kurtosis=((((count + 1) * count)/((count - 1)*(count - 2)*(count - 3)))*(m4))-(3*Math.Pow(count-1,2))/((count-2) * (count-3)); | |
| //Sorted List | |
| double[] Sorted_List = rowvalue.OrderBy(x=>x).ToArray(); | |
| Func<double[], double, double> percentileCal = (double[] sortedData, double p) => { | |
| // algo derived from Aczel pg 15 bottom | |
| if (p >= 100.0d) return sortedData[sortedData.Length - 1]; | |
| double position = (double)(sortedData.Length + 1) * p / 100.0; | |
| double leftNumber = 0.0d, rightNumber = 0.0d; | |
| double n = p / 100.0d * (sortedData.Length - 1) + 1.0d; | |
| if (position >= 1) | |
| { | |
| leftNumber = sortedData[(int)System.Math.Floor(n) - 1]; | |
| rightNumber = sortedData[(int)System.Math.Floor(n)]; | |
| } | |
| else | |
| { | |
| leftNumber = sortedData[0]; // first data | |
| rightNumber = sortedData[1]; // first data | |
| } | |
| if (leftNumber == rightNumber) | |
| return leftNumber; | |
| else | |
| { | |
| double part = n - System.Math.Floor(n); | |
| return leftNumber + part * (rightNumber - leftNumber); | |
| } | |
| }; | |
| FirstQuartile = percentileCal(Sorted_List, 25); | |
| ThirdQuartile = percentileCal(Sorted_List, 75); | |
| Median = percentileCal(Sorted_List, 50); | |
| IQR = percentileCal(Sorted_List, 75) - percentileCal(Sorted_List, 25); | |
| string outputString = FirstQuartile.ToString()+","+Kurtosis.ToString()+","+Skewness.ToString()+","+SkewCum.ToString()+","+StdDev.ToString()+","+Variance.ToString()+","+SumOfErrorSquare.ToString()+","+SumOfError.ToString()+","+sum.ToString()+","+min.ToString()+","+max.ToString()+","+ count.ToString()+","+ mean.ToString()+","+range.ToString()+","+GeometricMean.ToString()+","+HarmonicMean.ToString(); //note that the output will be string | |
| return outputString.ToString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment