楼主: moonstone
19748 15

[原创博文] 广义加法模型(PROC GAM)与PROC LOGISTIC 及PROC GENMOD之间的区别与联系 [推广有奖]

讲师

74%

还不是VIP/贵宾

-

威望
0
论坛币
10442 个
通用积分
336.6055
学术水平
160 点
热心指数
169 点
信用等级
124 点
经验
263126 点
帖子
237
精华
1
在线时间
520 小时
注册时间
2007-4-27
最后登录
2024-4-11

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
PROC GAM的主要用途是在广义线性模型(PROC GENMOD)基础上探索自变量与因变量之间是否有非线性关系。至于为什么名称中叫“加法模型”,个人简单的理解是:基于PROC GAM得到的预测结果是线性成分与非线性成分的相加得到的,也即线性预测的成分与非线性预测的成分是一个(广义)相加的模型。

既然GAM模型可以拟合线性成分与非线性成分,自然也就可以拟合所有广义线性的结果,也即PROC GAM理论上可以拟合所有PROC GENMOD所能构建的模型。而PROC LOGISTIC回归同时也属于广义线性模型的范畴,也即PROC GENMOD可以拟合PROC LOGISTIC回归所能构建的模型。进一步推理可得,PROC GAM理论上同样也可以构建
PROC LOGISTIC回归所能构建的模型。下面以一个简单的例子说明一下三者之间的区别与联系。

例子来源:PROC GAM 的SAS帮助文件的EXAMPLE 1,主要探索驼背(Kyphosis )的发生是否受小孩接受脊柱手术的年龄(AGE)、脊柱手术的起始脊椎(StartVert )以及手术所涉及脊椎数(NumVert )的影响。对原始程序稍加修改如下:


  1. data kyphosis;
  2.    input Age StartVert NumVert Kyphosis @@;
  3.    datalines;
  4. 71  5  3  0     158 14 3 0    128 5   4 1
  5. 2   1  5  0     1   15 4 0    1   16  2 0
  6. 61  17 2  0     37  16 3 0    113 16  2 0
  7. 59  12 6  1     82  14 5 1    148 16  3 0
  8. 18  2  5  0     1   12 4 0    243 8   8 0
  9. 168 18 3  0     1   16 3 0    78  15  6 0
  10. 175 13 5  0     80  16 5 0    27  9   4 0
  11. 22  16 2  0     105 5  6 1    96  12  3 1
  12. 131 3  2  0     15  2  7 1    9   13  5 0
  13. 12  2 14  1     8   6  3 0    100 14  3 0
  14. 4   16 3  0     151 16 2 0    31  16  3 0
  15. 125 11 2  0     130 13 5 0    112 16  3 0
  16. 140 11 5  0     93  16 3 0    1   9   3 0
  17. 52  6  5  1     20  9  6 0    91  12  5 1
  18. 73  1  5  1     35  13 3 0    143 3   9 0
  19. 61  1  4  0     97  16 3 0    139 10  3 1
  20. 136 15 4  0     131 13 5 0    121 3   3 1
  21. 177 14 2  0     68  10 5 0    9   17  2 0
  22. 139 6  10 1     2   17 2 0    140 15  4 0
  23. 72  15 5  0     2   13 3 0    120 8   5 1
  24. 51  9  7  0     102 13 3 0    130 1   4 1
  25. 114 8  7  1     81  1  4 0    118 16  3 0
  26. 118 16 4  0     17  10 4 0    195 17  2 0
  27. 159 13 4  0     18  11 4 0    15  16  5 0
  28. 158 15 4  0     127 12 4 0    87  16  4 0
  29. 206 10 4  0     11  15 3 0    178 15  4 0
  30. 157 13 3  1     26  13 7 0    120 13  2 0
  31. 42  6  7  1     36  13 4 0
  32. ;

  33. proc logistic data=kyphosis descending;
  34.    model Kyphosis = Age StartVert NumVert;
  35. run;

  36. title 'Comparing PROC GENMOD with PROC LOGISTIC';
  37. proc genmod data=kyphosis descending;
  38.    model Kyphosis = Age StartVert NumVert /link=logit dist=binomial;
  39. run;

  40. title 'Comparing PROC GAM with PROC GENMOD';
  41. proc gam data=kyphosis;
  42.    model Kyphosis (event='1') = param(Age)
  43.                                 param(StartVert)
  44.                                 param(NumVert) / dist=binomial;
  45. run;

  46. title 'Developing a non-linear model with PROC GAM';
  47. proc gam data=kyphosis;
  48.    model Kyphosis (event='1') = spline(Age      ,df=3)
  49.                                 spline(StartVert,df=3)
  50.                                 spline(NumVert  ,df=3) / dist=binomial;
  51.         output
  52.     OUT=output
  53.     PREDICTED   /*  predicted values for each smoothing component and overall predicted values
  54.                         on the response scale at design points. The prediction for each spline or
  55.                         loess term is only for the nonlinear component of each smoother. */
  56.     LINP        /*  linear prediction values on the link scale at design points  */
  57. ;
  58. run;
复制代码


SmoothingComponentPlot1.png


对于输出结果,可以看到PROC GAM 可以拟合与PROC GENMOD以及PROC LOGISTIC回归一样的结果

但是对于包含非线性成分的PROC GAM模型,需要注意的是,上述输出图形的纵坐标包含有负值,难道不应该是0到1之间的概率值吗?


这个问题很早以前,论坛中已经有人提过(https://bbs.pinggu.org/thread-2146081-1-1.html),但是没有回复 ,详细研究之后,得到答案如下:

如果采用PROC GAM构建的模型是 y=spline(x)

所得到的预测结果: E(Y|X=x)=a + bx +s(x)

如果将结果输出,可以看到上述图形中实际只是利用模型的非参数部分,也即 s(x) 对x作图所得的结果。
如果想看预测概率与原始x的关系,可以补充以下程序,但是得到的图形其实并没有实际规律,因为预测值是线性成分bx 与非线性成分s(x)共同构建的结果。所以采用预测值对x作图没有实际意义。而真正有意义的是看非线性成分的回归系数是否小于0.05,如果非线性成分回归系数的P值小于0.05,则提示自变量与因变量之间应该考虑非线性成分的影响。



  1. proc sort data=output ;
  2. by age;run;

  3. proc sgplot data=output ;
  4.   series x=Age       y=p_Kyphosis;
  5. run;
复制代码





二维码

扫码加我 拉你入群

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

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

关键词:logistic logisti ogistic logist genmod 模型

已有 1 人评分经验 收起 理由
eijuhz + 20 精彩帖子

总评分: 经验 + 20   查看全部评分

沙发
brspy2008 发表于 2014-12-9 23:07:51 |只看作者 |坛友微信交流群
请问这是哪个模块的过程呢?

使用道具

藤椅
moonstone 发表于 2014-12-15 13:57:31 |只看作者 |坛友微信交流群
但是当自变量中存在分类变量(也即在模型中加入CLASS变量)时,PROC GAM、PROC GENMOD,及 PROC LOGISTIC 回归所得到的结果则并非完全相同,至于为什么会出现如此差异,有待进一步的研究。检验程序如下:
  1. proc logistic data=kyphosis descending;
  2.    class NumVert;
  3.    model Kyphosis = Age StartVert NumVert;
  4. run;


  5. proc genmod data=kyphosis descending;
  6.    class NumVert;
  7.    model Kyphosis = Age StartVert NumVert /link=logit dist=binomial;
  8. run;


  9. proc gam data=kyphosis;
  10.    class NumVert;
  11.    model Kyphosis (event='1') = param(Age)
  12.                                 param(StartVert)
  13.                                 param(NumVert) / dist=binomial;
  14. run;
复制代码


已有 1 人评分经验 收起 理由
eijuhz + 20 精彩帖子

总评分: 经验 + 20   查看全部评分

使用道具

板凳
jingju11 发表于 2014-12-16 13:17:20 |只看作者 |坛友微信交流群
moonstone 发表于 2014-12-15 13:57
但是当自变量中存在分类变量(也即在模型中加入CLASS变量)时,PROC GAM、PROC GENMOD,及 PROC LOGISTIC 回 ...
LOGISTIC 回归所得到的结果则并非完全相同,至于为什么会出现如此差异,有待进一步的研究。
Thanks for sharing.
The difference was resulted from that both logistic and genmod procedures were not converged at all provided that the data and predictors you had given.
I agree with you that the parameters from the three models should be consistent if the models are converged. I don't think the three models use the same optimization methods.
JingJu

使用道具

报纸
moonstone 发表于 2014-12-16 17:48:07 |只看作者 |坛友微信交流群
jingju11 发表于 2014-12-16 13:17
Thanks for sharing.
The difference was resulted from that both logistic and genmod procedures ...
非常感谢老师的回复。
老师提到logistic和GENMOD在现有提供的数据中均没有完全收敛,那是否有方法可以验证三个模型在存在class语句的时候能够取得理论上一致的结果。
另外,为什么上述语句中,当存在class语句后,genmod与gam的结果一致呢?只是logistic回归的结果与前两者不一致?
欢迎老师继续交流。

使用道具

地板
jingju11 发表于 2014-12-17 05:50:11 |只看作者 |坛友微信交流群
moonstone 发表于 2014-12-16 17:48
非常感谢老师的回复。
老师提到logistic和GENMOD在现有提供的数据中均没有完全收敛,那是否有方法可以验 ...
Thanks. As you mentioned, logistic model can be viewed as a special case from generalized linear models, and thus should provide consistent results for binomial data from Logistic and Genmod procedures. To compare the results we need to specify the models under the same parameterization scheme.

  1. data kyphosis;
  2. input Age StartVert NumVert Kyphosis @@;
  3. age100 =(age<100);/* create a class variable*/
  4. datalines;
  5. ...
  6. ;
  7. ods output ParameterEstimates(persist=proc)=pes;
  8. proc logistic data=kyphosis descending;
  9. class age100(param=ref ref='1');
  10. model Kyphosis = age100 StartVert NumVert;
  11. run;
  12. proc genmod data=kyphosis descending;
  13. class age100(ref='1');
  14. model Kyphosis = age100 StartVert NumVert /link=logit dist=binomial;
  15. run;
  16. proc gam data=kyphosis;
  17. class age100;
  18. model Kyphosis (event='1') = param(age100)
  19. param(StartVert)
  20. param(NumVert) / dist=binomial;
  21. run;
  22. ods output close;
  23. data have;
  24. set pes;
  25. parameter =coalescec(parameter, variable);
  26. level =coalescec(classval0, level1);
  27. parameter =catx(' ', parameter, level);
  28. if scan(parameter, 2) in (' ', '0') and parameter ~='Scale';
  29. keep _proc_ parameter Estimate StdErr;
  30. run;
复制代码
The results
_1.PNG
JingJu

已有 1 人评分经验 收起 理由
eijuhz + 20 精彩帖子

总评分: 经验 + 20   查看全部评分

使用道具

7
moonstone 发表于 2014-12-17 08:44:54 |只看作者 |坛友微信交流群
jingju11 发表于 2014-12-17 05:50
Thanks. As you mentioned, logistic model can be viewed as a special case from generalized linear m ...
非常感谢老师的回复,之前为什么我的程序中出来三个结果不一样,主要是因为选择的class变量分层太多,所以模型无法很好收敛。老师生成的新的class变量,保证了三个模型都能很好收敛。所以也就是说,只有在按照class变量分层后,各层样本量相对充足的情况下,保证模型能够充分收敛,三者才能取得理论上一致的结果。
另外,上述讨论的是三者之间的一致性,我已经相对比较明白,但是如果genmod只是能构建logisitic回归相同的模型,那genmod与logisitic回归在处理二分类结局变量资料上又有什么区别呢,也就是genmod相对于logisitic回归在处理二分类结局变量资料上又有什么优势呢。谢谢老师指点。

使用道具

8
jingju11 发表于 2014-12-17 09:14:42 |只看作者 |坛友微信交流群
moonstone 发表于 2014-12-17 08:44
非常感谢老师的回复,之前为什么我的程序中出来三个结果不一样,主要是因为选择的class变量分层太多,所以 ...
Agree.

The more relevant reason for non-convergence here is because of data separation. This kind of data or model specification will cause computation matrix not stable or singular. for example, there is no inverse matrix available. you may observe this from an extremely large standard errors for estimated parameters. similar to 1/0.

Genmod covers many distributions from exponential family. Of note, Genmod provides GEE method that is for longitudinal data. Of course, PROC GEE is available at SAS/STAT 12.3, which may give more options.
JingJu

使用道具

9
moonstone 发表于 2014-12-17 10:30:53 |只看作者 |坛友微信交流群
jingju11 发表于 2014-12-17 09:14
Agree.

The more relevant reason for non-convergence here is because of data separation. This ki ...
谢谢,线性可分确实是logisitc回归使用的时候应该注意的问题。如果数据确实存在class变量导致的不收敛以及线性可分的问题,采用上述三种方法来分析二分类结局变量资料的影响因素时,是否都不合适?还是说除了简单地的变量变换外,还有其他的方法来处理此类问题?

使用道具

10
tangfever 发表于 2015-3-26 18:45:51 |只看作者 |坛友微信交流群
请问你这个平滑图是怎么画出来的呢?

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 19:40