Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Analysis-3.3/BonferroniHolmUnitTests.cs @ 13553

Last change on this file since 13553 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Analysis.Tests {
27  [TestClass]
28  public class BonferroniHolmUnitTest {
29    [TestMethod]
30    [TestCategory("Analysis.Statistics")]
31    [TestProperty("Time", "short")]
32    public void BonferroniHolmUnitTest1() {
33      /* example taken from
34       * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons
35       *
36       * p = 0.56, 0.22, 0.001, 0.04, 0.01
37       * a = 0.05
38       * cor_p = 0.560, 0.440, 0.005, 0.120, 0.040
39       * h = 0, 0, 1, 0, 1
40       *
41       */
42
43      double[] correctedPValues = new double[] { 0.56, 0.44, 0.005, 0.12, 0.04 };
44      double[] pVals = new[] { 0.56, 0.22, 0.001, 0.04, 0.01 };
45      bool[] h = new bool[] { false, false, true, false, true };
46      bool[] decision;
47
48      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
49
50      for (int i = 0; i < pVals.Length; i++) {
51        Assert.AreEqual(correctedPValues[i], result[i]);
52        Assert.AreEqual(h[i], decision[i]);
53      }
54    }
55
56    [TestMethod]
57    [TestCategory("Analysis.Statistics")]
58    [TestProperty("Time", "short")]
59    public void BonferroniHolmUnitTest2() {
60      /* example taken from
61       * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example
62       *
63       * p = 0.01, 0.04, 0.03,  0.005
64       * a = 0.05
65       * cor_p = 0.03, 0.06, 0.06, 0.02
66       * h = 1, 0, 0, 1
67       *
68       */
69
70      double[] correctedPValues = new double[] { 0.03, 0.06, 0.06, 0.02 };
71      double[] pVals = new[] { 0.01, 0.04, 0.03, 0.005 };
72      bool[] h = new bool[] { true, false, false, true };
73      bool[] decision;
74
75      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
76
77      for (int i = 0; i < pVals.Length; i++) {
78        Assert.AreEqual(correctedPValues[i], result[i]);
79        Assert.AreEqual(h[i], decision[i]);
80      }
81    }
82
83    [TestMethod]
84    [TestCategory("Analysis.Statistics")]
85    [TestProperty("Time", "short")]
86    public void BonferroniHolmUnitTest3() {
87      // comparison with R's p.adjust(p, "holm") method
88      double[] correctedPValues = new double[] { 0.23262159, 0.05204139 };
89      double[] pVals = new[] { 0.232621592948806, 0.0260206949805373 };
90      bool[] decision;
91
92      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
93
94      for (int i = 0; i < pVals.Length; i++) {
95        Assert.AreEqual(correctedPValues[i], Math.Round(result[i], 8));
96      }
97    }
98
99    [TestMethod]
100    [TestCategory("Analysis.Statistics")]
101    [TestProperty("Time", "short")]
102    public void BonferroniHolmUnitTest4() {
103      // comparison with R's p.adjust(p, "holm") method
104      double[] correctedPValues = new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
105      double[] pVals = new[] { 0.1108139, 0.1241641, 0.2805913, 0.3715633, 0.3967397, 0.6165547, 0.7272018, 0.8774432, 0.9495787, 0.9755199 };
106      bool[] decision;
107
108      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
109
110      for (int i = 0; i < pVals.Length; i++) {
111        Assert.AreEqual(correctedPValues[i], Math.Round(result[i], 8));
112      }
113    }
114
115    [TestMethod]
116    [TestCategory("Analysis.Statistics")]
117    [TestProperty("Time", "short")]
118    public void BonferroniHolmUnitTest5() {
119      // comparison with R's p.adjust(p, "holm") method
120      double[] correctedPValues = new double[] { 1.389563e-05, 7.293675e-05, 2.330999e-04, 2.330999e-04, 4.370736e-04, 5.539326e-04 };
121      double[] pVals = new[] { 2.315938e-06, 1.458735e-05, 5.827497e-05, 7.166659e-05, 2.185368e-04, 5.539326e-04 };
122      bool[] decision;
123
124      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
125
126      for (int i = 0; i < pVals.Length; i++) {
127        Assert.AreEqual(Math.Round(correctedPValues[i], 10), Math.Round(result[i], 10));
128      }
129    }
130  }
131}
132
Note: See TracBrowser for help on using the repository browser.