α   |  ȸ  |  Ʈ  |  Contact Us
  ̵ ϱ
 
Ȩ > SAS Tech & Tip > SAS
[Logistic] Surveyselect ν Ȱ Bagging Logistic 2017.06.01
¹ 258 0
http://www.mysas.co.kr/SAS_tiptech/a_all.asp?b_no=7311&gotopage=1&con=subject&keyword=&cmd=content&bd_no=33&gubun=

* ǥ Ŵ(ѱǻȸ);

 

* MODEL VALIDATION TECHNIQUES

  : http://www.listendata.com/2015/01/model-validation-in-logistic-regression.html


* Don't Be Loopy: Re-Sampling and Simulation the SAS Way

  : http://www2.sas.com/proceedings/forum2007/183-2007.pdf

 

* Lab Eight: implementing the bootstrap and 10-fold CV in SAS

  : https://web.stanford.edu/~kcobb/hrp261/lab8.doc;

 

* : https://web.stanford.edu/~kcobb/hrp261/kyphosis.sas7bdat;

 

 

LIBNAME lab8 'C:\work\SAS\Ÿ';

 

%LET nsamples=20;

 

PROC SORT DATA=lab8.kyphosis OUT=kyphosis;

     BY Kyphosis;

RUN;

 

ods select none;

* OUTHITS : ǥ 1ȸ̻ Ե ǥ;

* URS : , SRS : 񺹿;

* strata : ǥ Ÿ ;

proc surveyselect data=kyphosis method=urs n=83 rep=&nsamples. out=boot SEED=1234;

     strata Kyphosis;

run;

ods select all;

 

PROC SQL;

  SELECT SUM(CASE WHEN Kyphosis=1 THEN 1 ELSE 0 END) / COUNT(*) AS RATIO

  FROM   lab8.kyphosis;

QUIT;

 

PROC SQL;

  SELECT Replicate,

         SUM(CASE WHEN Kyphosis=1 THEN 1 ELSE 0 END) / COUNT(*) AS RATIO

  FROM   boot

  GROUP BY 1;

QUIT;

 

proc sort data=boot;

     by Replicate; 

run;

 

proc logistic data=boot outest=est outmodel=LOGIT_MODEL noprint;

     by    replicate;

     model kyphosis (event="1")= age number start;

     freq  numberhits;

run;

 

 

/* ׽Ʈ SCORE */

 

* SCORE ν(TEST SCORE );

proc score data=kyphosis(rename=(Kyphosis=Kyphosis_1)) out=SCORE_OUT score=est type=parms;

     by  replicate;

     var age number start;

run;

 

data RESULT_1;

 set SCORE_OUT;

     prob=exp(Kyphosis)/(1+exp(Kyphosis));

run;

 

* logistic ν INMODEL(TEST SCORE );

proc logistic inmodel=LOGIT_MODEL;

     by replicate;

     score data=kyphosis(rename=(Kyphosis=Kyphosis_1)) out=RESULT_2;

run;

 

* TEST Ʈ SCORE հ ;

PROC SQL;

  CREATE TABLE RESULT_PREV AS

    SELECT ID,

           AVG(PROB) AS AVG_SOCRE

    FROM   RESULT_1

    GROUP BY 1;

QUIT;

 

*********************************************;

/* CROSS-VALIDATION */

*********************************************;

%let K=10;

%let rate=%syseval‎f((&K-1)/&K);

%PUT &RATE;

 

/* generate the cross-validation sample */

proc surveyselect data=kyphosis out=xv seed=495857

                  samprate=&RATE outall rep=&K method=urs ;

run;

 

data xv;

 set xv;

     if selected then new_Kyphosis=Kyphosis;

run;

 

/* get predicted values for the missing new_y in each replicate */

 

proc logistic data=xv outest=est outmodel=LOGIT_MODEL outest=est noprint;

     by    replicate;

     model new_Kyphosis (event="1")= age number start;

     freq  numberhits;

     output out=out1(where=(new_Kyphosis=.)) p=yhat;

run;


*********************************************;

/* do LOOCV */

*********************************************;

data xv;

     do replicate = 1 to numrecs;

        do rec = 1 to numrecs;

           set kyphosis nobs=numrecs point=rec;

           if replicate ^= rec then new_Kyphosis=Kyphosis; else new_Kyphosis=.;

           OUTPUT;

        end;

     end;

     STOP;

 run;

 

 

 proc logistic data=xv outest=est outmodel=LOGIT_MODEL outest=est noprint;

     by    replicate;

     model new_Kyphosis (event="1")= age number start;

     output out=out1(where=(new_Kyphosis=.)) p=yhat;

run;

 




*********************************************;

* ;

*********************************************;

 

PROC SORT DATA=kyphosis;

     BY ID;

RUN;

 

/* ׽Ʈ 10 : 񺹿 Ʒ ڵ */

proc surveyselect data=kyphosis method=SRS n=83 rep=10 out=TEST_DATA SEED=1234 NOPRINT;

run;

 

data TEST_DATA_1;

     do replicate = 1 to &nsamples;

        do rec = 1 to numrecs;

           set kyphosis nobs=numrecs point=rec;

           OUTPUT;

        end;

     end;

     STOP;

 run;

 

 
 
 
 
 [ǥ] SAS ϴ
 [HELP] Sashelp Data Sets Ʈ