Free cookie consent management tool by TermsFeed Policy Generator

source: branches/StatisticalTesting/Statistics.UnitTests/BonferroniHolmUnitTest.cs @ 11673

Last change on this file since 11673 was 11673, checked in by ascheibe, 9 years ago

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

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Analysis.Statistics;
24using Microsoft.VisualStudio.TestTools.UnitTesting;
25
26namespace Statistics.UnitTests {
27  [TestClass]
28  public class BonferroniHolmUnitTest {
29    [TestMethod]
30    public void BonferroniHolmUnitTest1() {
31      /* example taken from
32       * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons
33       *
34       * p = 0.56, 0.22, 0.001, 0.04, 0.01
35       * a = 0.05
36       * cor_p = 0.560, 0.440, 0.005, 0.120, 0.040
37       * h = 0, 0, 1, 0, 1
38       *
39       */
40
41      double[] correctedPValues = new double[] { 0.56, 0.44, 0.005, 0.12, 0.04 };
42      double[] pVals = new[] { 0.56, 0.22, 0.001, 0.04, 0.01 };
43      bool[] h = new bool[] { false, false, true, false, true };
44      bool[] decision;
45
46      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
47
48      for (int i = 0; i < pVals.Length; i++) {
49        Assert.AreEqual(correctedPValues[i], result[i]);
50        Assert.AreEqual(h[i], decision[i]);
51      }
52    }
53
54    [TestMethod]
55    public void BonferroniHolmUnitTest2() {
56      /* example taken from
57       * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example
58       *
59       * p = 0.01, 0.04, 0.03,  0.005
60       * a = 0.05
61       * cor_p = 0.03, 0.06, 0.06, 0.02
62       * h = 1, 0, 0, 1
63       *
64       */
65
66      double[] correctedPValues = new double[] { 0.03, 0.06, 0.06, 0.02 };
67      double[] pVals = new[] { 0.01, 0.04, 0.03, 0.005 };
68      bool[] h = new bool[] { true, false, false, true };
69      bool[] decision;
70
71      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
72
73      for (int i = 0; i < pVals.Length; i++) {
74        Assert.AreEqual(correctedPValues[i], result[i]);
75        Assert.AreEqual(h[i], decision[i]);
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    }
120  }
121}
122
Note: See TracBrowser for help on using the repository browser.