SAS学习 / 卡方检验

您所在的位置:网站首页 sas相关性分析代码 SAS学习 / 卡方检验

SAS学习 / 卡方检验

2023-11-23 09:51| 来源: 网络整理| 查看: 265

第一记 SAS学习 / 卡方检验

文章目录 第一记 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; /*expected 输出期望频数*/ 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;/*McNemar 检验*/ 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方便,此处不再赘述。

4. 分层CMH检验

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; /*分层CMH,若优比齐性的Breslow-Day检验的P


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3