*EXAMPLE 1: Basic GLMM with Categorical Treatment; DATA multicenter; input center group$ n SideEffect @@; datalines; 1 A 32 14 1 B 33 18 2 A 30 4 2 B 28 8 3 A 23 14 3 B 24 9 4 A 22 7 4 B 22 10 5 A 20 6 5 B 21 12 6 A 19 1 6 B 20 3 7 A 17 2 7 B 17 6 8 A 16 7 8 B 15 9 9 A 13 1 9 B 14 5 10 A 13 3 10 B 13 1 11 A 11 1 11 B 12 2 12 A 10 1 12 B 9 0 13 A 9 2 13 B 9 6 14 A 8 1 14 B 8 1 15 A 7 1 15 B 8 0 ; PROC PRINT data=multicenter; DATA multicenter; set multicenter; Prop_SideEffect = SideEffect/n; PROC SGPLOT data=multicenter; vbox Prop_SideEffect /group=group; PROC SGPLOT data=multicenter; vbox Prop_SideEffect/ group=center; PROC GLIMMIX data=multicenter; class group; model SideEffect/n = group /solution; PROC GLIMMIX data=multicenter; class center group; model SideEffect/n = group / solution; random center; PROC GLIMMIX data=multicenter; *same as above; class center group; model SideEffect/n = group / solution; random intercept / subject=center; *random intercept; lsmeans group / ilink cl; ods output LSMeans=lsm1; PROC PRINT data=lsm1; PROC SGPLOT data=lsm1; vbarparm category=group response=Mu / limitlower=LowerMu limitupper=UpperMu; /* PROC GLIMMIX data=multicenter; *same as above; class center group; model SideEffect/n = group / solution; random group/subject=center; *random slope; PROC GLIMMIX data=multicenter; *same as above; class center group; model SideEffect/n = group / solution; random intercept group/subject=center; *random slope and intercept; */ *==========================================================================================================; *EXAMPLE 2: Basic GLMM with Multiple Treatments; DATA npk; input block $ N $ P $ K $ yield; *Use “$” for characters; cards; 1 0 1 1 49.5 1 1 1 0 62.8 1 0 0 0 46.8 1 1 0 1 57.0 2 1 0 0 59.8 2 1 1 1 58.5 2 0 0 1 55.5 2 0 1 0 56.0 3 0 1 0 62.8 3 1 1 1 55.8 3 1 0 0 69.5 3 0 0 1 55.0 4 1 0 0 62.0 4 1 1 1 48.8 4 0 0 1 45.5 4 0 1 0 44.2 5 1 1 0 52.0 5 0 0 0 51.5 5 1 0 1 49.8 5 0 1 1 48.8 6 1 0 1 57.2 6 1 1 0 59.0 6 0 1 1 53.2 6 0 0 0 56.0 ; PROC PRINT data=npk; PROC SGPLOT data=npk; histogram yield; PROC SORT data=npk; by N; PROC SGPLOT data=npk; vbox yield /group=N; PROC SORT data=npk; by P; PROC SGPLOT data=npk; vbox yield /group=P; PROC SORT data=npk; by K; PROC SGPLOT data=npk; vbox yield /group=K; PROC SGPLOT data=npk; vbox yield /category=block; PROC GLIMMIX data=npk plots=all; class N P K; model yield=N|P|K /solution; PROC GLIMMIX data=npk plots=all; class N P K block; model yield=N|P|K /solution; random block; lsmeans N K / cl; ods output LSMeans=lsm2; PROC PRINT data=lsm2; PROC SGPLOT data=lsm2; vbarparm category=N response=Estimate / limitlower=Lower limitupper=Upper; PROC SGPLOT data=lsm2; vbarparm category=K response=Estimate / limitlower=Lower limitupper=Upper; *==========================================================================================================; *EXAMPLE 3: GLMM with Random Slopes; DATA rc; input Batch Month @@; Monthc = Month; do i = 1 to 6; input Y @@; output; end; datalines; 1 0 101.2 103.3 103.3 102.1 104.4 102.4 1 1 98.8 99.4 99.7 99.5 . . 1 3 98.4 99.0 97.3 99.8 . . 1 6 101.5 100.2 101.7 102.7 . . 1 9 96.3 97.2 97.2 96.3 . . 1 12 97.3 97.9 96.8 97.7 97.7 96.7 2 0 102.6 102.7 102.4 102.1 102.9 102.6 2 1 99.1 99.0 99.9 100.6 . . 2 3 105.7 103.3 103.4 104.0 . . 2 6 101.3 101.5 100.9 101.4 . . 2 9 94.1 96.5 97.2 95.6 . . 2 12 93.1 92.8 95.4 92.2 92.2 93.0 3 0 105.1 103.9 106.1 104.1 103.7 104.6 3 1 102.2 102.0 100.8 99.8 . . 3 3 101.2 101.8 100.8 102.6 . . 3 6 101.1 102.0 100.1 100.2 . . 3 9 100.9 99.5 102.2 100.8 . . 3 12 97.8 98.3 96.9 98.4 96.9 96.5 ; PROC PRINT data=rc; PROC SGPLOT data=rc; histogram Y; PROC SGPLOT data=rc; scatter X=Month Y=Y; PROC SGPLOT data=rc; scatter X=Month Y=Y / group=Batch; PROC GLIMMIX data=rc plots=all; model Y = Month /dist=Gaussian s; PROC GLIMMIX data=rc plots=all; model Y = Month /dist=Poisson s; PROC GLIMMIX data=rc plots=all; model Y = Month /dist=Negbinomial s; PROC GLIMMIX data=rc plots=all; class Batch; model Y = Month / s; random Int /sub=Batch s; PROC GLIMMIX data=rc plots=all; class Batch; model Y = Month / s; random Int Month / type=un sub=Batch s; /* 102.70-0.3735=102.3265 102.70-0.6303=102.0697 102.70+1.0038=103.7038 */ PROC SGPLOT data=rc; scatter X=Month Y=Y/ group=Batch; lineparm x=0 y=102.70 slope=-0.5259/lineattrs=(pattern=ShortDash color=black); /** intercept, slope **/ lineparm x=0 y=102.3265 slope=-0.5259/lineattrs=(color=blue); lineparm x=0 y=102.0697 slope=-0.5259/lineattrs=(color=red); lineparm x=0 y=103.7038 slope=-0.5259/lineattrs=(color=green); PROC SGPLOT data=rc; scatter X=Month Y=Y/ group=Batch; lineparm x=0 y=102.70 slope=-0.5259/lineattrs=(pattern=ShortDash color=black); /** intercept, slope **/ lineparm x=0 y=101.699 slope=-0.3972/lineattrs=(color=blue); lineparm x=0 y=103.0934 slope=-0.7319/lineattrs=(color=red); lineparm x=0 y=103.3076 slope=-0.44859/lineattrs=(color=green); *==========================================================================================================; *EXAMPLE 4: GLMM with Nested Effects; PROC IMPORT datafile='/home/markwilliamson20/my_courses/briandarby0/biometrydatasets/wings.csv' dbms=csv out=wings replace; getnames=yes; PROC PRINT data=wings; PROC SGPLOT data=wings; histogram Wingsize; PROC SGPLOT data=wings; vbox Wingsize /category=Class group=Sex groupdisplay=cluster; PROC SGPLOT data=wings; vbox Wingsize /category=Class group=Block groupdisplay=cluster; *Response - Wingsize *Bookkepping - Individual Day *Fixed - Block Class Sex *Random - Site Month; PROC SORT data=wings; by Class Sex Block Site Pot Month; PROC GLIMMIX data=wings order=data plots=all; class Sex; model Wingsize = Sex/s dist=normal; PROC GLIMMIX data=wings order=data plots=all; class Sex Site Pot; model Wingsize = Sex/s dist=normal; random Site Pot(Site) /s; PROC GLIMMIX data=wings order=data plots=all; class Class Sex Block Site Pot; model Wingsize = Class|Sex/s dist=normal; random Site Pot(Site) /s; PROC GLIMMIX data=wings order=data plots=all; class Class Sex Block Site Pot Month; model Wingsize = Class|Sex|Block /s dist=normal; random Site Pot(Site) Month /s; lsmeans Class*Block Sex*Block / cl; ods output LSMeans=lsm3; PROC SGPLOT data=lsm3; vbarparm category=Class response=Estimate / group=Block groupdisplay=cluster limitlower=Lower limitupper=Upper; PROC SGPLOT data=lsm3; vbarparm category=Sex response=Estimate / group=Block groupdisplay=cluster limitlower=Lower limitupper=Upper;