Changeset 11673
- Timestamp:
- 12/09/14 15:16:31 (10 years ago)
- Location:
- branches/StatisticalTesting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/BonferroniHolm.cs
r11375 r11673 28 28 /// <summary> 29 29 /// Based on David Groppe's MATLAB implementation 30 /// (BSD Licensed, see30 /// (BSD licensed, see 31 31 /// http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons) 32 32 /// </summary> … … 45 45 for (int i = 1; i < k + 1; i++) { 46 46 alphaNiveau[i - 1] = globalAlpha / (k - i + 1); 47 int idx = sortedPValues.ElementAt(i - 1).Key; 47 48 48 49 if (i == 1) { 49 50 //true means reject 50 decision[ sortedPValues.ElementAt(i - 1).Key] = sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1];51 adjustedPValues[ sortedPValues.ElementAt(i - 1).Key] = sortedPValues.ElementAt(i - 1).Value * (k - i + 1);51 decision[idx] = sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1]; 52 adjustedPValues[idx] = sortedPValues.ElementAt(i - 1).Value * (k - i + 1); 52 53 } else { 53 decision[sortedPValues.ElementAt(i - 1).Key] = decision[sortedPValues.ElementAt(i - 2).Key] ? (sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1]) : false; 54 adjustedPValues[sortedPValues.ElementAt(i - 1).Key] = Math.Max(adjustedPValues[sortedPValues.ElementAt(i - 2).Key], sortedPValues.ElementAt(i - 1).Value * (k - i + 1)); 54 decision[idx] = decision[sortedPValues.ElementAt(i - 2).Key] ? (sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1]) : false; 55 adjustedPValues[idx] = Math.Max(adjustedPValues[sortedPValues.ElementAt(i - 2).Key], sortedPValues.ElementAt(i - 1).Value * (k - i + 1)); 56 } 57 if (adjustedPValues[idx] > 1.0) { 58 adjustedPValues[idx] = 1.0; 55 59 } 56 60 } -
branches/StatisticalTesting/Statistics.UnitTests/BonferroniHolmUnitTest.cs
r11375 r11673 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Analysis.Statistics; 23 24 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 27 28 public class BonferroniHolmUnitTest { 28 29 [TestMethod] 29 public void TestMethod1() {30 public void BonferroniHolmUnitTest1() { 30 31 /* example taken from 31 32 * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons … … 52 53 53 54 [TestMethod] 54 public void TestMethod2() {55 public void BonferroniHolmUnitTest2() { 55 56 /* example taken from 56 57 * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example … … 75 76 } 76 77 } 78 79 [TestMethod] 80 public void BonferroniHolmUnitTest3() { 81 // comparison with R's p.adjust(p, "holm") method 82 double[] correctedPValues = new double[] { 0.23262159, 0.05204139 }; 83 double[] pVals = new[] { 0.232621592948806, 0.0260206949805373 }; 84 bool[] decision; 85 86 var result = BonferroniHolm.Calculate(0.05, pVals, out decision); 87 88 for (int i = 0; i < pVals.Length; i++) { 89 Assert.AreEqual(correctedPValues[i], Math.Round(result[i], 8)); 90 } 91 } 92 93 [TestMethod] 94 public void BonferroniHolmUnitTest4() { 95 // comparison with R's p.adjust(p, "holm") method 96 double[] correctedPValues = new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; 97 double[] pVals = new[] { 0.1108139, 0.1241641, 0.2805913, 0.3715633, 0.3967397, 0.6165547, 0.7272018, 0.8774432, 0.9495787, 0.9755199 }; 98 bool[] decision; 99 100 var result = BonferroniHolm.Calculate(0.05, pVals, out decision); 101 102 for (int i = 0; i < pVals.Length; i++) { 103 Assert.AreEqual(correctedPValues[i], Math.Round(result[i], 8)); 104 } 105 } 106 107 [TestMethod] 108 public void BonferroniHolmUnitTest5() { 109 // comparison with R's p.adjust(p, "holm") method 110 double[] correctedPValues = new double[] { 1.389563e-05, 7.293675e-05, 2.330999e-04, 2.330999e-04, 4.370736e-04, 5.539326e-04 }; 111 double[] pVals = new[] { 2.315938e-06, 1.458735e-05, 5.827497e-05, 7.166659e-05, 2.185368e-04, 5.539326e-04 }; 112 bool[] decision; 113 114 var result = BonferroniHolm.Calculate(0.05, pVals, out decision); 115 116 for (int i = 0; i < pVals.Length; i++) { 117 Assert.AreEqual(Math.Round(correctedPValues[i], 10), Math.Round(result[i], 10)); 118 } 119 } 77 120 } 78 121 } 122
Note: See TracChangeset
for help on using the changeset viewer.