Changeset 11673


Ignore:
Timestamp:
12/09/14 15:16:31 (8 years ago)
Author:
ascheibe
Message:

#2031 fixed a small bug in Bonferroni-Holm adjustment and added more unit tests for it

Location:
branches/StatisticalTesting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/BonferroniHolm.cs

    r11375 r11673  
    2828    /// <summary>
    2929    /// Based on David Groppe's MATLAB implementation
    30     /// (BSD Licensed, see
     30    /// (BSD licensed, see
    3131    /// http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons)
    3232    /// </summary>
     
    4545      for (int i = 1; i < k + 1; i++) {
    4646        alphaNiveau[i - 1] = globalAlpha / (k - i + 1);
     47        int idx = sortedPValues.ElementAt(i - 1).Key;
    4748
    4849        if (i == 1) {
    4950          //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);
    5253        } 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;
    5559        }
    5660      }
  • branches/StatisticalTesting/Statistics.UnitTests/BonferroniHolmUnitTest.cs

    r11375 r11673  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Analysis.Statistics;
    2324using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    2728  public class BonferroniHolmUnitTest {
    2829    [TestMethod]
    29     public void TestMethod1() {
     30    public void BonferroniHolmUnitTest1() {
    3031      /* example taken from
    3132       * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons
     
    5253
    5354    [TestMethod]
    54     public void TestMethod2() {
     55    public void BonferroniHolmUnitTest2() {
    5556      /* example taken from
    5657       * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example
     
    7576      }
    7677    }
     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    }
    77120  }
    78121}
     122
Note: See TracChangeset for help on using the changeset viewer.