/************************************************************** Autism Data Analysis ***************************************************************/ PROC IMPORT OUT= WORK.autism DATAFILE= "C:\temp\autism.csv" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; data autism2; set autism; age_2 = age-2; age_2sq = age_2 * age_2; run; /*Descriptive Statistics*/ proc means data = autism maxdec = 2; class age; var vsae; run; proc means data = autism maxdec = 2; class sicdegp age; var vsae; run; proc freq data = autism; tables sicdegp*age / nocol nopercent; run; /*Trajectories of Each Child over time by SICDEGP*/ proc sort data=autism; by childid age; run; ods listing style = journal; ods listing sge = on; /*To edit graphs in SAS*/ proc sgpanel data = autism noautolegend; panelby sicdegp / columns = 3; series y=vsae x=age/group=childid; scatter y=vsae x=age / group=childid markerattrs=(symbol=circle); run; /*Mean Trajectories over time by SICDEGP*/ proc sort data=autism; by sicdegp age; run; proc means data=autism noprint; by sicdegp age; output out=meandat mean(vsae)=Mean_VSAE; run; data combine; merge autism meandat; by sicdegp age; run; proc sgpanel data = combine noautolegend; panelby sicdegp / columns = 3; series y=Mean_VSAE x=age / lineattrs=(thickness=3 color=black); scatter y=vsae x=age / group=childid markerattrs=(color=black symbol=circle); run; /************************************************************** Fit Models using Proc Glimmix ***************************************************************/ /*NOTE: Estimated G matrix is not positive definite.*/ title "Model 6.1"; proc glimmix data=autism2; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random int age_2 age_2sq / subject=childid type=un g v solution; run; /* We can use this approach to diagnose the problem with the G matrix seen in Model 6.1. Estimated Variance of the random intercept is negative (-10.55) in the G matrix for this model*/ title "Model 6.1 (nobound option)"; proc glimmix data=autism2 nobound; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random int age_2 age_2sq / subject=childid type=un g v solution; run; /*Model 6.2. Test Hypothesis 6.1: Removal of RE of age_2sq */ title "Model 6.2"; proc glimmix data=autism2 ; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un g; covtest "Hypothesis 6.1" general 0 0 1 0, 0 1 0 0 / est; run; /************************************************************* Reduce Fixed Effects (FE) in the Model **************************************************************/ /*Model 6.2: Includes all FE*/ title "Model 6.2 (ML)"; proc glimmix data=autism2 noreml; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /*Model 6.3: Remove FE of Age_2sq*sicdegrp*/ title "Model 6.3 (ML)"; proc glimmix data=autism2 noreml; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /****************************************************** LRT of Hypothesis 6.2: Compare -2LL of Model 6.3 (nested) vs. 6.2 (reference) Both models fit using ML *******************************************************/ title "P-value for Hypothesis 6.2"; data _null_; lrstat = 4612.3 - 4610.4; df = 2; pvalue = 1 - probchi(lrstat,df); put lrstat= df= pvalue= ; run; /*Model 6.4: Remove FE of age_2*sicdegp*/ title "Model 6.4 (ML)"; proc glimmix data=autism2 noreml; class childid sicdegp; model vsae = age_2 age_2sq sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /********************************************************* LRT of Hypothesis 6.3: Compare -2LL of Model 6.4 (nested) vs. 6.3 (reference) Both models fit using ML **********************************************************/ title "P-value for Hypothesis 6.3"; data _null_; lrstat = 4635.7 - 4612.3; df = 2; pvalue = 1 - probchi(lrstat,df); put lrstat= df= pvalue= ; run; /*Model 6.3: Final Model with Diagnostics*/ title "Final Model 6.3 (REML)"; ods output solutionR = eblup_dat; ods exclude solutionR; proc glimmix data = autism2 plots =(residualpanel(blup) studentpanel(blup) boxplot(student blup)); class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution ddfm=sat; random age_2 age_2sq /subject = childid solution g v vcorr type=un; output out = diagnostic_dat pred(blup) = p_cond resid(blup) = r_cond student(blup) = s_cond pred(noblup)=p_marg resid(noblup)=r_marg student(noblup)=s_marg; run; /*Plot of Marginal Predicted Values for Each level of SICDEGP*/ proc sort data=diagnostic_dat; by sicdegp age; run; proc sgplot data=diagnostic_dat; series x=age y=p_marg / group=sicdegp; keylegend / location=inside position=topleft border down=3; yaxis label="Marginal Predicted VSAE"; xaxis label="Age (Years)"; run; /*Plot of Marginal Predicted Values and Conditional Predicted Values vs. Age for First 12 Children*/ proc sort data=diagnostic_dat(where=(sicdegp=3)) out=child_dat; by childid age; run; proc freq data=child_dat; tables childid; run; proc sgpanel data=child_dat(where=(childid <=51)); panelby childid / columns=4; series x=age y=p_marg; series x=age y=p_cond; run; /*Plot of Conditional Predicted Values and Actual VSAE vs. Age for First 12 Children*/ proc sgpanel data=child_dat(where=(childid <=51)); panelby childid / columns=4; series x=age y=p_cond; series x=age y=vsae; run; /*Alternative: Completely Marginal Model with Unstructured R Matrix using Proc Glimmix.*/ title "Marginal Model w/ Unstructured Covariance Matrix"; proc glimmix data=autism2 noclprint; class childid sicdegp age; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution; random age / subject=childid type=un residual v vcorr; run; /***************************************************** Fit Models using Proc Mixed ******************************************************/ /*Model 6.1: Loaded Mean Model*/ /*NOTE: Estimated G matrix is not positive definite.*/ title "Model 6.1"; proc mixed data=autism2 covtest; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random int age_2 age_2sq / subject=childid type=un g v solution; run; title "Model 6.1 (nobound option)"; proc mixed data=autism2 covtest nobound; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random int age_2 age_2sq / subject=childid type=un g v solution; run; /*Model 6.2: Random Intercept Removed*/ title "Model 6.2"; proc mixed data=autism2 covtest; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un g; run; /*Model 6.2A: RE of age_2sq removed*/ title "Model 6.2A"; proc mixed data=autism2 covtest; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random age_2 / subject=childid type=un g; run; /************************************************************ LRT comparing Model 6.2A(nested) vs 6.2 (reference) both models fit using REML Mixture of Chi-squares *************************************************************/ title "P-value for Hypothesis 6.1"; data _null_; lrstat = 4699.2 - 4615.3; pvalue = 0.5*(1-probchi(lrstat,1)) + 0.5*(1-probchi(lrstat,2)); format pvalue 10.8; put "Mixture Chi-square(1:2) " lrstat= pvalue= ; run; /***************************************************** Reduce Fixed Effects (FE) in the Model ******************************************************/ /*Model 6.2 ML: Has all FE in the model*/ title "Model 6.2 (ML)"; proc mixed data=autism2 covtest method = ML; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp age_2sq*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /*Model 6.3: Remove FE of age_2sq*sicdegp*/ title "Model 6.3 (ML)"; proc mixed data=autism2 covtest method = ML; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /****************************************************** LRT of Hypothesis 6.2: Compare -2LL of Model 6.3 (nested) vs. 6.2 (reference) Both models fit using ML *******************************************************/ title "P-value for Hypothesis 6.2"; data _null_; lrstat = 4612.3 - 4610.4; df = 2; pvalue = 1 - probchi(lrstat,df); put lrstat= df= pvalue= ; run; /*Model 6.4: Remove FE of age_2*sicdegp*/ title "Model 6.4 (ML)"; proc mixed data=autism2 method=ml; class childid sicdegp; model vsae = age_2 age_2sq sicdegp / solution ddfm=sat; random age_2 age_2sq / subject=childid type=un; run; /********************************************************* LRT of Hypothesis 6.3: Compare -2LL of Model 6.4 (nested) vs. 6.3 (reference) Both models fit using ML **********************************************************/ title "P-value for Hypothesis 6.3"; data _null_; lrstat = 4635.7 - 4612.3; df = 2; pvalue = 1 - probchi(lrstat,df); put lrstat= df= pvalue= ; run; /********************************************************* Model 6.3: Final Model with Diagnostics **********************************************************/ title "Final Model 6.3 (REML)"; ods output influence=inf_dat solutionR=eblup_dat; ods exclude influence solutionR; proc mixed data = autism2 covtest; class childid sicdegp; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution ddfm=sat influence; random age_2 age_2sq / subject = childid solution g v vcorr type = un; run; /********************************************************* Alternative Approach: Strictly Marginal Model **********************************************************/ title "Marginal Model w/ Unstructured Covariance Matrix"; proc mixed data=autism2 noclprint covtest; class childid sicdegp age influence; model vsae = age_2 age_2sq sicdegp age_2*sicdegp / solution; repeated age / subject=childid type=un r rcorr; run;