00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004
00005 namespace StephenAshley.Biostatistics
00006 {
00007 using NUMBER = Decimal;
00008
00012 public struct Rank
00013 {
00021 public Rank(Int32 iGrp, NUMBER decA, NUMBER decRnk)
00022 {
00023 iGroup = iGrp;
00024 decValue = decA;
00025 decRank = decRnk;
00026 }
00027
00032 public Int32 iGroup;
00033
00037 public NUMBER decValue;
00038
00042 public NUMBER decRank;
00043
00051 public static Int32 AdjustTies(ref List<Rank> lstRanks)
00052 {
00053 Int32 iTieAdjustment = 0;
00054
00055 List<NUMBER> lstUniqueNumbers = new List<NUMBER>();
00056 foreach (Rank rank in lstRanks)
00057 if (!(lstUniqueNumbers.Contains(rank.decValue)))
00058 lstUniqueNumbers.Add(rank.decValue);
00059
00060
00061 foreach (NUMBER decUniqueNumber in lstUniqueNumbers)
00062 {
00063 Int32 iTau = 0;
00064 NUMBER decSum = 0;
00065 foreach (Rank rank in lstRanks)
00066 if (rank.decValue == decUniqueNumber)
00067
00068 {
00069 iTau++;
00070 decSum += rank.decRank;
00071 }
00072 if (iTau > 1)
00073
00074 {
00075 for (int i = 0; i < lstRanks.Count(); i++)
00076 {
00077
00078 if (lstRanks[i].decValue == decUniqueNumber)
00079 lstRanks[i] = new Rank(
00080 lstRanks[i].iGroup,
00081 lstRanks[i].decValue,
00082 decSum / iTau);
00083
00084 }
00085 iTieAdjustment += (iTau - 1) * iTau * (iTau + 1);
00086 }
00087 }
00088 return iTieAdjustment;
00089 }
00090
00100 public static int CompareRanks(Rank x, Rank y)
00101 {
00102 return (x.decValue).CompareTo(y.decValue);
00103 }
00104
00115 public static int CompareRanksByAbsoluteValues(Rank x, Rank y)
00116 {
00117 NUMBER decX = DecMath.Abs(x.decValue);
00118 NUMBER decY = DecMath.Abs(y.decValue);
00119 return decX.CompareTo(decY);
00120 }
00121 }
00122 }