DM 'LOG; CLEAR; OUT; CLEAR;'; ODS GRAPHICS ON; ODS PRINTER PDF file='C:\COURSES\ST541\BOXCOX.PDF'; OPTIONS NODATE NONUMBER; ********************************************; *** Variance Stabilizing Transformations ***; ********************************************; DATA in; INPUT trt y @@; CARDS; 1 5 1 1 1 3 1 5 1 2 1 6 1 1 1 3 2 13 2 13 2 6 2 7 2 11 2 4 2 14 2 12 3 12 3 16 3 9 3 18 3 16 3 7 3 14 3 13 4 17 4 13 4 16 4 19 4 26 4 15 4 23 4 27 5 22 5 30 5 27 5 32 5 32 5 43 5 29 5 26 **********************************************************; *** Find the transformation using the empirical method ***; **********************************************************; PROC SORT DATA=in; BY trt; PROC MEANS DATA=in NOPRINT; BY trt; VAR y; OUTPUT OUT=yset MEAN=mean STD=std; DATA yset; SET yset; logstd =LOG(std); logmean=LOG(mean); PROC PRINT DATA=yset; VAR mean std logstd logmean; TITLE 'EMPIRICAL SELECTION OF ALPHA'; PROC GLM DATA=yset; MODEL logstd=logmean / SS3 solution; TITLE 'ANOVA TO FIND EMPIRICAL SELECTION OF ALPHA'; *** Use the output of the GLM procedure regressing the ***; *** log standard deviations on the log means. Apply the ***; *** Apply the transformation to the response and ***; *** rerun the analysis with the transformed response. ***; ********************************************************; *** Find the transformation using the Box-Cox method ***; ********************************************************; PROC TRANSREG DATA=in; MODEL BOXCOX(y / LAMBDA=-2 to 2 by .1) = CLASS(trt); TITLE 'Find the Box-Cox Transformation using PROC TRANSREG'; *** Use the output of the TRANSREG procedure to find the ***; *** the Box-Cox transformation. Apply the transformation ***; *** to the response and rerun the analysis with the ***; *** transformed response ***; *************************************; *** ANOVA BEFORE A TRANSFORMATION ***; *************************************; PROC GLM DATA=in PLOTS=(DIAGNOSTICS); CLASS trt; MODEL y = trt / SS3; MEANS trt ; TITLE 'ANOVA -- ORIGINAL DATA'; *************************************; *** ANOVA AFTER A TRANSFORMATION ***; *************************************; DATA in; SET in;; sqrty = SQRT(y); PROC GLM DATA=in PLOTS=(DIAGNOSTICS); CLASS trt; MODEL sqrty = trt / SS3; MEANS trt; TITLE 'ANOVA -- SQUARE ROOT TRANSFORMATION'; RUN;