SAS 分類資料檢驗


反應變量無序則使用卡方等分析方法,如果是等級資料考慮使用Wilcoxon秩檢驗

1. 卡方選擇標准

卡方,n>40, 理論頻數大於5

似然比卡方大樣本下和卡方一致,小樣本似然比卡方更穩健

連續校正卡方,理論頻數大於1小於5

Fisher精確檢驗,n<40,理論頻數小於1時。Fisher檢驗是基於超幾何分布。

 Yates也是小樣本檢驗,思想是Person卡方的分子減去0.5

 

2. McNemar檢驗

這是配對卡方檢驗。為啥不用卡方呢,因為配對樣本,觀測不獨立。

配對樣本,且反應變量只有兩個水平。comparing two binomial proportions。

 

 

 

這個地方就是檢驗配對前后的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;

 

 

不加上述語句,只要加上 table / agree,對於2 x 2表格,自動執行McNemar檢驗, 3 x 3自動執行Bowker’s test of symmetry檢驗。這兩個檢驗都是對symmetry檢驗。

McNemar顯著是說,測量前后的卻有差異。而kappa系數是說測量前后,這兩次測量的間的相關性。

 

 

 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;

 

 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

配對樣本,反應變量有多個水平。或者有多個影響因素。

 

 

 

 

 

*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;

 

 

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.

 

 

  

 tables cured / binomial alpha=0.05; 
 exact binomial; 

 

 

 

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

 

 4.1 score method with continuity correction

Confidence Intervals for One Proportion

 

 

 

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;

 

 

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;

 

 

 

EXACT CHISQ;

 

Chi-Square就是Pearson卡方,是檢驗行列之間的一般關聯。

Likelihood Ratio是似然比卡方,總例數/(行數*列數)<=5時使用。Likelihood Ration=滿足H0時參數的最大似然值/不一定滿足H0時參數的最大似然值。LR值越小拒絕H0的證據就越強。

MH卡方是檢驗行列之間的線性關系,一般只適用於行列均有序時使用。

上述只是檢驗有無關聯,如果了解具體關聯系數是多少,則可以計算相關系數線性相關系數總結

下面那三個是相關系數。線性相關系數總結

 

 就是重復顯示了下。

 

對於CMH的用法,可參考CMH

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM