***Generalized Linear Mixed Models for Everything SAS Code****; *Part 1: t-tests; *Class dataset; PROC PRINT data=sashelp.Class; PROC TTEST data=sashelp.Class; class Sex; var Height; PROC GLIMMIX data=sashelp.Class; class Sex; model Height=Sex /solution dist=normal; lsmeans Sex /cl; ods output LSmeans=Class_lsm; PROC SGPLOT data=Class_lsm; vbarparm category=Sex response=Estimate/limitupper=Upper limitlower=Lower; *========================================================================================================================================; *Part 2: ANOVA; *1997 Birth Weight Data dataset; PROC PRINT data=sashelp.bweight(obs=25); PROC ANOVA data=sashelp.bweight; class MomEdLevel; model Weight=MomEdLevel; means MomEdLevel; PROC GLIMMIX data=sashelp.bweight; class MomEdLevel; model Weight=MomEdLevel/solution dist=normal; lsmeans MomEdLevel / cl; ods output LSMeans=Bweight_lsm; PROC SGPLOT data=Bweight_lsm; vbarparm category=MomEdLevel response=Estimate/limitupper=Upper limitlower=Lower; *========================================================================================================================================; *Part 3: Linear regression; *Body Mass Index for Men; PROC PRINT data=sashelp.bmimen(obs=25); PROC REG data=sashelp.bmimen; model BMI=age; PROC GLIMMIX data=sashelp.bmimen; model BMI=age/solution dist=normal; output out=Bmimen_pred pred lcl ucl; PROC SGPLOT data=Bmimen_pred; band x=age lower=lcl upper=ucl; scatter x=age y=BMI; series x=age y=Pred; *========================================================================================================================================; *Part 4: Logistic regression; *2003 Birth Weight Data; PROC PRINT data=sashelp.birthwgt(obs=25); PROC LOGISTIC data=sashelp.birthwgt; class Married AgeGroup Race; model LowBirthWgt(Event='Yes')=Married AgeGroup Race; PROC GLIMMIX data=sashelp.birthwgt; class Married AgeGroup Race; model LowBirthWgt(Event='Yes')=Married AgeGroup Race / solution dist=binary oddsratio; *========================================================================================================================================; *Part 5: Poisson regression; *Days Absent (from https://stats.idre.ucla.edu/sas/output/poisson-regression/); *days absent during the school year (daysabs); *math standardized tests score (mathnce) *language standardized tests score (langnce) *gender (female); DATA absent; set "/home/markwilliamson20/my_courses/markwilliamson0/MW_Datasets_2020/poisson.sas7bdat"; female = (gender = 1); PROC PRINT data=absent(obs=25); PROC GENMOD data=absent; model daysabs=mathnce langnce female / link=log dist=Poisson; PROC GLIMMIX data=absent; model daysabs=mathnce langnce female /solution dist=Poisson; *========================================================================================================================================; *Part 6: Linear mixed models; *Split-Plot (from https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statug_mixed_examples01.htm&locale=en); *variable A is the whole-plot factor; *variable B is the subplot factor; DATA sp; input Block A B Y @@; datalines; 1 1 1 56 1 1 2 41 1 2 1 50 1 2 2 36 1 3 1 39 1 3 2 35 2 1 1 30 2 1 2 25 2 2 1 36 2 2 2 28 2 3 1 33 2 3 2 30 3 1 1 32 3 1 2 24 3 2 1 31 3 2 2 27 3 3 1 15 3 3 2 19 4 1 1 30 4 1 2 25 4 2 1 35 4 2 2 30 4 3 1 17 4 3 2 18 ; PROC PRINT data=sp; PROC MIXED data=sp; class A B Block; model Y = A B A*B; random Block A*Block/solution; PROC GLIMMIX data=sp; class A B Block; model Y = A B A*B; random Block A*Block/solution; *========================================================================================================================================; *Part 7: GLMM; *multicenter (from https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/196-30.pdf); 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; PROC GLIMMIX data=multicenter; class center group; model SideEffect/n = group / solution; random center; lsmeans group / ilink cl; ods output LSMeans=lsm1; PROC SGPLOT data=lsm1; vbarparm category=group response=Mu / limitlower=LowerMu limitupper=UpperMu;