文章目录
- 第一记 SAS学习 / 卡方检验
- 常用的几种率的比较方法
- 1. 两组独立样本:2*2卡方检验
- 2. 配对四格表:一致性检验
- 3. 多组率的比较:R*C列联表
- 4. 分层CMH检验
- 5. 卡方拟合优度检验
- 其他资料
常用的几种率的比较方法 1. 两组独立样本:2*2卡方检验
代码如下(示例):
Data a; Input r c f @@; Cards; 1 1 99 1 2 5 2 1 75 2 2 21; Run; Proc freq data=a; Weight f; Tables r*c/chisq expected norow nocol nopercent; Run;2. 配对四格表:一致性检验
代码如下(示例):
data b; do r=1 to 2; do c= 1 to 2; input f@@; output; end; end; cards; 11 12 2 33 ; run; proc freq data=b; weight f; tables r*c/agree; run;3. 多组率的比较:R*C列联表
CMH检验(Cochran-Mantel-Haenszel)
3.1 双向有序:nonzero correlation,行列为非零相关:
data b; do r=1 to 4; do c= 1 to 3; input f@@; output; end; end; cards; 431 490 902 388 410 800 495 587 950 137 179 32 ; run; proc freq data=b; weight f; tables r*c/cmh norow nocol nopercent; run;
3.2 列有序:row mean scores differ,行均值得分差值:
data b; do r=1 to 2; do c= 1 to 4; input f@@; output; end; end; cards; 2211 949 296 71 670 330 115 52 ; run; proc freq data=b; weight f; tables r*c/cmh norow nocol nopercent; run;
3.3 双向无序:general association,行列为一般关联:
data b; do r=1 to 3; do c= 1 to 4; input f@@; output; end; end; cards; 70 22 4 2 27 24 9 3 16 23 13 7 9 20 15 14 ; run; proc freq data=b; weight f; tables r*c/cmh norow nocol nopercent; run;
proc freq 代码一样,解读不同。
多组率的两两比较实现,SAS操作没有SPSS方便,此处不再赘述。
CMH检验(Cochran-Mantel-Haenszel)
3.1 双向有序:nonzero correlation,行列为非零相关:
data b;
do sex= 1 to 2;
do GROUP=1 to 2;
do EFFECT= 1 to 2;
input f@@;
output;
end;
end;
end;
cards;
5 36 33 645
10 58 19 518
;
run;
proc freq data=b;
tables sex*GROUP*EFFECT /cmh ;
weight f;
run;
普通优比和相对风险:
优比:OR,用于病例对照研究;相对风险:RR,用于队列研究。
优比齐性的Breslow-Day检验:检验各层之间的OR或RR是否齐,P>0.05,不拒绝H0,即层间有较好的一致性。
注:若各层间的OR或RR齐性检验提示层间存在统计学差异,则不能报告adjusted OR/RR,而应分层报告各层的CMH检验结果(P)和层内的OR/RR。
ods graphics on; proc freq data=b; tables sex*GROUP*EFFECT /chisq cmh plots(only)=freqplot(twoway=cluster); weight f; run; ods graphics off;
当分层因素有两个时:
data b;
do age= 1 to 3;
do sex= 1 to 2;
do GROUP=1 to 2;
do EFFECT= 1 to 2;
input f@@;
output;
end;
end;
end;
end;
cards;
5 36 33 645
10 58 19 518
8 28 39 538
20 48 19 618
12 36 63 495
22 34 15 554
;
run;
proc freq data=b;
tables age*sex*GROUP*EFFECT /cmh ;
weight f;
run;
proc freq data=b;
tables age*GROUP*EFFECT /cmh ;
weight f;
run;
proc freq data=b;
by age;
tables sex*GROUP*EFFECT /chisq cmh ;
weight f;
run;
5. 卡方拟合优度检验
单样本的构成比与已知的比例分布进行对比:
data a; input r f@@; cards; 1 10 2 10 ; run; proc freq data=a; weight f; tables r/chisq testp=(0.5552,0.4448); run;
当有单元格=0时,选择Fisher精确检验:
data a; input r c f@@; cards; 1 1 4 1 2 0 2 1 624 2 2 480 ; run; proc freq; weight f; tables r*c/chisq fisher; run;
其他资料
1.分层卡方检验-SPSS教程—医咖会添加链接描述
2.两个有序分类变量相关性的卡方检验-SPSS教程 添加链接描述
3.卡方拟合优度检验-SPSS教程 添加链接描述
4.卡方检验之R和SAS的实现 添加链接描述
5. 用spss做多组两两相关性分析_卡方检验的事后两两比较添加链接描述



