bonf_holm.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. % Bonferroni-Holm (1979) correction for multiple comparisons. This is a
  2. % sequentially rejective version of the simple Bonferroni correction for multiple
  3. % comparisons and strongly controls the family-wise error rate at level alpha.
  4. %
  5. % It works as follows:
  6. % 1) All p-values are sorted in order of smallest to largest. m is the
  7. % number p-values.
  8. % 2) If the 1st p-value is greater than or equal to alpha/m, the procedure
  9. % is stopped and no p-values are significant. Otherwise, go on.
  10. % 3) The 1st p-value is declared significant and now the second p-value is
  11. % compared to alpha/(m-1). If the 2nd p-value is greater than or equal
  12. % to alpha/(m-1), the procedure is stopped and no further p-values are
  13. % significant. Otherwise, go on.
  14. % 4) Et cetera.
  15. %
  16. % As stated by Holm (1979) "Except in trivial non-interesting cases the
  17. % sequentially rejective Bonferroni test has strictly larger probability of
  18. % rejecting false hypotheses and thus it ought to replace the classical
  19. % Bonferroni test at all instants where the latter usually is applied."
  20. %
  21. %
  22. % function [corrected_p, h]=bonf_holm(pvalues,alpha)
  23. %
  24. % Required Inputs:
  25. % pvalues - A vector or matrix of p-values. If pvalues is a matrix, it can
  26. % be of any dimensionality (e.g., 2D, 3D, etc...).
  27. %
  28. % Optional Input:
  29. % alpha - The desired family-wise alpha level (i.e., the probability of
  30. % rejecting one of more null hypotheses when all null hypotheses are
  31. % really true). {default: 0.05}
  32. %
  33. % Output:
  34. % corrected_p - Bonferroni-Holm adjusted p-values. Any adjusted p-values
  35. % less than alpha are significant (i.e., that null hypothesis
  36. % is rejected). The adjusted value of the smallest p-value
  37. % is p*m. The ith smallest adjusted p-value is the max of
  38. % p(i)*(m-i+1) or adj_p(i-1). Note, corrected p-values can
  39. % be greater than 1.
  40. % h - A binary vector or matrix of the same dimensionality as
  41. % pvalues. If the ith element of h is 1, then the ith p-value
  42. % of pvalues is significant. If the ith element of h is 0, then
  43. % the ith p-value of pvalues is NOT significant.
  44. %
  45. % Example:
  46. % >>p=[.56 .22 .001 .04 .01]; %five hypothetical p-values
  47. % >>[cor_p, h]=bonf_holm(p,.05)
  48. % cor_p =
  49. % 0.5600 0.4400 0.0050 0.1200 0.0400
  50. % h =
  51. % 0 0 1 0 1
  52. %
  53. % Conclusion: the third and fifth p-values are significant, but not the
  54. % remaining three.
  55. %
  56. % Reference:
  57. % Holm, S. (1979) A simple sequentially rejective multiple test procedure.
  58. % Scandinavian Journal of Statistics. 6, 65-70.
  59. %
  60. %
  61. % For a review on contemporary techniques for correcting for multiple
  62. % comparisons that are often more powerful than Bonferroni-Holm see:
  63. %
  64. % Groppe, D.M., Urbach, T.P., & Kutas, M. (2011) Mass univariate analysis
  65. % of event-related brain potentials/fields I: A critical tutorial review.
  66. % Psychophysiology, 48(12) pp. 1711-1725, DOI: 10.1111/j.1469-8986.2011.01273.x
  67. % http://www.cogsci.ucsd.edu/~dgroppe/PUBLICATIONS/mass_uni_preprint1.pdf
  68. %
  69. %
  70. % Author:
  71. % David M. Groppe
  72. % Kutaslab
  73. % Dept. of Cognitive Science
  74. % University of California, San Diego
  75. % March 24, 2010
  76. function [corrected_p, h]=bonf_holm(pvalues,alpha)
  77. if nargin<1,
  78. error('You need to provide a vector or matrix of p-values.');
  79. else
  80. if ~isempty(find(pvalues<0,1)),
  81. error('Some p-values are less than 0.');
  82. elseif ~isempty(find(pvalues>1,1)),
  83. fprintf('WARNING: Some uncorrected p-values are greater than 1.\n');
  84. end
  85. end
  86. if nargin<2,
  87. alpha=.05;
  88. elseif alpha<=0,
  89. error('Alpha must be greater than 0.');
  90. elseif alpha>=1,
  91. error('Alpha must be less than 1.');
  92. end
  93. s=size(pvalues);
  94. if isvector(pvalues),
  95. if size(pvalues,1)>1,
  96. pvalues=pvalues';
  97. end
  98. [sorted_p sort_ids]=sort(pvalues);
  99. else
  100. [sorted_p sort_ids]=sort(reshape(pvalues,1,prod(s)));
  101. end
  102. [dummy, unsort_ids]=sort(sort_ids); %indices to return sorted_p to pvalues order
  103. m=length(sorted_p); %number of tests
  104. mult_fac=m:-1:1;
  105. cor_p_sorted=sorted_p.*mult_fac;
  106. cor_p_sorted(2:m)=max([cor_p_sorted(1:m-1); cor_p_sorted(2:m)]); %Bonferroni-Holm adjusted p-value
  107. corrected_p=cor_p_sorted(unsort_ids);
  108. corrected_p=reshape(corrected_p,s);
  109. h=corrected_p<alpha;