18

STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 2: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 3: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)

One-way ANOVA with 5 treatment groups

Showing ‘means’ and ‘LSMeans’ statement for lines diagram from pairwise comparisons tests.

Three EUs are randomly assigned to each treatment. This is a completely randomized design (CRD).

data mine;input group y;cards;1 121 171 132 222 242 253 183 173 204 174 214 205 305 295 32;

SAS code and output using ‘means’ statement:

/*Fit the 1-way ANOVA model and use the ‘means’ statement to get thetukey adjustment, plus get the lines diagram.*/

proc glm data=mine plot=diagnostics;class group;model y=group;means group/tukey lines; /* Don’t put "Adjust=..." in the ‘means’ statement.*/

run;

The GLM ProcedureDependent Variable: y

Sum ofSource DF Squares Mean Square F Value Pr > FModel 4 459.0666667 114.7666667 31.30 <.0001Error 10 36.6666667 3.6666667Corrected Total 14 495.7333333

1

Page 4: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

The GLM ProcedureTukey’s Studentized Range (HSD) Test for y

NOTE: This test controls the Type I experimentwise error rate, but itgenerally has a higher Type II error rate than REGWQ.

Alpha 0.05Error Degrees of Freedom 10Error Mean Square 3.666667Critical Value of Studentized Range 4.65429Minimum Significant Difference 5.1455

SAS code and output using ‘lsmeans’ statement:

/* You can get ‘lines’ diagram in LSmeans, but not Tukey HSD detailed information. */

proc glm data=mine;class group;model y=group;lsmeans group/adjust=tukey pdiff lines; /* Use "Adjust=..." in the ‘lsmeans’ statement.*/

run;

Least Squares Means for effect groupPr > |t| for H0: LSMean(i)=LSMean(j)

Dependent Variable: y

i/j 1 2 3 4 5

1 0.0008 0.1111 0.0415 <.00012 0.0008 0.0415 0.1111 0.01123 0.1111 0.0415 0.9648 0.00014 0.0415 0.1111 0.9648 0.00035 <.0001 0.0112 0.0001 0.0003

2

Page 5: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

You will also get a ‘Di↵ogram’ or ‘mean-mean scatter plot’:

The upward sloping 45-degree dashed line in the plotting area represents points of equality for two means;

that is, it shows how close the di↵erence of the two lsmeans is to 0. For this reason both axes have the same

length and scale and that all p means are not plotted on each axis, as the di↵erence of any mean with itself

is trivially 0 (you will see this point of intersection on the graph for the values of means that appear on both

axes).

A third axis (implied on the graph but not printed by ODS Graphics) runs at -45 degrees (from the

upper left corner of the plotting area to the lower right corner). This axis represents the magnitude of the

di↵erences of the lsmeans depicted on the other two axes scaled in such a way that the confidence interval

crosses the line of equality when the interval contains 0. It serves as the reference point for the di↵erences

between pairs of lsmeans and also gives the approximate values of the endpoints of the confidence interval.

Because these data are balanced, the estimated standard errors of all pairwise comparisons are identical,

and the widths of the line segments are the same. The labels of the grid lines indicate the ordering of the

least squares means

3

Page 6: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

Using an ODS output statement and some reformatting of the data, we can also create a plot that shows

the Tukey-adjusted simultaneously confidence intervals in perhaps an easier viewing framework.

proc glm data=mine plots=diagnostics;class Group;model y = Group;lsmeans Group / pdiff=all cl adjust=tukey;ods output LSMeanDiffCL=MeanDiff; /* optional: save mean differences and CIs */

quit;

proc print data=MeanDiff;run;

Obs Effect Dependent i j LowerCL Difference UpperCL group _group

1 group y 1 2 -14.812134 -9.666667 -4.521200 1 22 group y 1 3 -9.478800 -4.333333 0.812134 1 33 group y 1 4 -10.478800 -5.333333 -0.187866 1 44 group y 1 5 -21.478800 -16.333333 -11.187866 1 55 group y 2 3 0.187866 5.333333 10.478800 2 36 group y 2 4 -0.812134 4.333333 9.478800 2 47 group y 2 5 -11.812134 -6.666667 -1.521200 2 58 group y 3 4 -6.145467 -1.000000 4.145467 3 49 group y 3 5 -17.145467 -12.000000 -6.854533 3 5

10 group y 4 5 -16.145467 -11.000000 -5.854533 4 5

The data set MeanDi↵ above contains the estimated di↵erence between all means (10 pairwise comparisons)

and the upper and lower bounds for the 95% simultaneous confidence intervals. We then add some more

information to this dataset to create a data set called Intervals.

data Intervals; set MeanDiff;Pair = catx(’ - ’, Group, _Group); /* set-up label*/Significant = (0 < LowerCL | UpperCL < 0); /* is 0 not in interior of interval? */S = ifc(Significant, "Significant", "Not significant"); /* set-up label*/

run;

proc print data=Intervals;run;

4

Page 7: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

Use the Intervals data set to make a new plot.

title "Pairwise Difference of LSMeans (Tukey Adjustment)";title2 "95% Confidence Intervals of Mean Difference";footnote J=L "Pairs Whose Intervals Contain 0 Are Not Significantly Different";proc sgplot data=Intervals;

scatter y=Pair x=Difference / group=S name="CIs"xerrorlower=LowerCL xerrorupper=UpperCL;

refline 0 / axis=x;yaxis reverse colorbands=odd display=(nolabel)

offsetmin=0.06 offsetmax=0.06;keylegend "CIs" / sortorder=ascending;

run;

Notice that this matches the earlier summaries such that three of the pairwise comparisons were not signifi-

cant.

See: https://blogs.sas.com/content/iml/2017/10/18/di↵ogram-multiple-comparisons-sas.html

5

Page 8: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

NOTE: If the design is unbalanced, you need to be careful using the ‘lines’ graphic, but SAS

will automatically correctly apply the Tukey-Kramer adjustment.

Output from the ‘means’ statement when unbalanced:

NOTE: Cell sizes are not equal.

From the SAS documentation on ‘means’:

Performs Tukey’s studentized range test (HSD) on all main-e↵ect means in the MEANS statement.(When the group sizes are di↵erent, this is the Tukey-Kramer test.)

Output from the ‘LSMeans’ statement when unbalanced:

The GLM ProcedureLeast Squares MeansAdjustment for Multiple Comparisons: Tukey-Kramer

From the SAS documentation on ‘LSMeans’:

When you specify ADJUST=TUKEY and your data are unbalanced, PROC GLM uses the approxi-mation described in Kramer (1956) and identifies the adjustment as “Tukey-Kramer” in the results.

6

Page 9: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 10: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 11: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 12: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 13: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 14: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter

SAS statements and partial output for ‘means’ statement with REGWQ adjustment:

proc glm data=mine;class group;model y=group;means group/regwq;

run;

7

Page 15: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 16: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 17: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter
Page 18: STAT:5201 Applied Statistic II (1-way ANOVA with ‘lines’ graphic)homepage.divms.uiowa.edu/~rdecook/stat5201/notes/3-4...You will also get a ‘Di ogram’ or ‘mean-mean scatter