Section 6b: Contrasts and Estimates in ANOVA Contrasts are comparisons of mean values for which you specify the coefficients. Two related statements will be presented here that work very much alike, the CONTRAST and the ESTIMATE statements. In PROC MIXED the LSMEANS statement with the DIFF option computes all pairwise contrasts, differences of two lsmeans where the coefficients are 1 and -1 attached to the respective lsmeans of interest. The CONTRAST and ESTIMATE statements will also compute pairwise differences, though their real function is greater flexibility in making only the comparisons of two or more means that interest you. SAS requires that all contrasts be estimable functions. It is common to request a contrast and then get a missing value for the result because SAS identifies the contrast as not being an estimable function. The key to computing with contrasts is patience and being very methodical as to what components the CONTRAST and ESTIMATE statements actually require. Single Factor Contrasts The first example is to compute contrasts with 1 between subjects variable, group in this first example with 3 levels. PROC MIXED DATA=indat; CLASS group id; MODEL y = group; LSMEANS group / diff; RUN; The ANOVA output shows the group effect has 2 degrees of freedom. This implies there are two independent contrasts. A common interpretation is to compare the first two levels of group with the last: CONTRAST 'Group' group 1 0 -1, group 0 1 -1; You will see the F-test for this contrast is the same as the ANOVA results in the Type 3 table of fixed effects. The pairwise comparisons of means can be found as: ESTIMATE 'Group 1 - 2' group 1 -1 0; ESTIMATE 'Group 1 - 3' group 1 0 -1; ESTIMATE 'Group 2 - 3' group 0 1 -1; The ESTIMATE statements produce the same results as the LSMEANS statement above with the diff option. Interaction Contrasts The interaction terms from a multifactor ANOVA are commonly computed and when significant, provide the basis for how means are tested within one factor across levels of the other(s). For example, in a two-way ANOVA with both group (between) and condition (within) having 2 levels, an ANOVA is produced with PROC MIXED DATA=indat; CLASS group cond id; MODEL y = group cond group*cond; REPEATED cond / subject=id type=cs rcorr; RUN; The two hypotheses for testing the population means of a group*cond interaction are: HO: mu_gr1_cond1 - mu_gr1_cond2 == mu_gr2_cond1 - mu_gr2_cond2 HA: mu_gr1_cond1 - mu_gr1_cond2 ~= mu_gr2_cond1 - mu_gr2_cond2 That is, HO states the difference in the two condition means for group 1 is the _same_ as the difference observed in group 2; HA states they are _different_. The null hypothesis can also be written as: HO: (mu_gr1_cnd1 - mu_gr1_cnd2) - (mu_gr2_cnd1 - mu_gr2_cnd2) = 0 The placement of the two categorical variable names on the CLASS statement, how they are coded (single digit integers are preferred), and the coefficients in the hypothesis show how to compute the test for their interaction with an ESTIMATE statement (which is directly related to the subject of this page, the CONTRAST statement). Since group is first on the CLASS statement, its levels change slowest: Group: 1 1 2 2 OR Group: a a b b Cond: 1 2 1 2 Cond: c d c d With either coding scheme (the levels are interpred alphabetically by SAS), it is straightforward to set up statements to compute the actual differences in the two condition means for group 1 and group 2: ESTIMATE "Group 1: Cond_1 - Cond_2" cond 1 -1 group*cond 1 -1 0 0 ; ESTIMATE "Group 2: Cond_1 - Cond_2" cond 1 -1 group*cond 0 0 1 -1 ; For a 2x2 ANOVA the interaction contrast is the "difference" in these two ESTIMATE statements, that is, subtract the coefficients from the lower statement from the coefficients from the upper one: ESTIMATE "G1,G2: Cond_1-Cond_2 eq?" cond 0 0 group*cond 1 -1 -1 1 ; Having "cond 0 0" is meaningless, so it can be removed and the interaction contrast remains: ESTIMATE "G1,G2: Cond_1 - Cond_2 eq?" group*cond 1 -1 -1 1 ; This statement produces the same F test as the two-factor interaction in the ANOVA table. For designs having multiple independent variables with at least one having three or more levels, they are omnibus tests which refer to a set of very specific contrasts (actually many independent sets of contrasts are inferred) that are tested as if pre-planned. Contrasts are basically "simple" tests extracted from simpler global contrasts than the interaction terms of 2, 3, or more factors. The approach taken is partly done to increase power, following guidelines or examples set forth in "Contrasts and Effect Sizes in Behavioral Research" by Rosenthal, Rownow, and Rubin. Why would anyone want to choose specific contrasts, here is a quote from the first paragraph of Chapter 1, p. 1 from this reference: "Contrasts are statistical procedures for asking focused questions of data. Compared to ... omnibus questions, focused questions are characterized by greater conceptual clarity, and the statistical procedure by greater statistical power when examining those focused questions. That is, if an effect truly exists, we are more likely to discover it and to believe it to be real when asking focused questions rather than omnibus ones." The essence of the final sentence is to not base your statistical interpretive skills only on the 2-factor, 3-factor, or any higher order interaction from an ANOVA table (which has a rather diffuse or ominibus interpretation), but rather focus on the contrasts of greatest interest to you -- and of those, there are many. ... more details to follow