1. Home
  2. ANOVA Contrasts Example

ANOVA Contrasts Example

Sometimes there may be comparisons between the levels of a treatment factor that you are particularly keen to assess. In this case you can test the significance of these individual comparisons using contrasts. This section gives an example of this using a randomized field trial with two factors, nitrogen (N) with levels of 0, 180 and 230 kg/ha, and sulphur (S) with levels of 0, 10, 20 and 40 kg/ha. The trial is laid out in randomized blocks with 3 replicates. The variate analysed is the yield of wheat in tonnes/ha.

For example, you might have had an initial suspicion that there would be little difference between the 180 and 230 levels of nitrogen, but similar (and larger) differences between 0 and 180, and between 0 and 230. You might then want to fit a single mean for the 180 and 230 levels of nitrogen, and assess the contrast between this value and the mean for level 0. 

  1. To define contrasts like these, import your data then from the menu select 
    Stats | Analysis of Variance | General.
  2. Click the Contrasts button to open the ANOVA Contrasts dialog.

In the following example we have selected Two-way ANOVA (in Randomized Blocks) in the Design field of the Analysis of Variance menu

The Contrast factor and Contrast type fields set to N and 1 respectively, indicate that we want to assess comparisons between the levels of the factor N, and the Number of contrasts field indicates that we want to fit one contrast.

When we click OK, a Genstat spreadsheet opens containing the contrast matrix Cont whose name was specified in the Contrast matrix field; this name was selected automatically by the ANOVA Contrasts menu, but you can specify your own name if you prefer, or if you have already formed a suitable matrix. You use the spreadsheet to specify the coefficients that define the comparison. In the Figure below the matrix defines the comparison: N0 vs (N180 + N230)/2.

Notice that you can also define names for the contrasts, using the Rows column. Back in the Analysis of Variance menu in the Treatment 2 field we now have a function of N, namely COMP(N;1;Cont). There is a box controlling the printing of contrasts in the Display section of the ANOVA Options menu. If we check this together with the AOV table field then click OK in the ANOVA Options and main Analysis of Variance dialogs, the output below appears.

Analysis of variance
====================

Variate: yield

Source of variation     d.f.       s.s.       m.s.    v.r.  F pr.

block stratum              2    0.30850    0.15425    3.44

block.*Units* stratum
S                          3    0.97720    0.32573    7.27  0.001
N                          2    4.59223    2.29611   51.22  <.001
  0 versus 180 and 230     1    4.54954    4.54954  101.48  <.001
S.N                        6    0.64851    0.10808    2.41  0.061
  S.0 versus 180 and 230
                           3    0.59907    0.19969    4.45  0.014
Residual                  22    0.98625    0.04483

Total                     35    7.51269


Tables of contrasts
===================

Variate: yield

block.*Units* stratum
---------------------

N contrasts
-----------

0 versus 180 and 230    0.754   s.e. 0.0749    ss.div. 8.00

S.N contrasts
-------------

S.0 versus 180 and 230   e.s.e. 0.150   ss.div. 2.00

        S     0.00    10.00    20.00    40.00
             -0.35    -0.18     0.21     0.32

Notice that, in the analysis of variance table, the line for the main effect N is now accompanied by a line entitled “0 versus 180 and 230” giving the degrees of freedom, sum of squares and so on for that comparison. In addition the N.S interaction is accompanied by a line “S.0 versus 180 and 230” which represents the interaction between the comparison and the factor S (that is, it measures how the size of the comparison varies according to the level of S). The section headed “Tables of contrasts” then shows the estimate of the contrast, 0.754, with standard error 0.0749.

The “spreadsheet. div” value is analogous to the replication of a table of means or effects: it is the divisor used in calculating the estimated values of the contrasts. This is useful mainly where there is a range of e.s.e.s for a table of contrasts: the contrasts with the smallest values of the spreadsheet. div. are those with the largest e.s.e., and vice versa. (The spreadsheet. div. of each estimated contrast is in fact the sum of squares of the values of the coefficients used to calculate it, weighted according to the replication.) The S.N contrasts table shows have the overall value of the contrast varies according to the level of S. So, at level 0 of S, the estimated contrast is 0.754 0.35. When a factor like sulphur (or nitrogen) has quantitative levels, you might want to investigate whether the yield increases linearly with the amount of sulphur (or nitrogen); you could also include a quadratic term to check for curvature in the response. You can fit polynomial contrasts like these by selecting Polynomial within the Contrast type field in the ANOVA Contrasts menu. If we set the Contrast factor to S and the Number of contrasts to 2, the Treatment 1 field of the Analysis of Variance dialog will contain the function POL(S;2). If we change the setting of the Treatment 2 field back to N then click OK, we obtain the output below.

 

Analysis of variance
====================

Variate: yield

Source of variation     d.f.       s.s.       m.s.    v.r.  F pr.

block stratum              2    0.30850    0.15425    3.44

block.*Units* stratum
S                          3    0.97720    0.32573    7.27  0.001
  Lin                      1    0.69741    0.69741   15.56  <.001
  Quad                     1    0.19577    0.19577    4.37  0.048
  Deviations               1    0.08403    0.08403    1.87  0.185
N                          2    4.59223    2.29611   51.22  <.001
S.N                        6    0.64851    0.10808    2.41  0.061
  Lin.N                    2    0.52294    0.26147    5.83  0.009
  Quad.N                   2    0.07788    0.03894    0.87  0.433
  Deviations               2    0.04769    0.02385    0.53  0.595
Residual                  22    0.98625    0.04483

Total                     35    7.51269


Tables of contrasts
===================

Variate: yield

block.*Units* stratum
---------------------

S contrasts
-----------

Lin    0.0094   s.e. 0.00239   ss.div. 7875.

Quad -0.00042   s.e. 0.000199  ss.div. 1131429.

Deviations   e.s.e. 0.0706   ss.div. 9.00

        S     0.00    10.00    20.00    40.00
            -0.028    0.074   -0.055    0.009

S.N contrasts
-------------

Lin.N   e.s.e. 0.00413   ss.div. 2625.

        N     0.00   180.00   230.00
           -0.0115   0.0058   0.0058

Quad.N   e.s.e. 0.000345   ss.div. 377143.

        N     0.00   180.00   230.00
           0.00028 -0.00035  0.00007

Deviations   e.s.e. 0.122   ss.div. 3.00

        S        N     0.00   180.00   230.00
     0.00             -0.02     0.03     0.00
    10.00              0.06    -0.07     0.01
    20.00             -0.05     0.05    -0.01
    40.00              0.01    -0.01     0.00

In the analysis of variance, the sum of squares for sulphur is partitioned into the amount that can be explained by a linear relationship of the yields with sulphur (the line marked Lin), the extra amount that can be explained if the relationship is quadratic (the line Quad), and the amount represented by deviations from a quadratic polynomial. A cubic term would be labelled as Cub, and a quartic as Quart. You are not allowed to fit more than fourth-order polynomials. The interaction of nitrogen and sulphur is also partitioned: Lin.N lets you assess the effect of fitting three different linear relationships, one for each level of nitrogen; Quad.N assesses the effect of fitting a different quadratic contrast for each level of N; and the deviations line represents deviations from these quadratic polynomials.

So, the analysis shows strong evidence for linear and quadratic effects of sulphur, and for interactions between these contrasts and nitrogen. The tables of contrasts again provide estimates of the parameters of the contrasts. For example, the overall linear effect is 0.0094, and the effect for level 0 of nitrogen is 0.0094-0.0115.

You can fit more than one set of contrasts at a time. If we had retained the nitrogen comparison, we would have obtained the output below.

 

Analysis of variance
====================

Variate: yield

Source of variation     d.f.       s.s.       m.s.    v.r.  F pr.

block stratum              2    0.30850    0.15425    3.44

block.*Units* stratum
S                          3    0.97720    0.32573    7.27  0.001
  Lin                      1    0.69741    0.69741   15.56  <.001
  Quad                     1    0.19577    0.19577    4.37  0.048
  Deviations               1    0.08403    0.08403    1.87  0.185
N                          2    4.59223    2.29611   51.22  <.001
  0 versus 180 and 230     1    4.54954    4.54954  101.48  <.001
S.N                        6    0.64851    0.10808    2.41  0.061
  Lin.0 versus 180 and 230
                           1    0.52294    0.52294   11.67  0.002
  Quad.0 versus 180 and 230
                           1    0.04448    0.04448    0.99  0.330
  Dev.0 versus 180 and 230
                           1    0.59907    0.59907   13.36  0.001
Residual                  22    0.98625    0.04483

Total                     35    7.51269


Tables of contrasts
===================

Variate: yield

block.*Units* stratum
---------------------

S contrasts
-----------

Lin    0.0094   s.e. 0.00239   ss.div. 7875.

Quad -0.00042   s.e. 0.000199  ss.div. 1131429.

Deviations   e.s.e. 0.0706   ss.div. 9.00

        S     0.00    10.00    20.00    40.00
            -0.028    0.074   -0.055    0.009

N contrasts
-----------

0 versus 180 and 230    0.754   s.e. 0.0749    ss.div. 8.00

S.N contrasts
-------------

Lin.0 versus 180 and 230    0.0173   s.e. 0.00506   ss.div. 1750.

Quad.0 versus 180 and 230 -0.00042   s.e. 0.000422  ss.div. 251429.

Dev.0 versus 180 and 230   e.s.e. 0.150   ss.div. 2.00

        S     0.00    10.00    20.00    40.00
             -0.35    -0.18     0.21     0.32

The interaction between nitrogen and sulphur is now partitioned according to the nitrogen comparison: “Lin.0 versus 180 and 230” lets you assess the effect of fitting two different linear relationships, one for each level 0 of nitrogen, and one for levels 180 and 230 of nitrogen, instead of a single overall linear contrast; “Quad.0 versus 180 and 230” represents two different quadratic contrasts; and Dev.0 versus 180 and 230 assess how the deviations from these two quadratic polynomials differ between the 0 level of nitrogen and the 180 and 230 levels.

So you can define contrasts on any treatment factor, and Genstat will automatically estimate their interactions. To fit polynomial contrasts, Genstat calculates orthogonal polynomials and does a multiple regression of the effects of factor using the polynomials as x-variates. Regression contrasts are similar to polynomial contrasts, except that here you can supply your own matrix of x-variates. Genstat orthogonalizes the x-variates for you, so that each one represents the effect adding this x-variable to a model containing all the earlier ones.

 

See also

Updated on July 13, 2023

Was this article helpful?