# Changeset 1548

Ignore:
Timestamp:
04/10/09 10:45:35 (12 years ago)
Message:

fixes a bug in MannWhitneyWilcoxonTest, regarding unsorted arrays (#573)
using a 2-tailed test is now properly used under the normal approximation method
some small enhancements to the control

Location:
trunk/sources/HeuristicLab.StatisticalAnalysis/3.2
Files:
2 edited

Unmodified
Added
Removed
• ## trunk/sources/HeuristicLab.StatisticalAnalysis/3.2/MannWhitneyWilcoxonTest.cs

 r1530 /// The p-value of the test public static double TwoTailedTest(double[] p1, double[] p2) { Array.Sort(p1); Array.Sort(p2); double rank = MannWhitneyWilcoxonTest.CalculateRankSumForP1(p1, p2); return MannWhitneyWilcoxonTest.ApproximatePValue(rank, p1.Length, p2.Length, true); /// True if H0 (p1 equals p2) can be rejected, False otherwise public static bool TwoTailedTest(double[] p1, double[] p2, double alpha) { Array.Sort(p1); Array.Sort(p2); return MannWhitneyWilcoxonTest.TwoTailedTest(p1, p2, alpha, 20); } /// The p-value of the test public static double TwoTailedTest(int[] p1, int[] p2) { Array.Sort(p1); Array.Sort(p2); double rank = MannWhitneyWilcoxonTest.CalculateRankSumForP1(p1, p2); return MannWhitneyWilcoxonTest.ApproximatePValue(rank, p1.Length, p2.Length, true); double U1 = rank - (double)(nRank * (nRank + 1) / 2); double U2 = (double)(nRank * nOther) - U1; if (alpha <= 0.01) { if (alpha < 0.05) { return (Math.Min(U1, U2) <= table001[nRank - 1, nOther - 1]); } else if (alpha <= 0.05) { } else if (alpha < 0.1) { return (Math.Min(U1, U2) <= table005[nRank - 1, nOther - 1]); } else if (alpha <= 0.1) { } else if (Math.Abs(alpha - 0.1) < 1e-07) { return (Math.Min(U1, U2) <= table01[nRank - 1, nOther - 1]); } else throw new ArgumentException("ERROR in MannWhitneyWilcoxonTest: alpha must be <= 0.1"); double sigma = Math.Sqrt(nRank * nOther * (nRank + nOther + 1) / 12); double z = (Math.Min(U1, U2) - mu) / sigma; return ProbabilityOfZValue(z); if (twoTailed) { return 2 * ProbabilityOfZValue(z); } else return ProbabilityOfZValue(z); }
• ## trunk/sources/HeuristicLab.StatisticalAnalysis/3.2/MannWhitneyWilcoxonTestControl.cs

 r1530 private double[] ConvertStringToArray(TextBox p) { string t = p.Text; string[] s = t.Split(new char[] { ';' }); double[] tmp = new double[s.Length]; try { for (int i = 0; i < s.Length; i++) { tmp[i] = double.Parse(s[i]); string[] s = t.Split(new char[] { ';', ' ', '\t' }); List tmp = new List(); for (int i = 0; i < s.Length; i++) { try { double val = double.Parse(s[i]); tmp.Add(val); } catch (FormatException) { } } catch (FormatException) { return null; } return tmp; if (tmp.Count > 0) return tmp.ToArray(); else return null; } double[] p2 = ConvertStringToArray(p2TextBox); if (p1.Length > 20 || p2.Length > 20) { MessageBox.Show("Sample size is too large for exact calculation, do not use more than 20 samples in each population."); return; double[] tmp = new double[Math.Min(20, p1.Length)]; for (int i = 0; i < Math.Min(20, p1.Length); i++) tmp[i] = p1[i]; p1 = tmp; tmp = new double[Math.Min(20, p2.Length)]; for (int i = 0; i < Math.Min(20, p2.Length); i++) tmp[i] = p2[i]; p2 = tmp; MessageBox.Show("Caution: Sample size is too large for exact calculation. Only the first 20 samples are used for the test!"); } double alpha = Double.Parse(alphaTextBox.Text);
Note: See TracChangeset for help on using the changeset viewer.