用SPSS检验过正确,你试试看,别忘了付钱
%macro ROC(variable=,binary=,intable=,outtable=);
option notes=1;
proc sql;
create table &outtable.
(FLAG char(20)
,VAR char(20)
,ROC num
,constraint ok_roc check(roc between 0.5 and 1)
);
quit;
proc sql noprint;
create table temp_1 as
select &variable.,count(*) as bin_sum ,sum(&binary.) as bin_resp from &intable.
where &variable. is not null
group by &variable.
order by &variable.;
select count(*)-sum(&binary.) into :total_nresp from &intable. where &variable. is not null;
select sum(&binary.) into :total_resp from &intable. where &variable. is not null;
quit;
data temp_2;
set temp_1;
length area 8.;
retain C_sum 0 C_resp 0 C_nresp 0 l_resp 0 l_nresp 0;
C_sum=sum(C_sum,bin_sum);
C_resp=sum(C_resp,bin_resp);
C_nresp=C_sum-C_resp;
_sensit=C_resp/&total_resp.;
_1mspec=C_nresp/&total_nresp.;
area=(C_nresp-l_nresp)/&total_nresp.*(C_resp+l_resp)/&total_resp./2;
l_resp=C_resp;
l_nresp=C_nresp;
run;
proc sql;
insert into &outtable.
select
distinct "&binary." as FLAG,
"&variable." as VAR,
case when sum(a.area) ge 0.5 then sum(a.area)
else 1-sum(a.area) end as ROC
from temp_2 as a;
quit;
proc sql;drop table temp_1,temp_2;quit;
%mend;
%ROC(variable=诊断指标,binary=二值变量,intable=要检验的数据集,outtable=输出数据集);