数码资讯
[PROC FREQ] 单组率置信区间的计算
本文链接:https://www.cnblogs.com/snoopy1866/p/15674999.html
利用PROC FREQ过程中的binomial语句可以很方便地计算单组率置信区间,SAS提供了9种(不包括校正法)计算单组率置信区间的方法,现列举如下:
首先准备示例数据:
data test; input out $ weight;cards;阳性 95阴性 5;run;
1. Wald 法
基于Wald法构建的单组率的置信区间应用非常广泛,且Wald在结构上有着以点估计为中心对称分布的天然优势,基于Wald法构建的单样本率置信区间可表示为:
优点:以点估计为中心,对称分布
缺点:(1)Overshoot: 置信区间可能超过[0,1]范围(2)Degeneracy: 区间宽度可能为0(p=0或1时)(3)覆盖率差
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = wald); weight weight;run;
2. Wald 法(连续性校正)
优点:(1)可避免区间宽度可能为0的情况(2)覆盖率较Wald法有所改善
缺点:(1)结果偏保守(2)更容易发生置信区间超过[0,1]范围的情况
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = wald(correct)); weight weight;run;
3. Agresti-Coull
Agresti-Coull法的主要思路是选择一个大于0的常数作为pseudo-frequency,在计算样本量的时候对点估计进行校正,目的是使点估计尽量向中央(0.5)靠拢,这个大于零0的常数被称为估计因子
Agresti和Coull提出了
当
其中
优点:(1)downward spikes现象略有改善(downward spikes:当率在极端情况下,置信区间覆盖率急剧下滑)
缺点:(1)牺牲了置信区间宽度
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = agresticoull); weight weight;run;
4. Wilson Score法
Wilson Score法作为Wald法的替代,应用十分广泛,是目前学界公认的在非极端率情况下的最佳置信区间构建方法。
基于Wilson Score法构建的置信区间可表示为:
优点:(1)被认为是moderate proportion(率不接近0或1)的最佳方法
缺点:(1)存在downward spikes现象
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = wilson); weight weight;run;
5. Wilson Score法(连续性校正)
基于Wilson Score法连续性校正构建的置信区间可表示为:
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = wilson(correct)); weight weight;run;
6. Jeffreys法
Jeffreys法构建的置信区间表示如下:
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = jeffreys); weight weight;run;
7. 似然比法
似然比法通过逆推似然比检验构造置信区间,零假设下似然比检验统计量可表示为:
使检验统计量
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = likelihoodratio); weight weight;run;
8. Logit法
基于Logit变换
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = likelihoodratio); weight weight;run;
9. Clopper-Pearson法
基于二项分布构建的置信区间方法,使得精确置信限满足以下方程:
PROC FREQ 使用
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = likelihoodratio); weight weight;run;
10. Mid-P法
Mid-P 精确置信限满足以下方程:
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = midp); weight weight;run;
11. Blaker法
通过对双侧 Blaker 精确检验逆推来构建置信区间,使检验统计量
其中:
代码:
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = blaker); weight weight;run;
最后,将以上9种方法同时展示(wald 和 wilson 仅展示校正法):
proc freq data = test; tables out /nopercent nocol norow nocum binomial(level = "阳性" cl = (wald(correct) agresticoull wilson(correct) jeffreys likelihoodratio logit clopperpearson midp blaker)); weight weight;run;
参考文献:徐莹. 一种新的单样本率的置信区间估计方法[D].南方医科大学,2019.