Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Main(string[] args)
- {
- int[] num = {
- 52,61,91,41,40,48,25,55,63,44,
- 88,55,62,58,98,51,30,73,57,95,
- 95,40,85,66,87,24,65,48,96,75,
- 45,36,75,71,85,24,92,50,50,57,
- 72,90,77,65,70,33,61,81,72,50
- };
- num = num.OrderByDescending(x => x).ToArray(); // Highest value is in the top
- num.Reverse();
- Console.WriteLine("Lowest Number - " + num[num.Length-1]);
- Console.WriteLine("Highest Number - " + num[0]);
- int EF = 0;
- MelodyHelp.ForEach(num, x => EF += x);
- #region Undefined Group
- double UD_Mean = ( EF / num.Length ); // Simple...
- int UD_MeanRounded = (int)Math.Round(UD_Mean);
- Console.WriteLine("Mean - " + UD_Mean);
- double UD_MedianCenter = 0;
- double UD_MedianAverage = 0;
- // Odd (n+1/2)
- if(num.Length % 2 != 0) {
- UD_MedianCenter = num[ (num.Length + 1) / 2 ];
- UD_MedianAverage = UD_MedianCenter;
- // Even
- } else {
- UD_MedianAverage = (num[ (num.Length) / 2 ] + num[ ( (num.Length) / 2 ) + 1 ])/2;
- UD_MedianCenter = num[ (num.Length + 1) / 2 ];
- }
- Console.WriteLine("Median (n+1/2) - " + UD_MedianCenter);
- Console.WriteLine("Median (Average of two middle numbers) - " + UD_MedianAverage);
- Dictionary<int, int> modeTemp1 = new Dictionary<int, int>();
- // Iterate through num
- foreach(int n in num) {
- if(!modeTemp1.ContainsKey(n)) {
- modeTemp1.Add(n, 1);
- } else {
- modeTemp1[n]++;
- }
- }
- List<int> UD_Mode = new List<int>();
- int modeTemp2 = modeTemp1.Values.OrderByDescending(x => x).ToArray()[0]; // Get highest value
- foreach(int n in modeTemp1.Keys)
- if(modeTemp1[n] == modeTemp2)
- UD_Mode.Add(n);
- List<string> TEMPUDMODE = new List<string>();
- foreach(int s in UD_Mode)
- TEMPUDMODE.Add(s.ToString());
- Console.WriteLine("Mode(s) - " + TEMPUDMODE.BetterToString(","));
- // Variability
- int UD_Range = num[0] - num[num.Length-1]; // HIGHEST VALUE - LOWEST VALUE
- Console.WriteLine("Range - " + UD_Range);
- double UD_MeanDeviation = 0;
- foreach(int n in num) {
- UD_MeanDeviation += (n - UD_MeanRounded);
- }
- UD_MeanDeviation /= num.Length;
- UD_MeanDeviation = Math.Round(UD_MeanDeviation, 2);
- Console.WriteLine("Mean Deviation - " + UD_MeanDeviation);
- double UD_StandardDeviation = 0;
- double UD_Variance = 0;
- foreach(int n in num) {
- UD_Variance += (Math.Pow(n-UD_MeanRounded,2));
- }
- UD_Variance /= num.Length;
- UD_Variance = Math.Round(UD_Variance, 2);
- UD_StandardDeviation = Math.Round(Math.Sqrt(UD_Variance), 2);
- Console.WriteLine("Variance - " + UD_Variance);
- Console.WriteLine("Standard Deviation - " + UD_StandardDeviation);
- #endregion
- Console.WriteLine("--[[GROUPED DATA STARTS HERE]]--");
- #region Grouped Data
- // Rounded off to the nearest and highest odd number
- int GD_ClassInterval = 0;
- int CITemp1 = (int)Math.Round((double)UD_Range / 10);
- if(CITemp1 % 2 == 0) // IS odd number
- CITemp1++;
- GD_ClassInterval = CITemp1;
- Console.WriteLine("Class Interval - " + GD_ClassInterval);
- int GD_ScoreStart = -1;
- // Start number is the nearest number below the range, which is divisible by the class interval
- for(int i = UD_Range; i >= 0; i--) {
- if(i % GD_ClassInterval == 0 && i <= num[num.Length-1]) {
- GD_ScoreStart = i;
- break;
- }
- }
- if(GD_ScoreStart < 0) {
- Console.WriteLine("Something has gone wrong while calculating the start of the score table!");
- Thread.Sleep(-1);
- }
- List<Score> GD_Scores = new List<Score>();
- List<int[]> GD_ClassRadius = new List<int[]>();
- // X - (CI-1) / 40 - 44
- for(int x = GD_ScoreStart; x+(GD_ClassInterval-1) < num[0]+GD_ClassInterval; x += GD_ClassInterval) {
- //Console.WriteLine("x - {0}, y - {1}".MelodyFormat(x, x + (GD_ClassInterval-1)));
- GD_ClassRadius.Add(new int[] {x, x+(GD_ClassInterval-1)});
- GD_Scores.Add(new Score() {Radius = new [] {x, x+(GD_ClassInterval-1)}, Frequency = 0});
- }
- GD_ClassRadius.Reverse();
- GD_Scores.Reverse();
- // Frequency
- foreach(int n in num) {
- foreach(int[] r in GD_ClassRadius) {
- if(n >= r[0] && n <= r[1]) {
- int ind = GD_ClassRadius.IndexOf(r);
- GD_Scores[ind].Frequency++;
- break;
- }
- }
- }
- // Comulative Frequency
- int v = 0;
- GD_Scores.Reverse();
- foreach(Score s in GD_Scores) {
- v += s.Frequency;
- s.cf = v;
- // Also set the
- }
- GD_Scores.Reverse();
- //MelodyHelp.ForEach(GD_Scores, x => "{0} - {1} = {2}, {3}".MelodyFormat(x.Radius[0], x.Radius[1], x.Frequency, x.cf).WriteLine());
- Score GD_MedianClass = GD_Scores.Where(x => (num.Length/2) <= x.cf).Reverse().FirstOrDefault();
- "{0} - {1}, {2}".MelodyFormat(GD_MedianClass.Radius[0], GD_MedianClass.Radius[1], GD_MedianClass.cf).WriteLine();
- // Median
- double GD_Median = num.Length/2;
- GD_Median -= GD_Scores[GD_Scores.IndexOf(GD_MedianClass) + 1].cf;
- GD_Median /= GD_MedianClass.Frequency;
- GD_Median *= GD_ClassInterval;
- GD_Median += GD_MedianClass.lb;
- GD_Median = Math.Round(GD_Median, 2); // :)
- Console.WriteLine("Median - " + GD_Median);
- // Mode
- int HighestFrequency = 0;
- foreach(Score s in GD_Scores) {
- if(s.Frequency > HighestFrequency) {
- HighestFrequency = s.Frequency;
- }
- }
- Score GD_ModalClass = null;
- double GD_Mode = 0;
- if(GD_Scores.Where(x => x.Frequency == HighestFrequency).Count() == 1) {
- GD_ModalClass = GD_Scores.Where(x => x.Frequency == HighestFrequency).First();
- //
- Score S_D1 = GD_Scores[GD_Scores.IndexOf(GD_ModalClass) - 1];
- Score S_D2 = GD_Scores[GD_Scores.IndexOf(GD_ModalClass) + 1];
- int D1 = GD_ModalClass.Frequency - S_D1.Frequency;
- int D2 = GD_ModalClass.Frequency - S_D2.Frequency;
- //
- GD_Mode = GD_ModalClass.lb + ( D1 / (D1 + D2) ) * GD_ClassInterval;
- GD_Mode.WriteLine();
- }
- if(GD_ModalClass != null)
- Console.WriteLine("Mode - " + GD_Mode);
- else
- Console.WriteLine("Mode - NONE");
- double GD_Range = (GD_Scores[0].Radius[1] + 0.5) - (GD_Scores[GD_Scores.Count() -1].Radius[0] - 0.5);
- Console.WriteLine("Range - " + GD_Range);
- double GD_Mean = 0;
- foreach(Score s in GD_Scores)
- GD_Mean += s.FX;
- GD_Mean /= num.Length;
- int GD_MeanRounded = (int)Math.Round(GD_Mean);
- Console.WriteLine("Mean - " + Math.Round(GD_Mean, 2));
- double GD_Variance = 0;
- foreach(Score s in GD_Scores) {
- GD_Variance += s.Frequency * Math.Pow((s.ClassMark - GD_Mean),2);
- }
- GD_Variance /= num.Length-1;
- Console.WriteLine("Variance - " + Math.Round(GD_Variance, 2));
- Console.WriteLine("Standard Deviation - " + Math.Round(Math.Sqrt(GD_Variance), 2));
- double h = 0.0;
- foreach(Score s in GD_Scores) {
- h += Math.Round(s.Frequency * Math.Pow((s.ClassMark - GD_MeanRounded),2), 2);
- }
- //h.WriteLine();
- // Now output it in an arranged table
- Console.WriteLine(@"Range | Frequency | Class Mark | f(X) | Lower Boundary | Comulative Frequency | (X-mean) | (X-mean)^2 | f(X-mean)^2");
- foreach(Score s in GD_Scores) {
- string range = s.Radius[0] + "-" + s.Radius[1];
- string fl = range + " | " + s.Frequency + " | " + s.ClassMark + " | " + s.FX + " | " + s.lb + " | " + s.cf;
- double xm = (s.ClassMark - GD_MeanRounded);
- fl += "| {0} | {1} | {2}".MelodyFormat(Math.Round(xm, 2), Math.Round(Math.Pow(xm,2), 2), Math.Round(s.Frequency * Math.Pow(xm,2), 2));
- if(GD_MedianClass.cf == s.cf) {
- fl += " - Median";
- }
- if(GD_ModalClass != null && GD_ModalClass == s) {
- fl += " - Mode";
- }
- fl.WriteLine();
- }
- #endregion
- Thread.Sleep(-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement