2016年6月30日 星期四

Logistic Regression

%macro Deviance_table(data, y, n, old_x) ;
/*********************************************************************************************************
*名稱:                                                                                                   *
*作者:jimmy                                                                                              *
*日期:2016/06/30                                                                                         *
*說明:                                                                                         *                         
*                                                             *
*                                                                                       *
*********************************************************************************************************/




/*進行組合*/
ods trace on / listing;
proc reg data = &data.;
 model &y. = &old_x. / selection = RSQUARE;
 ods output SubsetSelSummary = gx;
quit;
ods trace off;

proc sql;
 select VarsInModel
  into :g1 separated by "-"
  from gx;
quit;
/**/

/*取出組合 做多次迴歸*/
%do i = 1 %to &n;
 %let b = %scan(%bquote(&g1.), &i,%str(-));
 ods trace on / listing;
 proc logistic data = &data. desc;
  model &y. = &b. / aggregate scale = none;
  ods output GoodnessOfFit = test&i.;
 run;title;footnote;quit;
 ods trace off;

 data newtest;
 run;
%end;
/**/

proc sql; 
 create table newtest
 like test1;
quit;

%do i = 1 %to &n;
 proc sql;
  insert into newtest
  select * from test&i
  where Criterion = "Deviance";
 run;title;footnote;quit;
%end;


proc print data = newtest;
 title "&g1";
run;title;footnote;quit;
%mend;

%Deviance_table(data = mysas.reg13_5, y = y, n = 3, old_x = x1 x2)

只要輸入變數,就會依照變數的所有組合,進行多次的proc logistic。
這支macro主要是想要把每組模型的Deviance集合在一起。
因為proc logistic沒有selection的控制項,沒辦法進行變數的組合,所以用了proc reg來完成,但非常沒效率。
最後呈現的報表不易觀看,會持續改進此macro。


將會產生的報表
主要的內容

%Deviance_table(data = 資料集, y = 依變數, n = 3==(2^2-1), old_x = x1 x2)

Related Posts:

  • SAS macro Ensemble Learning 以bootstrap方法產生多個資料集, 分別為每個資料集建立linear regression模型, 整合多個模型降低mse。 作者:jimmy 日期:2017/3/9 %macro my_bootstrap(data = , b = , obs =); %do bootstrap_i… Read More
  • Logistic Regression%macro Deviance_table(data, y, n, old_x) ; /********************************************************************************************************* … Read More
  • proc gtile sas help檔 內容 goptions reset = all device = java noborder; proc gtile data = sashelp.shoes; tile stores tileby = (region subsidiary) / colorvar =… Read More
  • 將SAS報表匯出至外部檔案 可參考這篇(連結) PDF ods pdf file="C:\Users\139869\Desktop\深入解析SAS\test.pdf"; proc print data = sashelp.class; run; ods pdf close; ods pdf fil… Read More
  • 產生虛擬變數(dummy variable) 快速生成虛擬變數(dummy variable)  data test; input age aaa y; datalines; 1 1 1 2 2 2 3 3 3 1 4 3 2 5 3 5 5 3 4 5 3 3 1 3 ; run; %dummy(mydata = te… Read More

0 意見:

張貼留言