- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 50278 个
- 通用积分
- 83.5106
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
Multilevel Logistic Regression using SAS
- /* Simple model */
- /* Ignoring within child dependency */
- proc genmod data=respire descending;
- model resp = age /link=logit dist=bin type3 ;
- output out=preds pred=fitted;
- title 'Simple Model ignoring repeated measures';
- run;
- /* Simple Model: GEE */
- proc genmod data=respire descending;
- class id ;
- model resp = age /link=logit dist=bin type3 ;
- repeated subject=id / type=exch;
- title 'Simple Model GEE (exchangable)';
- run;
- /* Compute fitted probabilities to graph*/
- data preds;
- lambda=-2.3436 ;
- lamAge=-0.0248;
- do age = -40 to 50 by .5;
- psimple = exp(lambda + lamAge*Age)/(1+ exp(lambda + lamAge));
- pnoinf = 1-psimple;
- id=1;
- output;
- end;
- run;
- goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
- hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
- goptions device=WIN ctext=blue
- graphrc interpol=join;
- axis1 color=blue width=2.0 label=('Age in Months') ;
- axis2 color=blue width=2.0 label=(angle=90 'Fitted Probability of Infection')
- order=0 to 1 by .1;
- axis3 color=blue width=2.0 label=(angle=90 'Fitted Probability of NO Infection')
- order=0 to 1 by .1;
- proc gplot data=WORK.PREDS;
- plot psimple * age / haxis=axis1 vaxis=axis2 frame ;
- title 'Probability of Infection';
- run;
- proc gplot data=WORK.PREDS;
- plot pnoinf * age / haxis=axis1 vaxis=axis2 frame ;
- title 'Probability of NO Infection';
- run;
- /* Complex model */
- /* Ignoring within child dependency */
- proc genmod data=respire descending;
- class xero(descending) female(descending) stunted(descending);
- model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
- title 'Complex Model ignoring repeated measures';
- run;
- /* Complex Model: GEE */
- proc genmod data=respire descending;
- class id xero(descending) female(descending) stunted(descending);
- model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
- repeated subject=id / type=exch corrw;
- title 'Complex Model GEE (exchangable)';
- run;
- /* Complex Model: GEE */
- proc genmod data=respire descending;
- class id xero(descending) female(descending) stunted(descending);
- model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
- repeated subject=id / type=unstr corrw;
- title 'Complex Model GEE (unstructured)';
- run;
- /* Subject specific model */
- /* Simple */
- proc nlmixed data=respire qpoints=10; *<- I am starting in a good place so 10 should do it;
- parms lam=-2.3 bAge=0.02 tau0= 0.8; *<- starting values from GEE;
- eta = lam + bAge*Age + u; *<- linear predictor;
- p = exp(eta)/(1 + exp(eta)); *<- probabiliy;
- model resp ~ binary(p);
- random u ~ normal(0, tau0*tau0) subject=id out=ebuR;
- estimate 'Var(Uo)' tau0**2;
- estimate 'odds ratio' exp(bAge);
- title 'Random Intercept, Simple Model';
- run;
- proc glimmix data=respire method=mmpl gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: Default estimation method';
- run;
- proc glimmix data=respire method=rmpl gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: RMPL';
- run;
- proc glimmix data=respire method=mspl gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: mSPL';
- run;
- proc glimmix data=respire method=rspl gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: mSPL';
- run;
- proc glimmix data=respire method=laplace gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: laPlace';
- run;
- proc glimmix data=respire method=quad gradient noclprint;
- class id ;
- model resp = age / solution link=logit dist=bin;
- random intercept / subject=id;
- title 'Random Intercept, Simple Model: QUAD';
- run;
- data random;
- set ebuR;
- u = estimate;
- lam=-2.6130;
- bAge=-0.02676;
- do age=-40 to 50 by .5;
- pperson = exp(lam + bAge*age + u)/(1+exp(lam + bAge*age + u));
- output;
- end;
- run;
- goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
- hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
- goptions device=WIN ctext=blue
- graphrc interpol=join;
- axis1 color=blue width=2.0 label=('Age in Months') ;
- axis2 color=blue width=2.0 label=(angle=90 'Fitted Probability of Infection')
- order=0 to .5 by .1;
- axis3 color=blue width=2.0 label=(angle=90 'Fitted Probability of NO Infection')
- order=0 to .5 by .1;
- legend1 position=(top left inside) label=none frame cshadow=pink
- value=('Ignoring dependency' 'GEE (exchangable)');
- proc gplot data=random;
- plot pperson*age=id / overlay haxis=axis1 vaxis=axis2 frame nolegend;
- title 'Probability of Infection';
- run;
- data predtwo;
- /* From nlmixed */
- lam=-2.6130;
- bAge=-0.02676;
- /* From gendmode using GEE */
- lambda= -2.3355;
- lamAge= -0.0243;
- do age= -40 to 50 by .5;
- pGEE = exp(lambda + lamAge*Age)/(1+exp(lambda+lamAge*age));
- pperson = exp(lam + bAge*age)/(1+exp(lam + bAge*age ));
- pnoGEE= 1-pGEE;
- pnoperson = 1 -pperson;
- id=1;
- output;
- end;
- run;
- proc sort data=preds; by age;
- proc sort data=predGEE; by age;
- data tmp;
- merge preds predtwo;
- by age;
- pnosimple=1-psimple;
- run;
- goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
- hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
- goptions device=WIN ctext=blue
- graphrc interpol=join;
- axis1 color=blue width=2.0 label=('Age in Months') ;
- axis2 color=blue width=2.0 label=(angle=90 'Fitted Probability of Infection')
- order=0 to 1 by .1;
- axis3 color=blue width=2.0 label=(angle=90 'Fitted Probability of NO Infection')
- order=0 to 1 by .1;
- legend1 position=(top left inside) label=none frame cshadow=pink
- value=('Ignoring dependency' 'GEE (exchangable)' 'Random effects');
- legend2 position=(bottom left inside) label=none frame cshadow=pink
- value=('Ignoring dependency' 'GEE (exchangable)' 'Random effects');
- proc gplot data=tmp;
- plot psimple*age pGEE*age pperson*age/ overlay haxis=axis1 vaxis=axis2 frame legend=legend1;
- title 'Probability of Infection';
- run;
- proc gplot data=tmp;
- plot pnosimple*age pnoGEE*age pnoperson*age/ overlay haxis=axis1 vaxis=axis3 frame legend=legend2;
- title 'Probability of No Infection';
- run;
- /* Complex */
- proc nlmixed data=respire method=gauss qpoints=10;
- parms lam=-2.42 bAge=-.03 bxero=0.6 bfemale=-.42 bcos=-.6 bsin=-.2 bheight=-.05
- bstunt=0.15 sigma= 0.1;
- eta = lam + bAge*Age + bxero*xero + bfemale*female + bcos*cosine + bsin*sine
- + bheight*height + bstunt*stunted + u;
- p = exp(eta)/(1 + exp(eta));
- model resp ~ binary(p);
- random u ~ normal(0, sigma*sigma) subject=id;
- title 'Random Intercept, Complex Model';
- estimate 'exp(bAge)' exp(bAge);
- estimate 'exp(bxero)' exp(bxero);
- estimate 'exp(bfemale)' exp(bfemale);
- estimate 'exp(bcosine)' exp(bcos);
- estimate 'exp(bheight)' exp(eheight);
- estimate 'exp(bstunt)' exp(bstunt);
- estimate 'var(u)' sigma**2;
- run;
- proc glimmix data=respire method=quad gradient noclprint;
- class id;
- model resp = age xero female cosine sine height stunted / link=logit dis=binary solution;
- random intercept / subject=id;
- run;
复制代码
respirtory.zip
(12.62 KB)
本附件包括:
|
|