#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Analysis.Statistics; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Statistics.UnitTests { [TestClass] public class BonferroniHolmUnitTest { [TestMethod] public void TestMethod1() { /* example taken from * http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons * * p = 0.56, 0.22, 0.001, 0.04, 0.01 * a = 0.05 * cor_p = 0.560, 0.440, 0.005, 0.120, 0.040 * h = 0, 0, 1, 0, 1 * */ double[] correctedPValues = new double[] { 0.56, 0.44, 0.005, 0.12, 0.04 }; double[] pVals = new[] { 0.56, 0.22, 0.001, 0.04, 0.01 }; bool[] h = new bool[] { false, false, true, false, true }; bool[] decision; var result = BonferroniHolm.Calculate(0.05, pVals, out decision); for (int i = 0; i < pVals.Length; i++) { Assert.AreEqual(correctedPValues[i], result[i]); Assert.AreEqual(h[i], decision[i]); } } [TestMethod] public void TestMethod2() { /* example taken from * http://en.wikipedia.org/wiki/Holm-Bonferroni_method#Example * * p = 0.01, 0.04, 0.03, 0.005 * a = 0.05 * cor_p = 0.03, 0.06, 0.06, 0.02 * h = 1, 0, 0, 1 * */ double[] correctedPValues = new double[] { 0.03, 0.06, 0.06, 0.02 }; double[] pVals = new[] { 0.01, 0.04, 0.03, 0.005 }; bool[] h = new bool[] { true, false, false, true }; bool[] decision; var result = BonferroniHolm.Calculate(0.05, pVals, out decision); for (int i = 0; i < pVals.Length; i++) { Assert.AreEqual(correctedPValues[i], result[i]); Assert.AreEqual(h[i], decision[i]); } } } }