Model 3 with model checking

The code below can be used in any version of SAS to obtain the residual and normal plots. Following this alternative code using ODS GRAPHICS code available in SAS Version 9 will be given. Note that only the plots of centre and centre-treatment effects resulting from this code are shown in the text (Figures 2.6(a) and 2.7). Figures 2.5 and 2.6(a) result from the ODS GRAPHICS code given later.

PROC MIXED; CLASS centre treat;

MODEL dbp = dbp1 treat/ DDFM=KR OUTP=pred

OUTPM=predm;

RANDOM centre centre*treat/ SOLUTION;

LSMEANS treat/ DIFF PDIFF CL;

ODS LISTING EXCLUDE SOLUTIONR;

ODS OUTPUT SOLUTIONR=solut; RUN;

DATA solut; SET solut;

centrex=centre*1; * obtain numeric centre

variable;

DROP centre;

DATA c_est(KEEP=centre c_est) ct_est(KEEP=

centre treat

Ct_est); SET solut;

centre=centrex;

IF effect='centre' THEN DO;

c_est=estimate ;

OUTPUT c_est;

END;

ELSE DO; ct_est=estimate; OUTPUT ct_est; END;

PROC SORT DATA=ct_est; BY centre treat;

PROC SORT DATA=predm; BY centre treat;

DATA c_est; MERGE predm c_est; BY centre; PROC MEANS NOPRINT; BY centre; ID c_est; VAR pred; OUTPUT OUT=c_est MEAN=c_pred N=freq;

DATA ct_est; MERGE predm ct_est; BY centre treat; PROC MEANS NOPRINT; BY centre treat; ID ct_est; VAR pred; OUTPUT OUT=ct_est MEAN=ct_pred N=freq;

SYMBOL1 V=CIRCLE;

PROC GPLOT DATA=pred; PLOT resid*pred; TITLE 'RESIDUALS AGAINST THEIR PREDICTED VALUES'; PROC RANK DATA=pred OUT=norm NORMAL=TUKEY; VAR resid; RANKS s_est;

PROC GPLOT DATA=norm; PLOT resid*s_est; TITLE 'RESIDUALS - NORMAL PLOT';

PROC GPLOT DATA= c_est; PLOT c_est*c_pred; TITLE 'CENTRE EFFECTS AGAINST THEIR PREDICTED VALUES'; PROC RANK OUT=norm NORMAL=TUKEY DATA=c_est; VAR c_est; RANKS s_est;

PROC GPLOT DATA=norm; PLOT c_est*s_est; TITLE 'CENTRE EFFECTS - NORMAL PLOT';

PROC GPLOT DATA= ct_est; PLOT ct_est*ct_pred;

TITLE 'CENTRE.TREAT EFFECTS AGAINST THEIR PREDICTED VALUES'; PROC RANK OUT=norm NORMAL=TUKEY DATA= ct_est; VAR ct_est;

RANKS s_est; PROC GPLOT DATA=norm; PLOT ct_est*s_est; TITLE 'CENTRE.TREAT EFFECTS - NORMAL PLOT';

* CHECK HETEROGENEITY OF RESIDUAL AND CENTRE*TREAT VARIANCE

BY TREATMENT; PROC SORT DATA=pred; BY treat; PROC MEANS DATA=pred; VAR resid; BY treat;

TITLE 'PROC MEANS TO CHECK RESIDUAL VARIANCE IS HOMOGENEOUS ACROSS TREATMENTS';

PROC SORT DATA= ct_est; BY treat; PROC MEANS DATA= ct_est; VAR ct_est; BY treat; TITLE 'PROC MEANS TO CHECK CENTRE.TREAT EFFECT VARIANCE IS HOMOGENEOUS ACROSS TREATMENTS';

This code may not at first sight be straightforward to understand. The steps used are summarised below.

• Output the residuals and predicted values given by Xa + Z(3 to dataset pred using the OUTP option; output the predicted values given by Xa to dataset predm using the OUTPM option; output the random effects estimates to dataset solut using the SOLUTION option in the RANDOM statement and an ODS OUTPUT statement. Note that the ODS LISTING EXCLUDE statement cause the random effects to be excluded from the main PROC MIXED output.

• Create datasets c_est and ct_est containing random effects estimates for the centre and centre-treatment effects respectively.

• Merge datasets c_e s t and c t_e s t with the predicted values and calculate the mean predicted value within each random effects category.

• Print and plot the residuals and the centre and centre-treatment effect estimates.

• Calculate the standard deviations of the residuals and centre-treatment effects within each treatment group.

The output from PROC MIXED is identical to that given in Chapter 4 and the residual plots produced by this code were given earlier in this section.

Was this article helpful?

0 0

Post a comment