200 likes | 476 Views
生物統計中心 諮詢師及種子教師訓練課程. 96年5月8日(二)下午1:30~3:00 訓練講者:李郁芬. 訓練內容. 1. 邏輯斯迴歸 2. SAS PROC LOGISTIC 3. SAS MACRO 語法練習. 邏輯斯迴歸. Logistic Regression Binary Outcome Y Consider Prob(Y=1)= p One covariate X. The logistic function. 模式. Model. SAS Procedures.
E N D
生物統計中心諮詢師及種子教師訓練課程 96年5月8日(二)下午1:30~3:00 訓練講者:李郁芬
訓練內容 1. 邏輯斯迴歸 2. SAS PROC LOGISTIC 3. SAS MACRO 語法練習
邏輯斯迴歸 • Logistic Regression • Binary Outcome Y • Consider • Prob(Y=1)=p • One covariate X
模式 • Model
SAS Procedures • You have many choices of performing logistic regression in the SAS System: • CATMOD, • GENMOD, • LOGISTIC, and • PROBIT
The LOGISTIC Procedure PROC LOGISTIC < options >; BY variables ; CLASS variable <(v-options)> <variable <(v-options)>... > < / v-options >; MODEL events/trials = < effects > < / options >; MODEL variable < (variable_options) > = < effects > < / options >; STRATA effects < / options >; UNITS independent1 = list1 < ... independentk = listk > < /option > ; WEIGHT variable </ option >; FREQ variable ;
資料範例 In an experiment comparing the effects of five different drugs. The outcome of each experiment is the presence or absence of a positive response in a subject. The following artificial data represent the number of responses r in the n subjects for the five different drugs, labeled A through E. The response is measured for different levels of a continuous covariate x for each drug.
DATA I data drug; input drug$ x r n @@; datalines; A .1 1 10 A .23 2 12 A .67 1 9 B .2 3 13 B .3 4 15 B .45 5 16 B .78 5 13 C .04 0 10 C .15 0 11 C .56 1 12 C .7 2 12 D .34 5 10 D .6 5 9 D .7 8 10 E .2 12 20 E .34 15 20 E .56 13 15 E .8 17 20 ; run;
SAS CODE I PROC LOGISTIC DATA=drug; CLASS drug(CODING=REF REF=‘A'); MODEL r/n = x drug; RUN;
SAS CODE II PROC LOGISTIC DATA=new; CLASS drug(CODING=REF REF='A'); MODEL y(EVENT="1")=drug x; RUN; PROC LOGISTIC DATA=newDESCENDING; CLASS drug(CODING=REF REF='A'); MODEL y=drug x; RUN;
HERE COMES THE PROBLEM • The original SAS code PROC LOGISTIC; CLASS z (CODING=REF REF=‘0'); MODEL y= x z; RUN; • 10 outcomes (Y’s) and 4 exposure matrixes (Z’s) 40 models
SAS MACRO LANGUAGE • The SAS MACRO LANGUAGE %MACRO name <(parameter-list)>; ……… ……… %mend; (SAS code)
SAS MACRO LANGUAGE • PROC LOGISTIC; • CLASS z (CODING=REF REF=“0”); • MODEL y= x z; • RUN; %MACRO xyz (depvar, indepvar); PROC LOGISTIC; CLASS &indepvar(CODING=REF REF=“0”); MODEL &depvar = x &indepvar ; RUN; %mend;
SAS MACRO LANGUAGE • Call the self-defined MACRO %xyz(y1, z1); %xyz(y2, z2); …… …… %xyz(y4, z1); %xyz(y4, z2); • we can make it more efficient
USEFUL LINK • http://www.ats.ucla.edu/STAT/sas/topics/programming.htm • Array • Macro