天天看点

SAS 分类资料检验

反应变量无序则使用卡方等分析方法,如果是等级资料考虑使用Wilcoxon秩检验。

1. 卡方选择标准

卡方,n>40, 理论频数大于5

似然比卡方大样本下和卡方一致,小样本似然比卡方更稳健

连续校正卡方,理论频数大于1小于5

Fisher精确检验,n<40,理论频数小于1时。

2. McNemar检验

这是配对卡方检验。为啥不用卡方呢,因为配对样本,观测不独立。

配对样本,且反应变量只有两个水平。comparing two binomial proportions。

SAS 分类资料检验
这个地方就是检验配对前后的Non-Response的比例。

data dat7;
do r=1 to 2;
do c=1 to 2;
input freq @@;
output;
end;
end;
datalines;
160 26
5 48
;

ods html;

proc freq data=dat7;
tables r * c/nopct nocol norow  cl;
weight freq;
exact mcnem;
run;      
exact mcnem;      
SAS 分类资料检验

不加上述语句,只要加上 table / agree,对于2 x 2表格,自动执行McNemar检验, 3 x 3自动执行Bowker’s test of symmetry检验。这两个检验都是对symmetry检验。

McNemar显著是说,测量前后的却有差异。而kappa系数是说测量前后,这两次测量的间的相关性。

SAS 分类资料检验
SAS 分类资料检验

 2.1 kappa

卡方检验重在检验差异性,kappa一致性检验重在检验一致性。对同一样本实施这两种方法,会得出相反的结论。

data diet;

input pre wk2 cnt @@;

datalines;

0 0 14 0 1 6 0 2 4

1 0 9 1 1 17 1 2 2

2 0 6 2 1 12 2 2 8

;

run;

ods html;

proc freq data = diet;

tables pre*wk2 / agree nocol norow ;

test kappa;

weight cnt;

run;

SAS 分类资料检验

 Bowker’s test can be used to test for symmetry in 3×3 or larger tables. Bowker’s test for symmetry can be performed in SAS in the same way that McNemar’s test is run (by using the AGREE option in the TABLES statement in PROC FREQ)。

个人理解对称性检验是检验是否对称,kappa系数是量化。

2 x 2的symmetry检验就是Mc Nemar’s test。

3. Stuart-Maxwell

配对样本,反应变量有多个水平。或者有多个影响因素。

SAS 分类资料检验
SAS 分类资料检验
*Paired,category more than 2;
data diet;
 input pre wk2 cnt @@;
 datalines;
0 0 14 0 1 6 0 2 4
1 0 9 1 1 17 1 2 2
2 0 6 2 1 12 2 2 8
;
run; 


proc catmod data = diet;
weight cnt;
response marginal;
model pre*wk2 = _response_;
repeated time 2;
run;      
SAS 分类资料检验

4. Binomial检验

*Binomial test;
data gwart;
 input patient $ cured $ @@;
 datalines;
1 YES 2 _NO 3 YES 4 _NO 5 YES 6 YES
7 _NO 8 YES 9 _NO 10 _NO 11 YES 12 _NO
13 YES 14 _NO 15 YES 16 _NO 17 _NO 18 YES
19 YES 20 _NO 21 YES 22 YES 23 _NO 24 YES
25 YES
;

proc freq data=gwart;
 tables cured /binomial (exact  level = 'YES' ) alpha=0.05; 
run;      
binomial (exact  level = 'YES' )      

这个是精确检验,检验YES的比例是不是0.5.

SAS 分类资料检验
tables cured / binomial alpha=0.05; 
 exact binomial;       
SAS 分类资料检验

 Exact confidence intervals, sometimes known as the Clopper-Pearson limits

 4.1 score method with continuity correction

Confidence Intervals for One Proportion

SAS 分类资料检验
SAS 分类资料检验
proc freq data=gwart;
 tables cured / binomialC(wilson level = 'YES') alpha=0.05; 
run;

proc freq data=gwart;
 tables cured / binomial(cl = wilson level = 'YES' correct) alpha=0.05; 
run;      

Wilson: quests Wilson (score) confidence limits

Correct: Requests continuity correction

5. 拟合优度检验

proc freq data=gwart;
 tables cured /testp = (40 60) alpha=0.05; 
 exact chisq; 
run;      
SAS 分类资料检验

6. 卡方检验

data dat3;
do r=1 to 3;
do c=1 to 4;
input freq @@;
output;
end;
end;
datalines;
112 150 205 40
200 112 135 73
362 219 310 69
;

proc freq data = dat3;
table r*c/chisq NOROW NOCOL;
weight freq;
run;      
SAS 分类资料检验
EXACT CHISQ;      
SAS 分类资料检验

 就是重复显示了下。

对于CMH的用法,可参考CMH

本文来自博客园,作者:Iving,转载请注明原文链接:https://www.cnblogs.com/SAS-T/p/15546185.html

继续阅读