楼主: Silence.
9064 19

[问答] 关于零膨胀负二项回归模型用SAS实现? [推广有奖]

11
Silence. 发表于 2012-9-27 22:04:33
jingju11 发表于 2012-9-26 09:49
把所有的在zeromodel的自变量去掉即可。我的看法,应用同样的自变量组合,无论在model还是zeromodel,是比较 ...
jingju,P本身符合常数分布?这句如何理解。为什么网上的例子都是用相同的协变量,对于model和zeromodel可以引入不同的协变量吗?如果这样,关于各自协变量的选择又改如何?望指教!

12
jingju11 发表于 2012-9-28 02:58:00
both questions are yes

13
Silence. 发表于 2012-9-29 20:41:21
jingju11 发表于 2012-9-25 08:42
略微补充一下:
在sas新近的版本里,proc genmod也包含0-inflated 模型(poisson 和nb)。如果使用sas9.3, ...
Jingju,想请教你一段代码。我看你博客写的,然后按你写的编了下。
但proc countreg和proc nlmixed求解参数估计结果不一样,不知道是哪里出错了?
更奇怪的是当P和协变量不相关时,P为常数时,两个过程得到的结果是一样的。

/*-- Zero-Inflated Negative Binomial Model */
proc countreg data=clmfreq  covest=hessian  method=nra;
model CLM_FREQ=new_CAR_USE new_MARRIED new_DENSITY new_INCOME  new_GENDER/ dist=ZINB;
zeromodel CLM_FREQ ~new_CAR_USE new_MARRIED new_DENSITY new_INCOME  new_GENDER /link=logistic;
run;

/*--Proc Nlmixed--*/
proc nlmixed data=clmfreq;
parms b0=0 b1=0 b2=0 b3=0 b4=0 b5=0 a0=0 a1=0 a2=0 a3=0 a4=0 a5=0 infprinfl=0 k=1;
infprinfl= a0+a1*new_CAR_USE+        a2*new_MARRIED+a3*new_DENSITY+a4*new_INCOME+a5* new_GENDER;
infprob=1/(1+exp(-infprinfl));
linp=b0+b1*new_CAR_USE+        b2*new_MARRIED+b3*new_DENSITY+b4*new_INCOME+b5* new_GENDER;
mu=exp(linp);
p=1/(1+mu*k);
ll=(CLM_FREQ=0)*(log(infprob+(1-infprob)*pdf('negbinomial',CLM_FREQ,p,1/k)))+
     (CLM_FREQ^=0)*(log(1-infprob)+log(pdf( 'negbinomial',CLM_FREQ,p,1/k)));
model  CLM_FREQ~general(ll);
predict exp(ll) out=nb0Out(keep=CLM_FREQ pred);
run;

14
jingju11 发表于 2012-9-30 00:59:26
Silence. 发表于 2012-9-29 20:41
Jingju,想请教你一段代码。我看你博客写的,然后按你写的编了下。
但proc countreg和proc nlmixed求解参 ...
what i can see is, initiating  infprinfl =0 in PARMS statement was not correct.Remove it.
as my understanding, countreg uses no distinct nonlinear optimaztion methods as proc nlmixed does. so, you can expect same results, at least similiar.
i don't have sas/ets so i cannot check countreg. years ago, my sas indeed contained ETS but now it is not accessible to me.
hopefully it is helpful. jingju

15
Silence. 发表于 2012-9-30 18:29:04
jingju11 发表于 2012-9-30 00:59
what i can see is, initiating  infprinfl =0 in PARMS statement was not correct.Remove it.
as my ...
我把 infprinfl =0去掉了,但出现
WARNING: The final Hessian matrix is full rank but has at least one negative eigenvalue.
                Second-order optimality condition violated
而且结果和countreg结果还是不一样。(ZIP的countreg和nlmixed结果却是一样的)

16
jingju11 发表于 2012-9-30 22:58:08
yeah. 我的建议是不要过分简单化的给定初始值.比如全是0等等.靠近真实值或许可以避免一些计算上的问题.JINGJU

17
抢车位贴条号 发表于 2012-10-1 06:55:41
二楼正解

18
Silence. 发表于 2012-10-1 18:25:05
jingju11 发表于 2012-9-30 22:58
yeah. 我的建议是不要过分简单化的给定初始值.比如全是0等等.靠近真实值或许可以避免一些计算上的问题.JING ...
谢谢你的回复!我将初始值给定为countreg结果,算出的结果很接近。但是仍然有WARNING: The final Hessian matrix is full rank but has at least one negative eigenvalue.Second-order optimality condition violated。这样的做法可靠吗?我设置别的初始值算的结果相差就会大一点,请问我该如何知道初始值?

19
jingju11 发表于 2012-10-2 10:54:02
initiating logk =0.001;
set k =exp(logk);
set qpoints =1 at nlmixed model.

that is what i can think of, just have a try. jingju

20
xdzl2003 发表于 2012-12-6 10:14:44
我用上面的程序,操作不成功呀,哪位高手帮助写一下零堆积负二项回归sas程序呀,谢谢呀
等待

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 15:43