[程式] SAS 重複1000次交叉驗證
[軟體程式類別]: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)
推
09/30 12:14, , 1F
09/30 12:14, 1F
推
09/30 12:21, , 2F
09/30 12:21, 2F
→
09/30 12:28, , 3F
09/30 12:28, 3F
→
09/30 12:28, , 4F
09/30 12:28, 4F
※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 12:35)
→
09/30 15:01, , 5F
09/30 15:01, 5F
→
09/30 15:22, , 6F
09/30 15:22, 6F
→
09/30 16:25, , 7F
09/30 16:25, 7F
→
09/30 16:29, , 8F
09/30 16:29, 8F
→
09/30 16:30, , 9F
09/30 16:30, 9F
→
09/30 16:30, , 10F
09/30 16:30, 10F
→
09/30 20:29, , 11F
09/30 20:29, 11F
推
10/05 01:06, , 12F
10/05 01:06, 12F