Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2031 updated unit tests

File size: 2.6 KB
Line
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 HeuristicLab.Analysis.Statistics;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24
25namespace Statistics.UnitTests {
26  [TestClass]
27  public class BonferroniHolmUnitTest {
28    [TestMethod]
29    public void TestMethod1() {
30      /* example taken from
31       * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons
32       *
33       * p = 0.56, 0.22, 0.001, 0.04, 0.01
34       * a = 0.05
35       * cor_p = 0.560, 0.440, 0.005, 0.120, 0.040
36       * h = 0, 0, 1, 0, 1
37       *
38       */
39
40      double[] correctedPValues = new double[] { 0.56, 0.44, 0.005, 0.12, 0.04 };
41      double[] pVals = new[] { 0.56, 0.22, 0.001, 0.04, 0.01 };
42      bool[] h = new bool[] { false, false, true, false, true };
43      bool[] decision;
44
45      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
46
47      for (int i = 0; i < pVals.Length; i++) {
48        Assert.AreEqual(correctedPValues[i], result[i]);
49        Assert.AreEqual(h[i], decision[i]);
50      }
51    }
52
53    [TestMethod]
54    public void TestMethod2() {
55      /* example taken from
56       * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example
57       *
58       * p = 0.01, 0.04, 0.03,  0.005
59       * a = 0.05
60       * cor_p = 0.03, 0.06, 0.06, 0.02
61       * h = 1, 0, 0, 1
62       *
63       */
64
65      double[] correctedPValues = new double[] { 0.03, 0.06, 0.06, 0.02 };
66      double[] pVals = new[] { 0.01, 0.04, 0.03, 0.005 };
67      bool[] h = new bool[] { true, false, false, true };
68      bool[] decision;
69
70      var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
71
72      for (int i = 0; i < pVals.Length; i++) {
73        Assert.AreEqual(correctedPValues[i], result[i]);
74        Assert.AreEqual(h[i], decision[i]);
75      }
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.