Search code examples
sasprobabilitypredictionlogistic-regression

How to predict probability in logistic regression in SAS?


I am very new to SAS and trying to predict probabilities using logistic regression in SAS. I got the code below from SAS Support web site:

  data vaso;
  length Response $12;
  input Volume Rate Response @@;
  LogVolume=log(Volume);
  LogRate=log(Rate);
  datalines;
3.70  0.825  constrict       3.50  1.09   constrict
1.25  2.50   constrict       0.75  1.50   constrict
0.80  3.20   constrict       0.70  3.50   constrict
0.60  0.75   no_constrict    1.10  1.70   no_constrict
0.90  0.75   no_constrict    0.90  0.45   no_constrict
0.80  0.57   no_constrict    0.55  2.75   no_constrict
0.60  3.00   no_constrict    1.40  2.33   constrict
0.75  3.75   constrict       2.30  1.64   constrict
3.20  1.60   constrict       0.85  1.415  constrict
1.70  1.06   no_constrict    1.80  1.80   constrict
0.40  2.00   no_constrict    0.95  1.36   no_constrict
1.35  1.35   no_constrict    1.50  1.36   no_constrict
1.60  1.78   constrict       0.60  1.50   no_constrict
1.80  1.50   constrict       0.95  1.90   no_constrict
1.90  0.95   constrict       1.60  0.40   no_constrict
2.70  0.75   constrict       2.35  0.03   no_constrict
1.10  1.83   no_constrict    1.10  2.20   constrict
1.20  2.00   constrict       0.80  3.33   constrict
0.95  1.90   no_constrict    0.75  1.90   no_constrict
1.30  1.625  constrict
;
ods graphics on;

proc logistic data=vaso PLOTS = (ROC EFFECT);
  model Response(event='constrict')=LogRate LogVolume 
  /ctable pprob=0.5 selection=forward rsquare link=logit expb ;
run;
ods graphics off; 

I am wondering how I could predict the probability when I have logVolume= 1.5 and logRate=1.3. Also, can you please explain what length Response $12 above means?


Solution

  • 2 ways to get predicted values: 1. Using Score method in proc logistic 2. Adding the data to the original data set, minus the response variable and getting the prediction in the output dataset.

    Both are illustrated in the code below:

    *Create an dataset with the values you want predictions for;
    data pred_wanted;
    input logvolume lograte;
    cards;
    1.5 1.3
    ;
    run;
    
    *append to predicted data set;
    data vaso2;
    set vaso pred_wanted;
    run;
    
    *run model with new options;
    proc logistic data=vaso2 ;
      model Response(event='constrict')=LogRate LogVolume 
      /ctable pprob=0.5 selection=forward rsquare link=logit expb ;
      *Get output from vaso2 (method2);
      output out=estimates p=est_response;
      *Get output from pred_wanted(method1);
      score data=pred_wanted out=estimates2;
    run;