#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 System;
using System.Collections.Generic;
using System.Linq;
namespace HeuristicLab.Analysis.Statistics {
public static class BonferroniHolm {
///
/// Based on David Groppe's MATLAB implementation
/// (BSD Licensed, see
/// http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons)
///
public static double[] Calculate(double globalAlpha, double[] pValues, out bool[] h) {
int k = pValues.Length;
double[] alphaNiveau = new double[k];
double[] adjustedPValues = new double[k];
bool[] decision = new bool[k];
Dictionary pValuesIndizes = new Dictionary();
for (int i = 0; i < k; i++) {
pValuesIndizes.Add(i, pValues[i]);
}
var sortedPValues = pValuesIndizes.OrderBy(x => x.Value);
for (int i = 1; i < k + 1; i++) {
alphaNiveau[i - 1] = globalAlpha / (k - i + 1);
if (i == 1) {
//true means reject
decision[sortedPValues.ElementAt(i - 1).Key] = sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1];
adjustedPValues[sortedPValues.ElementAt(i - 1).Key] = sortedPValues.ElementAt(i - 1).Value * (k - i + 1);
} else {
decision[sortedPValues.ElementAt(i - 1).Key] = decision[sortedPValues.ElementAt(i - 2).Key] ? (sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1]) : false;
adjustedPValues[sortedPValues.ElementAt(i - 1).Key] = Math.Max(adjustedPValues[sortedPValues.ElementAt(i - 2).Key], sortedPValues.ElementAt(i - 1).Value * (k - i + 1));
}
}
h = decision;
return adjustedPValues;
}
}
}