SAS中文论坛

标题: 如何编程使其自动完成多次logistic回归分析 [打印本页]

作者: shiyiming    时间: 2006-3-12 14:20
标题: 如何编程使其自动完成多次logistic回归分析
请教各位高手 :

    我现在遇到的问题是:我需要做500次逻辑回归,问能否编成实现,并且希望每次回归过程能够自动实现用逐步回归法选择自变量。

   谢谢您的回复!
作者: shiyiming    时间: 2006-3-14 08:54
标题:
比较感兴趣您的问题,能否详细描述一下,最好附上数据。
作者: shiyiming    时间: 2006-3-14 14:54
标题: 如何编程使其自动完成多次logistic回归分析
collen :您好!非常感谢您能帮忙!我把问题简化如下,不知道我说清楚了没有,没有的话我再详细介绍。


编号       X1            X2        X3           X4             X5            X6        X7             X8            Y1            Y2        Y3        Y4        Y5        Y6        Y7        Y8        Y9        Y10
1        2        0        1        6        1        2        5        2        0        …        …        …        …        …        …        …        …        …
2        3        3        1        5        0        1        2        2        0        …        …        …        …        …        …        …        …        …
3        1        3        0        2        1        3        0        1        1        …        …        …        …        …        …        …        …        …
4        2        2        1        3        1        2        6        3        0        …        …        …        …        …        …        …        …        …
5        5        1        1        4        0        2        3        2        1        …        …        …        …        …        …        …        …        …
6        0        2        0        1        1        3        2        1        ?        ?        ?        ?        ?        ?        ?        ?        ?        ?
7        5        5        0        2        0        2        6        3        ?        ?        ?        ?        ?        ?        ?        ?        ?        ?
8        3        4        0        2        0        3        4        2        ?        ?        ?        ?        ?        ?        ?        ?        ?        ?
9        4        3        1        4        0        1        4        2        ?        ?        ?        ?        ?        ?        ?        ?        ?        ?
10        1        1        0        3        1        3        3        3        ?        ?        ?        ?        ?        ?        ?        ?        ?        ?
假如有10行记录,X1-X8 都是已知 对于1-5号记录Y1-Y10(实际有500个)也是已知的
过程描述:
(1)        用1-5号的X1-X8 与Y1可以进行一次逻辑回归,得到相关参数 求出 6-10号的Y1
(2)        用1-5号的X1-X8 与Y2可以进行一次逻辑回归,得到相关参数 求出 6-10号的Y2
(3)        同样的道理,对于上面的数据可以求出 6-10号的Y3-Y10
(4)        希望每次逻辑回归能够检验回归方程的显著性,以及所的系数的显著性,并按照规定的标准剔除不显著的自变量。
作者: shiyiming    时间: 2006-3-14 22:55
标题:
我觉得用proc logistic做不存在什么困难啊。
作者: shiyiming    时间: 2006-3-15 11:55
标题: 谢谢!
因为之前没有做过类似的分析,在语句控制和参数设置方面觉得有难度,不知道能否推荐类似的程序作参照,我自己找了很久都没有找到。
作者: shiyiming    时间: 2006-3-15 13:54
标题: 动手吧
无非就是用宏语言来动态变化参数.
会用宏细心点就可以作出来.
作者: shiyiming    时间: 2006-3-15 15:31
标题: 有没有类似的例子推荐一个吧
刚刚开始学,可以推荐一个例子吗?可能会学得快一些,论文有点急 <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: --> 。非常感谢啦!
作者: shiyiming    时间: 2006-3-21 22:11
标题: 请各位多多指教!
初学,需要大家的鼓励, <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->

分两个部分来处理:
  1,连续执行logistic 回归,得到自变量的估计系数, 它是定义在一个数据文件(estimator)中;
  2,用estimator对预测数据预测出因变量的预测值;
这里将用来估计的和预测的数据分成两个数据文件来处理。

%macro product(aa=,bb=);
  proc sql;
  create table c as
  select intercept as intercept, x1*y1 as z1 %do i=2 %to 8;,x&i*y&i as z&i %end;
  from &aa,&bb;
  quit;
%mend;

%macro logistic(data=,dv=,iv=,num=,dnum=,test=);
/* data means what you want do satatistical test on*/
/* dv and iv means dependent variable and independent variables*/
/* dnum is used to specify how many dependant variables includes, like   
   /*x1 x2 x3...x8, where there are 8 variable and setting dnum=8*/
/* test is dataset, based on which you get predicted yi.*/

  data _null_;
    iv2 = tranwrd(compbl("&iv"), " ", "+");
    dv2 = tranwrd(compbl("&dv"), " ", "+");
    call symput('iv2', iv2); /* independant variables array, like weight len...'*/
    call symput('dv2', dv2);
  run;

%do i=1 %to &dnum;
    %let dvv&i=%scan(&dv2,&i,+);
%end;

%do i=1 %to &num;
     %let ivv=%scan(&iv2,&i,+);      
           proc logistic data=&data outest=estimates;
               /* estimated coefficienct stored on dataset estimates;*/
              model &ivv=&dvv1-&&dvv&dnum /selection=forward;
           run;

      data estimates(keep=&dvv1-&dvv2,intercept);
           set estimates;
      run;
     /*  keep coefficient for dv and intercept in dataset estimates;*/

      %product(aa=estimates,bb=test);
      proc sql;
          create table y&i as
          select z1+z2+z3+z4+z5+z6+z7+z8 as y;
      /* where there should be on simplied expression instead of z1+...z8*/
          from c;
       quit;
  %end;
%mend;

Any commets are welcome. thanks a lot!
作者: shiyiming    时间: 2006-3-22 19:15
标题: thanks!!!
这几天没有上网,才看到您的回复,非常感谢!
作者: shiyiming    时间: 2006-4-20 12:15
标题: to gesas
我是新手,只知道简单的sas语法,你写的程序里面好多我都不懂,比如:macro, call, from, 还有%也不知道什么意思,能不能再详细给我讲一下,或者传给我一些关于macro和哪些%的相关资料,我参考一下,能不能信件交流一下,我的mail:atomdust@163.com,多谢了!
作者: shiyiming    时间: 2006-4-22 23:01
标题: to najia_yj
这个你还是要参看一些教程了。看看marco的在线教材也是不错。这个论坛上有在线教材的link。




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2