此文為兩組配對資料檢定-Wilcoxon Signed Rank Test Paired t test using SAS 之進階版
分兩個語法介紹,語法2會用到SAS macro,當重複變項很多時,可善用macro,提升工作效率
語法1
data a;
call streaminit(123);*指定隨機數生成的種子值(seed value),可固定每次的隨機值;
do i=1 to 10;
T0=int(100*rand('uniform'));
T1=10+int(90*rand('uniform'));
T2=30+int(70*rand('uniform'));
T3=50+int(50*rand('uniform'));
output;
end;
drop i;
run;
proc means mean min max;var T0 T1 T2 T3;run;*檢視平均值、最小值和最大值;
data a1;set a;
diff1=T1-T0;
diff2=T2-T0;
diff3=T3-T0;
proc print noobs;run;
proc univariate normal data=a1; *檢視是否常態;
var diff1 diff2 diff3;
run;
|
結果
diff1: 由位置檢定中的 Student's t 得到T1和T0差距數據的p=0.2754
diff2 :由位置檢定中的 Student's t 得到T2和T0差距數據的p=0.2126
diff3: 由位置檢定中的 Student's t 得到T3和T0差距數據的p=0.0127
語法2
/*Using Macro*/
data a1;set a;
%macro diff;
%do i=1 %to 3;
diff&i.=T&i.-T0;
%end;
%mend;
%diff;
proc print noobs;run;
%macro uni;
%do i=1 %to 3;
ods output TestsForLocation=TFL&i.;
proc univariate normal data=a1;
var diff&i.;
run;
%end;
%mend;
data TFL;set TFL1-TFL3;
proc print data=TFL;
where test="Student's t";
var pvalue;
run;
|
結果2
若資料未通過常態,則需採用無母數分析-Wilcoxon Sign Rank test:
proc print data=TFL;
where test="符號秩";
var pvalue;
run; |
結果3
留言列表