- Timestamp:
- 04/10/09 10:45:35 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StatisticalAnalysis/3.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StatisticalAnalysis/3.2/MannWhitneyWilcoxonTest.cs
r1530 r1548 50 50 /// <returns>The p-value of the test</returns> 51 51 public static double TwoTailedTest(double[] p1, double[] p2) { 52 Array.Sort<double>(p1); 53 Array.Sort<double>(p2); 52 54 double rank = MannWhitneyWilcoxonTest.CalculateRankSumForP1(p1, p2); 53 55 return MannWhitneyWilcoxonTest.ApproximatePValue(rank, p1.Length, p2.Length, true); … … 70 72 /// <returns>True if H0 (p1 equals p2) can be rejected, False otherwise</returns> 71 73 public static bool TwoTailedTest(double[] p1, double[] p2, double alpha) { 74 Array.Sort<double>(p1); 75 Array.Sort<double>(p2); 72 76 return MannWhitneyWilcoxonTest.TwoTailedTest(p1, p2, alpha, 20); 73 77 } … … 120 124 /// <returns>The p-value of the test</returns> 121 125 public static double TwoTailedTest(int[] p1, int[] p2) { 126 Array.Sort<int>(p1); 127 Array.Sort<int>(p2); 122 128 double rank = MannWhitneyWilcoxonTest.CalculateRankSumForP1(p1, p2); 123 129 return MannWhitneyWilcoxonTest.ApproximatePValue(rank, p1.Length, p2.Length, true); … … 181 187 double U1 = rank - (double)(nRank * (nRank + 1) / 2); 182 188 double U2 = (double)(nRank * nOther) - U1; 183 if (alpha < = 0.01) {189 if (alpha < 0.05) { 184 190 return (Math.Min(U1, U2) <= table001[nRank - 1, nOther - 1]); 185 } else if (alpha < = 0.05) {191 } else if (alpha < 0.1) { 186 192 return (Math.Min(U1, U2) <= table005[nRank - 1, nOther - 1]); 187 } else if ( alpha <= 0.1) {193 } else if (Math.Abs(alpha - 0.1) < 1e-07) { 188 194 return (Math.Min(U1, U2) <= table01[nRank - 1, nOther - 1]); 189 195 } else throw new ArgumentException("ERROR in MannWhitneyWilcoxonTest: alpha must be <= 0.1"); … … 197 203 double sigma = Math.Sqrt(nRank * nOther * (nRank + nOther + 1) / 12); 198 204 double z = (Math.Min(U1, U2) - mu) / sigma; 199 return ProbabilityOfZValue(z); 205 if (twoTailed) { 206 return 2 * ProbabilityOfZValue(z); 207 } else return ProbabilityOfZValue(z); 200 208 } 201 209 -
trunk/sources/HeuristicLab.StatisticalAnalysis/3.2/MannWhitneyWilcoxonTestControl.cs
r1530 r1548 48 48 private double[] ConvertStringToArray(TextBox p) { 49 49 string t = p.Text; 50 string[] s = t.Split(new char[] { ';' }); 51 double[] tmp = new double[s.Length]; 52 try { 53 for (int i = 0; i < s.Length; i++) { 54 tmp[i] = double.Parse(s[i]); 50 string[] s = t.Split(new char[] { ';', ' ', '\t' }); 51 List<double> tmp = new List<double>(); 52 for (int i = 0; i < s.Length; i++) { 53 try { 54 double val = double.Parse(s[i]); 55 tmp.Add(val); 55 56 } 57 catch (FormatException) { } 56 58 } 57 catch (FormatException) { 58 return null; 59 } 60 return tmp; 59 if (tmp.Count > 0) return tmp.ToArray(); 60 else return null; 61 61 } 62 62 … … 81 81 double[] p2 = ConvertStringToArray(p2TextBox); 82 82 if (p1.Length > 20 || p2.Length > 20) { 83 MessageBox.Show("Sample size is too large for exact calculation, do not use more than 20 samples in each population."); 84 return; 83 double[] tmp = new double[Math.Min(20, p1.Length)]; 84 for (int i = 0; i < Math.Min(20, p1.Length); i++) tmp[i] = p1[i]; 85 p1 = tmp; 86 tmp = new double[Math.Min(20, p2.Length)]; 87 for (int i = 0; i < Math.Min(20, p2.Length); i++) tmp[i] = p2[i]; 88 p2 = tmp; 89 MessageBox.Show("Caution: Sample size is too large for exact calculation. Only the first 20 samples are used for the test!"); 85 90 } 86 91 double alpha = Double.Parse(alphaTextBox.Text);
Note: See TracChangeset
for help on using the changeset viewer.