问题
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?
回答1:
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;
回答2:
As another option, the code statement in proc logistic will save SAS code to a file to calculate the predicted probability from the regression parameters that you estimated. In this example, it would look something like this:
proc logistic data=vaso PLOTS = (ROC EFFECT);
model Response(event='constrict')=LogRate LogVolume
/ctable pprob=0.5 selection=forward rsquare link=logit expb ;
CODE "pprob.sas";
run;
data probabilities;
input logVolume logRate;
%include "pprob.sas";
cards;
1.5 1.3
;
run;
The data set probabilities should contain the predicted values from the fitted model.
来源:https://stackoverflow.com/questions/27451600/how-to-predict-probability-in-logistic-regression-in-sas