Holm–Bonferroni method
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share
项目合作:QQ231469242
# -*- coding: utf-8 -*- # Import standard packages
import numpy as np
from scipy import stats
import pandas as pd
import os # Other required packages
from statsmodels.stats.multicomp import (pairwise_tukeyhsd,
MultiComparison)
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm #数据excel名
excel="sample.xlsx"
#读取数据
df=pd.read_excel(excel)
#获取第一组数据,结构为列表
group_mental=list(df.StressReduction[(df.Treatment=="mental")])
group_physical=list(df.StressReduction[(df.Treatment=="physical")])
group_medical=list(df.StressReduction[(df.Treatment=="medical")]) multiComp = MultiComparison(df['StressReduction'], df['Treatment']) def Holm_Bonferroni(multiComp):
''' Instead of the Tukey's test, we can do pairwise t-test
通过均分a=0.05,矫正a,得到更小a''' # First, with the "Holm" correction
rtp = multiComp.allpairtest(stats.ttest_rel, method='Holm')
print((rtp[0])) # and then with the Bonferroni correction
print((multiComp.allpairtest(stats.ttest_rel, method='b')[0])) # Any value, for testing the program for correct execution
checkVal = rtp[1][0][0,0]
return checkVal Holm_Bonferroni(multiComp)
数据sample.xlsx


因为反复比较,一型错误概率会增加。
bonferroni 矫正一型错误的公式,它减少了a=0.05关键值
例如有5组数比较,比较的配对结果有10个
所以矫正的a=0.05/10=0.005










https://en.wikipedia.org/wiki/Holm%E2%80%93Bonferroni_method
In statistics, the Holm–Bonferroni method[1] (also called the Holm method or Bonferroni-Holm method) is used to counteract the problem of multiple comparisons. It is intended to control the familywise error rate and offers a simple test uniformly more powerful than the Bonferroni correction. It is one of the earliest usages of stepwise algorithms in simultaneous inference. It is named after Sture Holm, who codified the method, and Carlo Emilio Bonferroni.
Contents
Motivation
When considering several hypotheses, the problem of multiplicity arises: the more hypotheses we check, the higher the probability of a Type I error (false positive). The Holm–Bonferroni method is one of many approaches that control the family-wise error rate (the probability that one or more Type I errors will occur) by adjusting the rejection criteria of each of the individual hypotheses or comparisons.
Formulation
The method is as follows:
- Let H 1 , . . . , H m {\displaystyle H_{1},...,H_{m}}
be a family of hypotheses and P 1 , . . . , P m {\displaystyle P_{1},...,P_{m}}
the corresponding P-values.
- Start by ordering the p-values (from lowest to highest) P ( 1 ) … P ( m ) {\displaystyle P_{(1)}\ldots P_{(m)}}
and let the associated hypotheses be H ( 1 ) … H ( m ) {\displaystyle H_{(1)}\ldots H_{(m)}}
- For a given significance level α {\displaystyle \alpha }
, let k {\displaystyle k}
be the minimal index such that P ( k ) > α m + 1 − k {\displaystyle P_{(k)}>{\frac {\alpha }{m+1-k}}}
- Reject the null hypotheses H ( 1 ) … H ( k − 1 ) {\displaystyle H_{(1)}\ldots H_{(k-1)}}
and do not reject H ( k ) … H ( m ) {\displaystyle H_{(k)}\ldots H_{(m)}}
- If k = 1 {\displaystyle k=1}
then do not reject any of the null hypotheses and if no such k {\displaystyle k}
exist then reject all of the null hypotheses.
The Holm–Bonferroni method ensures that this method will control the F W E R ≤ α {\displaystyle FWER\leq \alpha } , where F W E R {\displaystyle FWER}
is the familywise error rate
Proof
Holm-Bonferroni controls the FWER as follows. Let H ( 1 ) … H ( m ) {\displaystyle H_{(1)}\ldots H_{(m)}} be a family of hypotheses, and P ( 1 ) ≤ P ( 2 ) ≤ … ≤ P ( m ) {\displaystyle P_{(1)}\leq P_{(2)}\leq \ldots \leq P_{(m)}}
be the sorted p-values. Let I 0 {\displaystyle I_{0}}
be the set of indices corresponding to the (unknown) true null hypotheses, having m 0 {\displaystyle m_{0}}
members.
Let us assume that we wrongly reject a true hypothesis. We have to prove that the probability of this event is at most α {\displaystyle \alpha } . Let h {\displaystyle h}
be the first rejected true hypothesis (first in the ordering given by the Bonferroni–Holm test). So h − 1 {\displaystyle h-1}
is the last false hypothesis rejected and h − 1 + m 0 ≤ m {\displaystyle h-1+m_{0}\leq m}
. From there, we get 1 m − h + 1 ≤ 1 m 0 {\displaystyle {\frac {1}{m-h+1}}\leq {\frac {1}{m_{0}}}}
(1). Since h {\displaystyle h}
is rejected we have P ( h ) ≤ α m + 1 − h {\displaystyle P_{(h)}\leq {\frac {\alpha }{m+1-h}}}
by definition of the test. Using (1), the right hand side is at most α m 0 {\displaystyle {\frac {\alpha }{m_{0}}}}
. Thus, if we wrongly reject a true hypothesis, there has to be a true hypothesis with P-value at most α m 0 {\displaystyle {\frac {\alpha }{m_{0}}}}
.
So let us define A = { P i ≤ α m 0 for some i ∈ I 0 } {\displaystyle A=\left\{P_{i}\leq {\frac {\alpha }{m_{0}}}{\text{ for some }}i\in I_{0}\right\}} . Whatever the (unknown) set of true hypotheses I 0 {\displaystyle I_{0}}
is, we have Pr ( A ) ≤ α {\displaystyle \Pr(A)\leq \alpha }
(by the Bonferroni inequalities). Therefore, the probability to reject a true hypothesis is at most α {\displaystyle \alpha }
.
Alternative proof
The Holm–Bonferroni method can be viewed as closed testing procedure,[2] with Bonferroni method applied locally on each of the intersections of null hypotheses. As such, it controls the familywise error rate for all the k hypotheses at level α in the strong sense. Each intersection is tested using the simple Bonferroni test.
It is a shortcut procedure since practically the number of comparisons to be made equal to m {\displaystyle m} or less, while the number of all intersections of null hypotheses to be tested is of order 2 m {\displaystyle 2^{m}}
.
The closure principle states that a hypothesis H i {\displaystyle H_{i}} in a family of hypotheses H 1 , . . . , H m {\displaystyle H_{1},...,H_{m}}
is rejected - while controlling the family-wise error rate of α {\displaystyle \alpha }
- if and only if all the sub-families of the intersections with H i {\displaystyle H_{i}}
are controlled at level of family-wise error rate of α {\displaystyle \alpha }
.
In Holm-Bonferroni procedure, we first test H ( 1 ) {\displaystyle H_{(1)}} . If it is not rejected then the intersection of all null hypotheses ⋂ i = 1 m H i {\displaystyle \bigcap \nolimits _{i=1}^{m}{H_{i}}}
is not rejected too, such that there exist at least one intersection hypothesis for each of elementary hypotheses H 1 , . . . , H m {\displaystyle H_{1},...,H_{m}}
that is not rejected, thus we reject none of the elementary hypotheses.
If H ( 1 ) {\displaystyle H_{(1)}} is rejected at level α / m {\displaystyle \alpha /m}
then all the intersection sub-families that contain it are rejected too, thus H ( 1 ) {\displaystyle H_{(1)}}
is rejected. This is because P ( 1 ) {\displaystyle P_{(1)}}
is the smallest in each one of the intersection sub-families and the size of the sub-families is the most m {\displaystyle m}
, such that the Bonferroni threshold larger than α / m {\displaystyle \alpha /m}
.
The same rationale applies for H ( 2 ) {\displaystyle H_{(2)}} . However, since H ( 1 ) {\displaystyle H_{(1)}}
already rejected, it sufficient to reject all the intersection sub-families of H ( 2 ) {\displaystyle H_{(2)}}
without H ( 1 ) {\displaystyle H_{(1)}}
. Once P ( 2 ) ≤ α / ( m − 1 ) {\displaystyle P_{(2)}\leq \alpha /(m-1)}
holds all the intersections that contains H ( 2 ) {\displaystyle H_{(2)}}
are rejected.
The same applies for each 1 ≤ i ≤ m {\displaystyle 1\leq i\leq m} .
Example
Consider four null hypotheses H 1 , . . . , H 4 {\displaystyle H_{1},...,H_{4}} with unadjusted p-values p 1 = 0.01 {\displaystyle p_{1}=0.01}
, p 2 = 0.04 {\displaystyle p_{2}=0.04}
, p 3 = 0.03 {\displaystyle p_{3}=0.03}
and p 4 = 0.005 {\displaystyle p_{4}=0.005}
, to be tested at significance level α = 0.05 {\displaystyle \alpha =0.05}
. Since the procedure is step-down, we first test H 4 = H ( 1 ) {\displaystyle H_{4}=H_{(1)}}
, which has the smallest p-value p 4 = p ( 1 ) = 0.005 {\displaystyle p_{4}=p_{(1)}=0.005}
. The p-value is compared to α / 4 = 0.0125 {\displaystyle \alpha /4=0.0125}
, the null hypothesis is rejected and we continue to the next one. Since p 1 = p ( 2 ) = 0.01 < 0.0167 = α / 3 {\displaystyle p_{1}=p_{(2)}=0.01<0.0167=\alpha /3}
we reject H 1 = H ( 2 ) {\displaystyle H_{1}=H_{(2)}}
as well and continue. The next hypothesis H 3 {\displaystyle H_{3}}
is not rejected since p 3 = p ( 3 ) = 0.03 > 0.025 = α / 2 {\displaystyle p_{3}=p_{(3)}=0.03>0.025=\alpha /2}
. We stop testing and conclude that H 1 {\displaystyle H_{1}}
and H 4 {\displaystyle H_{4}}
are rejected and H 2 {\displaystyle H_{2}}
and H 3 {\displaystyle H_{3}}
are not rejected while controlling the familywise error rate at level α = 0.05 {\displaystyle \alpha =0.05}
. Note that even though p 2 = p ( 4 ) = 0.04 < 0.05 = α {\displaystyle p_{2}=p_{(4)}=0.04<0.05=\alpha }
applies, H 2 {\displaystyle H_{2}}
is not rejected. This is because the testing procedure stops once a failure to reject occurs.
Extensions
Holm–Šidák method
When the hypothesis tests are not negatively dependent, it is possible to replace α m , α m − 1 , . . . , α 1 {\displaystyle {\frac {\alpha }{m}},{\frac {\alpha }{m-1}},...,{\frac {\alpha }{1}}} with:
- 1 − ( 1 − α ) 1 / m , 1 − ( 1 − α ) 1 / ( m − 1 ) , . . . , 1 − ( 1 − α ) 1 {\displaystyle 1-(1-\alpha )^{1/m},1-(1-\alpha )^{1/(m-1)},...,1-(1-\alpha )^{1}}
resulting in a slightly more powerful test.
Weighted version
Let P ( 1 ) , . . . , P ( m ) {\displaystyle P_{(1)},...,P_{(m)}} be the ordered unadjusted p-values. Let H ( i ) {\displaystyle H_{(i)}}
, 0 ≤ w ( i ) {\displaystyle 0\leq w_{(i)}}
correspond to P ( i ) {\displaystyle P_{(i)}}
. Reject H ( i ) {\displaystyle H_{(i)}}
as long as
- P ( j ) ≤ w ( j ) ∑ k = j m w ( k ) α , j = 1 , . . . , i {\displaystyle P_{(j)}\leq {\frac {w_{(j)}}{\sum _{k=j}^{m}{w_{(k)}}}}\alpha ,\quad j=1,...,i}
Adjusted p-values
The adjusted p-values for Holm–Bonferroni method are:
- p ~ ( i ) = max j ≤ i { ( m − j + 1 ) p ( j ) } 1 {\displaystyle {\widetilde {p}}_{(i)}=\max _{j\leq i}\left\{(m-j+1)p_{(j)}\right\}_{1}}
, where { x } 1 ≡ min ( x , 1 ) {\displaystyle \{x\}_{1}\equiv \min(x,1)}
.
In the earlier example, the adjusted p-values are p ~ 1 = 0.03 {\displaystyle {\widetilde {p}}_{1}=0.03} , p ~ 2 = 0.06 {\displaystyle {\widetilde {p}}_{2}=0.06}
, p ~ 3 = 0.06 {\displaystyle {\widetilde {p}}_{3}=0.06}
and p ~ 4 = 0.02 {\displaystyle {\widetilde {p}}_{4}=0.02}
. Only hypotheses H 1 {\displaystyle H_{1}}
and H 4 {\displaystyle H_{4}}
are rejected at level α = 0.05 {\displaystyle \alpha =0.05}
.
The weighted adjusted p-values are:[citation needed]
- p ~ ( i ) = max j ≤ i { ∑ k = j m w ( k ) w ( j ) p ( j ) } 1 {\displaystyle {\widetilde {p}}_{(i)}=\max _{j\leq i}\left\{{\frac {\sum _{k=j}^{m}{w_{(k)}}}{w_{(j)}}}p_{(j)}\right\}_{1}}
, where { x } 1 ≡ min ( x , 1 ) {\displaystyle \{x\}_{1}\equiv \min(x,1)}
.
A hypothesis is rejected at level α if and only if its adjusted p-value is less than α. In the earlier example using equal weights, the adjusted p-values are 0.03, 0.06, 0.06, and 0.02. This is another way to see that using α = 0.05, only hypotheses one and four are rejected by this procedure.
Alternatives and usage
The Holm–Bonferroni method is uniformly more powerful than the classic Bonferroni correction. There are other methods for controlling the family-wise error rate that are more powerful than Holm-Bonferroni.
In the Hochberg procedure, rejection of H ( 1 ) … H ( k ) {\displaystyle H_{(1)}\ldots H_{(k)}} is made after finding the maximal index k {\displaystyle k}
such that P ( k ) ≤ α m + 1 − k {\displaystyle P_{(k)}\leq {\frac {\alpha }{m+1-k}}}
. Thus, The Hochberg procedure is more powerful by construction. However, the Hochberg procedure requires the hypotheses to be independent or under certain forms of positive dependence, whereas Holm-Bonferroni can be applied without such assumptions.
A similar step-up procedure is the Hommel procedure.[3]
Naming
Carlo Emilio Bonferroni did not take part in inventing the method described here. Holm originally called the method the "sequentially rejective Bonferroni test", and it became known as Holm-Bonferroni only after some time. Holm's motives for naming his method after Bonferroni are explained in the original paper: "The use of the Boole inequality within multiple inference theory is usually called the Bonferroni technique, and for this reason we will call our test the sequentially rejective Bonferroni test."
Bonferroni校正:如果在同一数据集上同时检验n个独立的假设,那么用于每一假设的统计显著水平,应为仅检验一个假设时的显著水平的1/n。
简介
维基百科原文
参考文献
- 参考资料
https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章)

Holm–Bonferroni method的更多相关文章
- SAGE|DNA微阵列|RNA-seq|lncRNA|scripture|tophat|cufflinks|NONCODE|MA|LOWESS|qualitile归一化|permutation test|SAM|FDR|The Bonferroni|Tukey's|BH|FWER|Holm's step-down|q-value|
生物信息学-基因表达分析 为了丰富中心法则,研究人员使用不断更新的技术研究lncRNA的方方面面,其中技术主要是生物学上的微阵列芯片技术和表达数据分析方法,方方面面是指lncRNA的位置特征. Bac ...
- jsp中出现onclick函数提示Cannot return from outside a function or method
在使用Myeclipse10部署完项目后,原先不出错的项目,会有红色的叉叉,JSP页面会提示onclick函数错误 Cannot return from outside a function or m ...
- Apply Newton Method to Find Extrema in OPEN CASCADE
Apply Newton Method to Find Extrema in OPEN CASCADE eryar@163.com Abstract. In calculus, Newton’s me ...
- 设计模式(九): 从醋溜土豆丝和清炒苦瓜中来学习"模板方法模式"(Template Method Pattern)
今天是五.四青年节,祝大家节日快乐.看着今天这标题就有食欲,夏天到了,醋溜土豆丝和清炒苦瓜适合夏天吃,好吃不上火.这两道菜大部分人都应该吃过,特别是醋溜土豆丝,作为“鲁菜”的代表作之一更是为大众所熟知 ...
- HTTP Method详细解读(`GET` `HEAD` `POST` `OPTIONS` `PUT` `DELETE` `TRACE` `CONNECT`)
前言 HTTP Method的历史: HTTP 0.9 这个版本只有GET方法 HTTP 1.0 这个版本有GET HEAD POST这三个方法 HTTP 1.1 这个版本是当前版本,包含GET HE ...
- IIS7.5上的REST服务的Put,Delete操作发生HTTP Error 405.0 - Method Not Allowed 解决方法
WebDAV 是超文本传输协议 (HTTP) 的一组扩展,为 Internet 上计算机之间的编辑和文件管理提供了标准.利用这个协议用户可以通过Web进行远程的基本文件操作,如拷贝.移动.删除等.在I ...
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory 这是由于项目里面的一些 ...
- Spring boot: Request method 'DELETE' not supported, Request method 'PUT' not supported, Request method 'POST' not supported
GET,POST,PUT,DELETE, Spring都支持,不要怀疑Spring, 一定是前端发送的rest 请求和后端的响应不匹配, 查找原因以及解决办法, 很简单 用chrome打开F12控制台 ...
- 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method
异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...
随机推荐
- 一个简单的rest_framework demo
models.py from django.db import models class UserInfo(models.Model): username = models.CharField(max ...
- 在html中怎么格式化输出json字符串
#今天的项目用到,看俊哥找到,特此记录下来 步骤: 1.在html页面中输入下面的标签,必须是在pre标签内输出格式才会生效: <pre id="songReqJson"&g ...
- lintcode-512-解码方法
512-解码方法 有一个消息包含A-Z通过以下规则编码 'A' -> 1 'B' -> 2 ... 'Z' -> 26 现在给你一个加密过后的消息,问有几种解码的方式 样例 给你的消 ...
- 第5题 查找字符串中的最长回文字符串---Manacher算法
转载:https://www.felix021.com/blog/read.php?2040 首先用一个非常巧妙的方式,将所有可能的奇数/偶数长度的回文子串都转换成了奇数长度:在每个字符的两边都插入一 ...
- bash循环语句
1 )单分支if语句 if 测试条件 :then 如果满足条件就执行这里的代码 f 2)双分支的if语句 if 测试条件:then 如果满足条件就执行这里的代码 else 如果不满足条件就执行这里 ...
- 将java开发的wordcount程序提交到spark集群上运行
今天来分享下将java开发的wordcount程序提交到spark集群上运行的步骤. 第一个步骤之前,先上传文本文件,spark.txt,然用命令hadoop fs -put spark.txt /s ...
- jar读取外部和内部配置文件的问题
最近修改XX应用的时候,涉及到需要在jar包中读取工程配置文件的问题.在jar包中,读取配置文件,需要单独处理. 项目中的一些配置文件,如dbconfig.properties log4j.xml 不 ...
- 第155天:canvas(二)
一.添加样式和颜色 在前面的绘制矩形章节中,只用到了默认的线条和颜色. 如果想要给图形上色,有两个重要的属性可以做到. fillStyle = color 设置图形的填充颜色 strokeSt ...
- 第154天:canvas基础(一)
一.canvas简介 <canvas> 是 HTML5 新增的,一个可以使用脚本(通常为JavaScript)在其中绘制图像的 HTML 元素.它可以用来制作照片集或者制作简单(也不是 ...
- python打印各种三角形
# 打印左下角三角形:for i in range(10):之后,range(0,i)# 打印右上角三角形:在左下角的基础上,将"-"变成" "空格 for i ...
