

/* 연속형 변수에 empirical logit plot */

%let var=DDABal; *변수지정;


/* empirical logit plot을 그리기 위해 그룹 변수 생성 */
proc rank data=imputed groups=100 out=out;
   var &var;
   ranks bin;
run;
* groups= : 그룹수 지정,100지정시 percentile과 같은 의미;
* ranks : 그룹변수 생성 ;

proc print data=out(obs=10);
   var &var bin;
run;

/* The data set BINS will contain:          */
/* INS = the count of successes in each bin */
/* _FREQ_ = the count of trials in each bin */
/* DDABAL = the avg DDABAL in each bin      */
proc means data=out noprint nway;
   class bin;
   var ins &var;
   output out=bins sum(ins)=ins mean(&var)=&var;
run;

proc print data=bins(obs=10);
run;


/* Calculate the empirical logit */ 
data bins;
   set bins;
   elogit=log((ins+(sqrt(_FREQ_ )/2))/
          ( _FREQ_ -ins+(sqrt(_FREQ_ )/2)));
run;

proc sgplot data = bins;
   reg y=elogit x=&var /
       curvelabel="Linear Relationship?"
	   curvelabelloc=outside
	   lineattrs=(color=ligr);
   series y=elogit x=&var;
   title "Empirical Logit against &var";
run;

proc sgplot data = bins;
   reg y=elogit x=bin /
       curvelabel="Linear Relationship?"
	   curvelabelloc=outside
	   lineattrs=(color=ligr);
   series y=elogit x=bin;
   title "Empirical Logit against Binned &var";
run;
