我是SAS的新手,并尝试使用SAS中的逻辑回归来预测概率。我从SAS支持网站获得了以下代码:
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;
我想知道如何预测logVolume= 1.5
和logRate=1.3
时的概率。另外,您能否解释一下上述length Response $12
的含义?
答案 0 :(得分:3)
获得预测值的两种方法: 1.在proc logistic中使用Score方法 2.将数据添加到原始数据集,减去响应变量并在输出数据集中获取预测。
两者都在下面的代码中说明:
*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;
答案 1 :(得分:2)
作为另一种选择,code
statement in proc logistic
会将SAS代码保存到文件中,以根据您估算的回归参数计算预测概率。在这个例子中,它看起来像这样:
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;
数据集概率应包含拟合模型的预测值。