Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs @ 12406

Last change on this file since 12406 was 12395, checked in by dglaser, 10 years ago

#2388 merged trunk into hive statistics branch

  • Property svn:mergeinfo set to (toggle deleted branches)
    /stable/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.csmergedeligible
    /trunk/sources/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.csmergedeligible
    /branches/CMAES/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs9141-9257
    /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs5815-6180
    /branches/DataPreprocessing/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs10085-11101
    /branches/LogResidualEvaluator/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs10202-10483
    /branches/QAP/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs5666-5932
    /branches/QAPAlgorithms/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs6350-6627
    /branches/Restructure trunk solution/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs6828
    /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs10204-10479
    /branches/Trunk/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs6829-6865
    /branches/histogram/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs5959-6341
File size: 2.5 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 System.Collections.Generic;
24using System.Linq;
25
26namespace HeuristicLab.Analysis.Statistics {
27  public static class BonferroniHolm {
28    /// <summary>
29    /// Based on David Groppe's MATLAB implementation
30    /// (BSD licensed, see
31    /// http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons)
32    /// </summary>
33    public static double[] Calculate(double globalAlpha, double[] pValues, out bool[] h) {
34      int k = pValues.Length;
35      double[] alphaNiveau = new double[k];
36      double[] adjustedPValues = new double[k];
37      bool[] decision = new bool[k];
38      Dictionary<int, double> pValuesIndizes = new Dictionary<int, double>();
39
40      for (int i = 0; i < k; i++) {
41        pValuesIndizes.Add(i, pValues[i]);
42      }
43      var sortedPValues = pValuesIndizes.OrderBy(x => x.Value).ToArray();
44
45      for (int i = 1; i < k + 1; i++) {
46        alphaNiveau[i - 1] = globalAlpha / (k - i + 1);
47        int idx = sortedPValues[i - 1].Key;
48
49        if (i == 1) {
50          //true means reject
51          decision[idx] = sortedPValues[i - 1].Value < alphaNiveau[i - 1];
52          adjustedPValues[idx] = sortedPValues[i - 1].Value * (k - i + 1);
53        } else {
54          decision[idx] = decision[sortedPValues[i - 2].Key] && (sortedPValues[i - 1].Value < alphaNiveau[i - 1]);
55          adjustedPValues[idx] = Math.Max(adjustedPValues[sortedPValues[i - 2].Key], sortedPValues[i - 1].Value * (k - i + 1));
56        }
57        if (adjustedPValues[idx] > 1.0) {
58          adjustedPValues[idx] = 1.0;
59        }
60      }
61
62      h = decision;
63      return adjustedPValues;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.