Illustration of - fitting both a full random coefficient model as in Chapter 8 and a and modified random coefficient model with intercepts random and slopes fixed for the dental data using PROC MIXED. - obtaining BLUPs of random effects and random intercepts (and slopes where applicable) for both models. The model for each child is assumed to be a straight line. The intercepts and slopes may have different means depending on gender. However, for the modified model, slopes are taken to be the SAME for all children within each gender. This assumption is probably not true, but is made for illustrative purposes to show how such a model may be specified in PROC MIXED. For both models, we take D to be common to both genders and take Ri = sigma^2_G I for girls and Ri = sigma^2_B for boys using the REPEATED statement. We use the RANDOM statement to specify how random effects enter the model AND to ask for the BLUPs of the bi to be printed in each case. We also use an option in the MODEL statement to ask for the BLUPs of the individual means at each time point for each child. *******************************************************************/ options ls=80 ps=59 nodate; run; /****************************************************************** Read in the data set (See Example 1 of Chapter 4) *******************************************************************/ data dent1; infile 'dental.dat'; input obsno child age distance gender; run; /******************************************************************* Use PROC MIXED to fit the two linear mixed effects models. For all of the fits, we use usual normal ML rather than REML (the default). We call PROC MIXED twice to fit each model, for reasons described below. In all cases, we use the usual parameterization for the mean model. In the first call to PROC MIXED: The PREDICTED option in the MODEL statement requests that the (approximate) Best Linear Unbiased Predictors for the individual means at each time point in the data set for each child be printed (along with the original data for comparison). These are printed along with the actual observations. The SOLUTION option in the RANDOM statement requests that the (approximate) Best Linear Unbiased Predictors for the random effects bi be printed for each child. In the second call to PROC MIXED, we use the MAKE statement to produce data sets containing the fixed effects estimates and the BLUPs for the random effects. Use of a MAKE statement causes the results requested to not appear in the printed output; thus, had we used MAKE statements in the first call, these results would not have been printed. To fit the full random coefficient model, we must specify that both intercept and slope are random in the RANDOM statement. To fit the modified model where slopes are taken to be constant across all children within a gender, we specify only that intercept is random in the RANDOM statement. *******************************************************************/ * MODEL (i) -- full random coefficient model; * Call to PROC MIXED to get the printed results; title 'FULL RANDOM COEFFICIENT MODEL WITH BOTH'; title2 'INTERCEPTS AND SLOPES RANDOM FOR EACH GENDER'; proc mixed method=ml data=dent1; class gender child; model distance = gender gender*age / noint solution predicted; random intercept age / type=un subject=child solution; repeated / group=gender subject=child; run; /******************************************************************* The output data sets FIXED1 and RANDOM1 we ask PROC MIXED to create in the MAKE statements contain the estimated fixed effects (betahats) and random effects (the BLUPs of bis), respectively. We now combine these into a single data set in order to compute the BLUPs of the individual betais. This is accomplished by manipulating the output data sets and then merging them. *******************************************************************/ * Call to PROC MIXED to produce the output data sets; proc mixed method=ml data=dent1; class gender child; model distance = gender gender*age / noint solution; random intercept age / type=un subject=child solution ; repeated / group=gender subject=child; make 'SolutionF' out=fixed1 noprint; make 'SolutionR' out=rand1 noprint; run; data fixed1; set fixed1; keep gender _effect_ _est_; run; title3 'FIXED EFFECTS OUTPUT DATA SET'; proc print data=fixed1; run; proc sort data=fixed1; by gender; run; data fixed12; set fixed1; by gender; retain fixint fixslope; if _effect_='GENDER' then fixint=_est_; if _effect_='AGE*GENDER' then fixslope=_est_; if last.gender then do; output; fixint=.; fixslope=.; end; drop _effect_ _est_; run; title3 'RECONFIGURED FIXED EFFECTS DATA SET'; proc print data=fixed12; run; data rand1; set rand1; gender='1'; if child<12 then gender='0'; keep child gender _effect_ _est_; run; title3 'RANDOM EFFECTS OUTPUT DATA SET'; proc print data=rand1; run; proc sort data=rand1; by child; run; data rand12; set rand1; by child; retain ranint ranslope; if _effect_='INTERCEPT' then ranint=_est_; if _effect_='AGE' then ranslope=_est_; if last.child then do; output; ranint=.; ranslope=.; end; drop _effect_ _est_; run; proc sort data=rand12; by gender child; run; title3 'RECONFIGURED RANDOM EFFECTS DATA SET'; proc print data=rand12; run; data both1; merge fixed12 rand12; by gender; beta0i=fixint+ranint; beta1i=fixslope+ranslope; run; title3 'RANDOM INTERCEPTS AND SLOPES'; proc print data=both1; run; * MODEL (ii) -- common slope within each gender; * Call to PROC MIXED to get the printed results; * To save space, we do not print the predicted values; title 'MODIFIED RANDOM COEFFICIENT MODEL WITH'; title2 'INTERCEPTS RANDOM, SLOPES FIXED'; proc mixed method=ml data=dent1; class gender child; model distance = gender gender*age / noint solution ; random intercept / type=un subject=child solution; repeated / group=gender subject=child; run; * Call to PROC MIXED to get the output data sets; proc mixed method=ml data=dent1; class gender child; model distance = gender gender*age / noint solution; random intercept / type=un subject=child solution; repeated / group=gender subject=child; make 'SolutionF' out=fixed2 noprint; make 'SolutionR' out=rand2 noprint; run; data fixed2; set fixed2; keep gender _effect_ _est_; run; title3 'FIXED EFFECTS OUTPUT DATA SET'; proc print data=fixed2; run; proc sort data=fixed2; by gender; run; data fixed22; set fixed2; by gender; retain fixint fixslope; if _effect_='GENDER' then fixint=_est_; if _effect_='AGE*GENDER' then fixslope=_est_; if last.gender then do; output; fixint=.; fixslope=.; end; drop _effect_ _est_; run; title3 'RECONFIGURED FIXED EFFECTS DATA SET'; proc print data=fixed22; run; data rand2; set rand2; gender='1'; if child<12 then gender='0'; keep child gender _effect_ _est_; run; title3 'RANDOM EFFECTS OUTPUT DATA SET'; proc print data=rand2; run; proc sort data=rand2; by child; run; data rand22; set rand2; by child; retain ranint ranslope; if _effect_='INTERCEPT' then ranint=_est_; if last.child then do; output; ranint=.; end; drop _effect_ _est_; run; proc sort data=rand22; by gender child; run; title3 'RECONFIGURED RANDOM EFFECTS DATA SET'; proc print data=rand22; run; data both2; merge fixed22 rand22; by gender; beta0i=fixint+ranint; beta1i=fixslope; run; title3 'RANDOM INTERCEPTS AND FIXED SLOPES'; proc print data=both2; run;