楼主: Trevor
2667 8

Lecture Notes: Multilevel Analysis/Hierarchical Linear Modeling [推广有奖]

  • 1关注
  • 4粉丝

已卖:1100份资源

副教授

26%

还不是VIP/贵宾

-

TA的文库  其他...

Probability NewOccidental

RapidMiner NewOccidental

Machine Learning

威望
1
论坛币
3509 个
通用积分
0.7297
学术水平
25 点
热心指数
17 点
信用等级
24 点
经验
5225 点
帖子
412
精华
2
在线时间
176 小时
注册时间
2005-5-4
最后登录
2024-4-7

楼主
Trevor 发表于 2013-12-14 02:31:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

Multilevel Analysis/Hierarchical Linear Modeling

Edpsych/Psych/Stat 587

C.J. Anderson

Fall 2013





http://courses.education.illinois.edu/edpsy587/



二维码

扫码加我 拉你入群

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

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

关键词:Hierarchical Multilevel Modeling Analysis Analysi

本帖被以下文库推荐

沙发
spaceknight79 发表于 2013-12-14 03:15:06
谢谢分享!
天南地北

藤椅
Nicolle 学生认证  发表于 2016-7-2 21:30:44
提示: 作者被禁止或删除 内容自动屏蔽

板凳
Nicolle 学生认证  发表于 2016-7-2 21:32:26

Random Intercept Models using SAS

提示: 作者被禁止或删除 内容自动屏蔽

报纸
Nicolle 学生认证  发表于 2016-7-2 21:35:02

Random Intercept and Slope Models using SAS

提示: 作者被禁止或删除 内容自动屏蔽

地板
Nicolle 学生认证  发表于 2016-7-2 21:37:49

Simulating Data from A Random Intercept Model With 2 Levels using SAS

提示: 作者被禁止或删除 内容自动屏蔽

7
Lisrelchen 发表于 2016-7-2 21:42:20

SAS for Marginal Modeling of Depression Data

  1. proc sort;
  2. by case diagnose treat time outcome;

  3. data tmp1 tmp2 tmp3;
  4. set depress;
  5. if time=0 then output tmp1;
  6. else if time=1 then output tmp2;
  7. else if time=2 then output tmp3;
  8. data tmp1a;
  9. set tmp1;
  10. if outcome=0 then Y1='A';
  11. else if outcome=1 then Y1='N';
  12. drop outcome;
  13. run;
  14. proc sort data=tmp1a; by case ;
  15. data tmp2a;
  16. set tmp2;
  17. if outcome=0 then Y2='A';
  18. else if outcome=1 then Y2='N';
  19. drop outcome;
  20. proc sort data=tmp1a; by case ;
  21. data tmp3a;
  22. set tmp3;
  23. if outcome=0 then Y3='A';
  24. else if outcome=1 then Y3='N';
  25. drop outcome;
  26. proc sort data=tmp1a; by case ;

  27. data Table11_2;
  28. merge tmp1a tmp2a tmp3a;
  29. by case ;
  30. /*
  31. if Y1='N' then do;
  32.      if Y2='N' then do;
  33.        if Y3='N' then Y='NNN';
  34.            else Y='NNA';
  35.          end;
  36.          else do;
  37.            if Y3='N' then Y='NAN';
  38.            else Y='NAA';
  39.          end;
  40. end;
  41. else do;
  42.       if Y2='N' then do;
  43.        if Y3='N' then Y='ANN';
  44.            else Y='ANA';
  45.          end;
  46.          else do;
  47.            if Y3='N' then Y='AAN';
  48.            else Y='AAA';
  49.          end;
  50. end;*/
  51. run;



  52. proc freq ;
  53. tables diagnose*treat*Y1*y2*y3/ nopercent norow nocol list sparse;
  54. run;

  55. proc genmod descending data=depress;  
  56.   model outcome = diagnose treat time treat*time / dist=bin link=logit type3;
  57.   title 'MLE ignoring repeated aspect of the data';
  58. run;

  59. proc logistic descending data=depress;
  60. model outcome = diagnose treat time treat*time / Lackfit ;
  61. run;

  62. proc genmod descending data=depress;  
  63.   class case;
  64.   model outcome = diagnose treat time treat*time / dist=bin link=logit type3;
  65.   repeated subject=case / type=exch corrw corrb;
  66.   title 'GEE with Exchangable';
  67. run;


  68. proc genmod descending data=depress;  
  69.   class case;
  70.   model outcome = diagnose treat time treat*time / dist=bin link=logit type3;
  71.   repeated subject=case / type=AR(1) corrw;
  72.   title 'GEE with AR(1)';
  73. run;


  74. proc genmod descending data=depress;  
  75.   class case;
  76.   model outcome = diagnose treat time treat*time / dist=bin link=logit type3;
  77.   repeated subject=case / type=unstr corrw;
  78.   title 'GEE with Unstructured';
  79. run;


  80. proc nlmixed  data=depress qpoints=20;
  81.   parms alpha=-.03 beta1=-1.3 beta2=-.06 beta3=.48 beta4=1.02 sigma=.01;   
  82.   eta = alpha + beta1*diagnose + beta2*treat + beta3*time + beta4*treat*time + u;
  83.   p = exp(eta)/(1 + exp(eta));
  84.   model outcome ~ binary(p);
  85.   random u ~ normal(0, sigma*sigma) subject = case;
  86.   estimate 'var(U_o)' sigma**2;
  87.   title 'Results from nlmixed';
  88. run;

  89. proc nlmixed  data=depress qpoints=20;
  90.   parms alpha=-.03 beta1=-1.3 beta2=-.06 beta3=.48 beta4=1.02 ;   
  91.   eta = alpha + beta1*diagnose + beta2*treat + beta3*time + beta4*treat*time ;
  92.   p = exp(eta)/(1 + exp(eta));
  93.   model outcome ~ binary(p);
  94.   title 'Results from nlmixed; w/o random';
  95. run;

  96. proc glimmix data=depress gradient method=RSPL;
  97. class case ;
  98. model outcome = diagnose treat time treat*time /dist=bin link=logit solution;
  99. random intercept / subject=case;
  100. title 'How about GLIMMIX?';
  101. run;

  102. proc glimmix data=depress;
  103. class case ;
  104. model outcome = diagnose treat time treat*time /dist=bin link=logit solution;
  105. title 'How about GLIMMIX? without random';
  106. run;
复制代码
Longitudinal_depression.zip (3.4 KB) 本附件包括:
  • Longitudinal_depression.sas

8
Lisrelchen 发表于 2016-7-2 22:02:54

Multilevel Logistic Regression using SAS

  1. /* Simple model */

  2. /* Ignoring within child dependency */
  3. proc genmod data=respire descending;
  4. model resp = age /link=logit dist=bin type3 ;
  5. output out=preds pred=fitted;
  6. title 'Simple Model ignoring repeated measures';
  7. run;

  8. /* Simple Model:  GEE */
  9. proc genmod data=respire descending;
  10. class id ;
  11. model resp = age /link=logit dist=bin type3 ;
  12. repeated subject=id  / type=exch;
  13. title 'Simple Model GEE (exchangable)';
  14. run;

  15. /* Compute fitted probabilities to graph*/
  16. data preds;
  17. lambda=-2.3436 ;
  18. lamAge=-0.0248;
  19. do age = -40 to 50 by .5;
  20.   psimple = exp(lambda + lamAge*Age)/(1+ exp(lambda + lamAge));
  21.   pnoinf = 1-psimple;
  22.   id=1;
  23.   output;
  24. end;
  25. run;

  26. goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
  27.          hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
  28. goptions device=WIN  ctext=blue
  29.          graphrc interpol=join;
  30. axis1   color=blue   width=2.0  label=('Age in Months')  ;
  31. axis2   color=blue   width=2.0  label=(angle=90 'Fitted Probability of Infection')
  32.   order=0 to 1 by .1;
  33. axis3   color=blue   width=2.0  label=(angle=90 'Fitted Probability of NO Infection')
  34.   order=0 to 1 by .1;
  35. proc gplot data=WORK.PREDS;
  36.    plot psimple * age / haxis=axis1 vaxis=axis2 frame ;
  37.    title 'Probability of Infection';
  38. run;

  39. proc gplot data=WORK.PREDS;
  40.    plot pnoinf * age / haxis=axis1 vaxis=axis2 frame ;
  41.    title 'Probability of NO Infection';
  42. run;

  43. /* Complex model */
  44. /* Ignoring within child dependency */
  45. proc genmod data=respire descending;
  46. class xero(descending) female(descending) stunted(descending);
  47. model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
  48. title 'Complex Model ignoring repeated measures';
  49. run;






  50. /* Complex Model: GEE */
  51. proc genmod data=respire descending;
  52. class id xero(descending) female(descending) stunted(descending);
  53. model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
  54. repeated subject=id  / type=exch corrw;
  55. title 'Complex Model GEE (exchangable)';
  56. run;

  57. /* Complex Model: GEE */
  58. proc genmod data=respire descending;
  59. class id xero(descending) female(descending) stunted(descending);
  60. model resp = age xero female cosine sine height stunted /link=logit dist=bin type3 ;
  61. repeated subject=id  / type=unstr corrw;
  62. title 'Complex Model GEE (unstructured)';
  63. run;


  64. /* Subject specific model */
  65. /* Simple */


  66. proc nlmixed data=respire qpoints=10;   *<- I am starting in a good place so 10 should do it;
  67.   parms lam=-2.3 bAge=0.02 tau0= 0.8;  *<- starting values from GEE;
  68.   eta = lam + bAge*Age + u;             *<- linear predictor;
  69.   p = exp(eta)/(1 + exp(eta));          *<- probabiliy;
  70.   model resp ~ binary(p);
  71.   random u ~ normal(0, tau0*tau0) subject=id out=ebuR;
  72.   estimate 'Var(Uo)' tau0**2;
  73.   estimate 'odds ratio' exp(bAge);
  74.   title 'Random Intercept, Simple Model';
  75. run;

  76. proc glimmix data=respire method=mmpl gradient noclprint;
  77. class id ;
  78. model resp = age / solution link=logit dist=bin;
  79. random intercept / subject=id;
  80. title 'Random Intercept, Simple Model: Default estimation method';
  81. run;

  82. proc glimmix data=respire  method=rmpl gradient noclprint;
  83. class id ;
  84. model resp = age / solution link=logit dist=bin;
  85. random intercept / subject=id;
  86. title 'Random Intercept, Simple Model: RMPL';
  87. run;


  88. proc glimmix data=respire  method=mspl gradient noclprint;
  89. class id ;
  90. model resp = age / solution link=logit dist=bin;
  91. random intercept / subject=id;
  92. title 'Random Intercept, Simple Model: mSPL';
  93. run;



  94. proc glimmix data=respire  method=rspl gradient noclprint;
  95. class id ;
  96. model resp = age / solution link=logit dist=bin;
  97. random intercept / subject=id;
  98. title 'Random Intercept, Simple Model: mSPL';
  99. run;

  100. proc glimmix data=respire method=laplace gradient noclprint;
  101. class id ;
  102. model resp = age / solution link=logit dist=bin;
  103. random intercept / subject=id;
  104. title 'Random Intercept, Simple Model: laPlace';
  105. run;

  106. proc glimmix data=respire method=quad gradient noclprint;
  107. class id ;
  108. model resp = age / solution link=logit dist=bin;
  109. random intercept / subject=id;
  110. title 'Random Intercept, Simple Model:  QUAD';
  111. run;

  112. data random;
  113. set ebuR;
  114. u = estimate;
  115. lam=-2.6130;
  116. bAge=-0.02676;
  117. do age=-40 to 50 by .5;
  118.    pperson = exp(lam + bAge*age + u)/(1+exp(lam + bAge*age + u));
  119.    output;
  120. end;
  121. run;


  122. goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
  123.          hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
  124. goptions device=WIN  ctext=blue
  125.          graphrc interpol=join;
  126. axis1   color=blue   width=2.0  label=('Age in Months')  ;
  127. axis2   color=blue   width=2.0  label=(angle=90 'Fitted Probability of Infection')
  128.   order=0 to .5 by .1;
  129. axis3   color=blue   width=2.0  label=(angle=90 'Fitted Probability of NO Infection')
  130.   order=0 to .5 by .1;
  131. legend1 position=(top left inside) label=none frame cshadow=pink
  132.         value=('Ignoring dependency' 'GEE (exchangable)');
  133. proc gplot data=random;
  134.    plot pperson*age=id / overlay haxis=axis1 vaxis=axis2 frame nolegend;
  135.    title 'Probability of Infection';
  136. run;


  137. data predtwo;
  138. /* From nlmixed */
  139. lam=-2.6130;
  140. bAge=-0.02676;
  141. /* From gendmode using GEE */
  142. lambda= -2.3355;
  143. lamAge= -0.0243;
  144. do age= -40 to 50 by .5;
  145.   pGEE = exp(lambda + lamAge*Age)/(1+exp(lambda+lamAge*age));
  146.   pperson = exp(lam + bAge*age)/(1+exp(lam + bAge*age ));
  147.   pnoGEE= 1-pGEE;
  148.   pnoperson = 1 -pperson;
  149.   id=1;
  150.   output;
  151. end;
  152. run;

  153. proc sort data=preds; by age;
  154. proc sort data=predGEE; by age;

  155. data tmp;
  156. merge preds predtwo;
  157. by age;
  158. pnosimple=1-psimple;
  159. run;


  160. goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate
  161.          hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= ;
  162. goptions device=WIN  ctext=blue
  163.          graphrc interpol=join;
  164. axis1   color=blue   width=2.0  label=('Age in Months')  ;
  165. axis2   color=blue   width=2.0  label=(angle=90 'Fitted Probability of Infection')
  166.   order=0 to 1 by .1;
  167. axis3   color=blue   width=2.0  label=(angle=90 'Fitted Probability of NO Infection')
  168.   order=0 to 1 by .1;
  169. legend1 position=(top left inside) label=none frame cshadow=pink
  170.         value=('Ignoring dependency' 'GEE (exchangable)' 'Random effects');
  171. legend2 position=(bottom left inside) label=none frame cshadow=pink
  172.         value=('Ignoring dependency' 'GEE (exchangable)' 'Random effects');

  173. proc gplot data=tmp;
  174.    plot psimple*age pGEE*age pperson*age/ overlay haxis=axis1 vaxis=axis2 frame legend=legend1;
  175.    title 'Probability of Infection';
  176. run;

  177. proc gplot data=tmp;
  178.    plot pnosimple*age pnoGEE*age pnoperson*age/ overlay haxis=axis1 vaxis=axis3 frame legend=legend2;
  179.    title 'Probability of No Infection';
  180. run;



  181.    /* Complex  */


  182. proc nlmixed data=respire method=gauss qpoints=10;   
  183.   parms lam=-2.42 bAge=-.03 bxero=0.6 bfemale=-.42 bcos=-.6 bsin=-.2 bheight=-.05
  184.         bstunt=0.15 sigma= 0.1;  
  185.   eta = lam + bAge*Age + bxero*xero + bfemale*female + bcos*cosine + bsin*sine
  186.         + bheight*height + bstunt*stunted +  u;            
  187.   p = exp(eta)/(1 + exp(eta));         
  188.   model resp ~ binary(p);
  189.   random u ~ normal(0, sigma*sigma) subject=id;
  190.   title 'Random Intercept, Complex Model';
  191.   estimate 'exp(bAge)' exp(bAge);
  192.   estimate 'exp(bxero)' exp(bxero);
  193.   estimate 'exp(bfemale)' exp(bfemale);
  194.   estimate 'exp(bcosine)' exp(bcos);
  195.   estimate 'exp(bheight)' exp(eheight);
  196.   estimate 'exp(bstunt)'  exp(bstunt);
  197.   estimate 'var(u)'  sigma**2;

  198. run;


  199. proc glimmix data=respire method=quad gradient noclprint;
  200. class id;
  201. model resp = age xero female cosine sine height stunted / link=logit dis=binary solution;
  202. random intercept / subject=id;
  203. run;
复制代码
respirtory.zip (12.62 KB) 本附件包括:
  • respirtory.sas

9
utaschen 发表于 2017-5-7 20:59:11
谢谢分享!

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-5 23:43