搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  DATA.xls
资料下载链接地址: https://bbs.pinggu.org/a-2500633.html
附件大小:
15.23 KB   举报本内容
总是提示where 子句运算符要求兼容的变量,我做的是一个10-fold cross- validation 交叉验证,因变量是字符型,自变量是数字,
  1. %macro xval(dsn=,outcome=,covars=,k=10,sel=stepwise,outdsn=_xval_,outdsn2=comparison);

  2. data _modif;
  3. set &dsn;
  4. unif=&k*ranuni(20052905);
  5. xv=ceil(unif);
  6. run;

  7. %do i=1 %to &k;
  8. proc logistic data=_modif(where=(xv ne &i)) outmodel=_mod&i;
  9. model &outcome (event="1") =&covars / selection=&sel;
  10. ods output association=assoc&i;
  11. run;
  12. %if print^=0 %then %do;proc printto file='junk.txt';%end;
  13. proc logistic inmodel=_mod&i;
  14. score data=_modif(where=(xv=&i)) out=out&i;
  15. run;

  16. ods select none;
  17. ods output KolSmir2Stats=KS&i;
  18. proc npar1way data= out&i edf;
  19. where &outcome^=.;
  20. class &outcome;
  21. varP_1;
  22. run;
  23. ods select all;

  24. ods select none;
  25. ods output WilcoxonScores=Wil&i;
  26. proc npar1way wilcoxon data= out&i;
  27. where &outcome^=.;
  28. class &outcome;
  29. varP_1;
  30. run;
  31. ods select all;

  32. data AUC&i;
  33. set Wil&i end=eof;
  34. retain v1 v2 1;
  35. if _n_=1 then v1=abs(ExpectedSum - SumOfScores);
  36. v2=N*v2;
  37. if eof then do;
  38. d=v1/v2;
  39. /*Gini=d * 2; */
  40. Scoring_AUC= d + 0.5;
  41. put Scoring_AUC=;
  42. put "****Open work.results dataset to see results of training datasets....";
  43. keep Scoring_AUC;
  44. output;
  45. end;
  46. run;

  47. %if print^=0 %then %do;proc printto;run;%end;
  48. %end;
  49. data &outdsn;
  50. set %do j=1 %to &k;out&j %end;;
  51. run;

  52. data training (keep =label2 nvalue2 rename= (nvalue2=Training_AUC));
  53. set %do j=1 %to &k;assoc&j %end;;
  54. where label2= 'c';
  55. if label2='c' then label2 ='AUC';
  56. run;

  57. data ks (keep =label2 nvalue2 rename= (nvalue2=Scoring_KS));
  58. set %do j=1 %to &k;ks&j %end;;
  59. where label2= 'D';
  60. if label2='D' then label2 ='KS';
  61. run;

  62. data validation;
  63. set %do j=1 %to &k;AUC&j %end;;
  64. run;

  65. data &outdsn2 (drop = label2);
  66. merge training validation ks;
  67. run;

  68. ods select none;
  69. ods output WilcoxonScores=WilcoxonScore;
  70. proc npar1way wilcoxon data= &outdsn;
  71. where &outcome^=.;
  72. class &outcome;
  73. varP_1;
  74. run;
  75. ods select all;

  76. data AUC;
  77. set WilcoxonScore end=eof;
  78. retain v1 v2 1;
  79. if _n_=1 then v1=abs(ExpectedSum - SumOfScores);
  80. v2=N*v2;
  81. if eof then do;
  82. d=v1/v2;
  83. Gini=d * 2;
  84. AUC= d + 0.5;
  85. put AUC=GINI=;
  86. put "****Open work.results dataset to see results of training datasets....";
  87. keep AUC Gini;
  88. output;
  89. end;
  90. run;

  91. %mend;

  92. %xval(dsn=data,outcome=var_13,covars= t569 t868 t725 t291 t323,k=10,sel=stepwise, outdsn=kfold, outdsn2=comparison);
复制代码



    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

GMT+8, 2026-1-17 23:04