[9950] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9950] | 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 |
|
---|
[11673] | 22 | using System;
|
---|
[9950] | 23 | using HeuristicLab.Analysis.Statistics;
|
---|
| 24 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 25 |
|
---|
[11705] | 26 | namespace HeuristicLab.Analysis.Tests {
|
---|
[9950] | 27 | [TestClass]
|
---|
| 28 | public class BonferroniHolmUnitTest {
|
---|
| 29 | [TestMethod]
|
---|
[11938] | 30 | [TestCategory("Analysis.Statistics")]
|
---|
| 31 | [TestProperty("Time", "short")]
|
---|
[11673] | 32 | public void BonferroniHolmUnitTest1() {
|
---|
[9950] | 33 | /* example taken from
|
---|
| 34 | * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons
|
---|
| 35 | *
|
---|
[10017] | 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
|
---|
[9950] | 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]
|
---|
[11938] | 57 | [TestCategory("Analysis.Statistics")]
|
---|
| 58 | [TestProperty("Time", "short")]
|
---|
[11673] | 59 | public void BonferroniHolmUnitTest2() {
|
---|
[9950] | 60 | /* example taken from
|
---|
| 61 | * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example
|
---|
| 62 | *
|
---|
[10017] | 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
|
---|
[9950] | 66 | * h = 1, 0, 0, 1
|
---|
| 67 | *
|
---|
| 68 | */
|
---|
| 69 |
|
---|
[9951] | 70 | double[] correctedPValues = new double[] { 0.03, 0.06, 0.06, 0.02 };
|
---|
[9950] | 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 |
|
---|
[9951] | 75 | var result = BonferroniHolm.Calculate(0.05, pVals, out decision);
|
---|
[9950] | 76 |
|
---|
| 77 | for (int i = 0; i < pVals.Length; i++) {
|
---|
[9951] | 78 | Assert.AreEqual(correctedPValues[i], result[i]);
|
---|
[9950] | 79 | Assert.AreEqual(h[i], decision[i]);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[11673] | 82 |
|
---|
| 83 | [TestMethod]
|
---|
[11938] | 84 | [TestCategory("Analysis.Statistics")]
|
---|
| 85 | [TestProperty("Time", "short")]
|
---|
[11673] | 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]
|
---|
[11938] | 100 | [TestCategory("Analysis.Statistics")]
|
---|
| 101 | [TestProperty("Time", "short")]
|
---|
[11673] | 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]
|
---|
[11938] | 116 | [TestCategory("Analysis.Statistics")]
|
---|
| 117 | [TestProperty("Time", "short")]
|
---|
[11673] | 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 | }
|
---|
[9950] | 130 | }
|
---|
| 131 | }
|
---|
[11673] | 132 |
|
---|