**********************************************************; * Using SAS to do a Latin square and extensions * Data from text (Box-Hunter-Hunter) p157-161, with * Latin square assignments from the bottom of p161 * * Yield: A measure of automobile pollution * Factors and factor levels: * Cars 1 2 3 4 * Drivers I II III IV * Additives A B C D * * There is an additional factor for the Greco-Latin square: * Run al be ga de * * which are abbreviations for alpha beta gamma delta * * See the comments before the second data step in `twoway.sas' * for the syntax in the data step below **********************************************************; options ls=75 ps=60 nocenter pageno=1; title1 'EXAMPLES OF LATIN SQUARES'; title2 'CAR-POLLUTION EXAMPLE from Box-Hunter-Hunter p157-161'; data latin; input driver$ add1$ r1$ y1 add2$ r2$ y2 add3$ r3$ y3 add4$ r4$ y4; car=1; additv=add1; runn=r1; yy=y1; output; car=2; additv=add2; runn=r2; yy=y2; output; car=3; additv=add3; runn=r3; yy=y3; output; car=4; additv=add4; runn=r4; yy=y4; output; * These variables will not be used again and can be dropped * (although no harm is done by leaving them in); drop add1 r1 y1 add2 r2 y2 add3 r3 y3 add4 r4 y4; datalines; I A al 19 B be 24 C ga 23 D de 26 II B de 23 A ga 24 D be 19 C al 30 III C be 15 D al 14 A de 15 B ga 16 IV D ga 19 C de 18 B al 19 A be 16 run; **********************************************************; * DISPLAY THE DATA THAT WE HAVE JUST CREATED: **********************************************************; proc print; title3 'THE DATA AS SAS SEES IT'; var yy driver car additv runn; run; **********************************************************; * Do ANOVA analyses with P-values for significance for a * a basic two-way ANOVA, a 4x4 Latin square, and a 4x4 * Graeco-Latin square. The output is not exactly the same * as that in the text since, in the text, the Latin squares * for the second two ANOVAs are not the same. * * See `twoway.sas' for information about the syntax of `proc glm', * what to look for in the output, and for the purpose and syntax * of the statement * output r=Residuals p=Predicted * * A difference here is that the residuals and fitted values * are written to different datasets (along with the original data) * so that the residuals for the three models can be examined * together. * * NOTE: The simpler syntax * output r=Residuals p=Predicted * * is not stable: It adds these columns temporarily to the * current dataset, but they can disappear if there are * intervening SAS procedures with the same dataset. **********************************************************; proc glm data=latin; title3 'Two-Way ANOVA for Cars and Drivers'; classes car driver; model yy=car driver; means car driver; output out=twowaydat r=Residuals p=Predicted; run; proc glm data=latin; title3 'Latin Square (Car Driver Additive)'; classes car driver additv; model yy=car driver additv; means car driver additv; output out=latinsq r=Residuals p=Predicted; run; proc glm data=latin; title3 'Graeco-Latin Square (Car Driver Additive Run)'; classes car driver additv runn; model yy=car driver additv runn; means car driver additv runn; output out=graecosq r=Residuals p=Predicted; run; options ps=40; * Contract page height for nicer plots; proc plot dat=twowaydat; title4 'TWO-WAY ANOVA RESIDUAL PLOT'; title5 'No extreme outliers nor obvious departures'; title6 ' from model assumptions'; plot Residuals*Predicted='*'; run; proc plot dat=latinsq; title4 'LATIN SQUARE RESIDUAL PLOT'; title5 'No extreme outliers nor obvious departures'; title6 ' from model assumptions'; plot Residuals*Predicted='*'; run; proc plot dat=graecosq; title4 'GRAECO-LATIN SQUARE RESIDUAL PLOT'; title5 'No extreme outliers nor obvious departures'; title6 ' from model assumptions'; plot Residuals*Predicted='*'; run; options ps=60; * Restore page height to its usual value;