為什麼這篇交叉驗證範例鄉民發文收入到精華區:因為在交叉驗證範例這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者wlsherica (CrevetteStudio)看板Statistics標題[程式] SAS...
[程式問題]:macro
[軟體熟悉度]:高(1年以上)
[問題敘述]:
手上有一組原始資料,想要作10-fold cross-validation(交叉驗證,CV)
計算線性迴歸後得到一個R-square之後,將這些過程重複1000次,
以得到1000個R-square,再去計算平均值。
目前先寫了內部的程式(CV+PROC SURVEYSELECT+PROC REG)
現在想要重覆作1000次,因為會有1000個R-square,想將之存在同一個檔案
應該是要用macro寫...
初步跑一次發現output與log file跑出很多檔,如果另存到其他地方
是否會提升效率呢?
[程式範例]:
%macro boot ;
%do x = 1 %to 1000;
/*對raw data(檔名boottest)進行抽樣,出來的檔為xv*/
%let k=10;
%let rate=%sysevalf((&k-1)/&k);
proc surveyselect data=boottest out=&x. seed=0
samprate=&rate outall rep=10;
run;
/*開始作10-fold CV*/
data xv&x.;
set xv&x.;
if selected then new_y=y;
run;
/*對proc reg內去取得Y的預測值(yhat)*/
proc reg data=xv&x. noprint;
model new_y=x;
by replicate;
output out=outb&x.(where=(new_y=.)) p=yhat;
run;
/*計算y與yhat的R-square,即這段程式的目標*/
ods output fitstatistics=tt&x.(where=(label2="R-Square"));
proc reg data=outb&x. ;
model yhat=y;
run;
%end;
%mend boot;
%boot;
-----------------------------------------------------------------------------
macro初學者,請先進們不吝賜教指點
非常感謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.25.110.97
※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 11:32)
※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 11:48)