Return-Path: <ECOOCH@PENNSAS.UPENN.EDU>
Newsgroups: bit.listserv.sas-l
Date:         Thu, 16 Apr 1992 21:11:37 EST
Reply-To:     Evan Cooch <ECOOCH@PENNSAS.UPENN.EDU>
From:         Evan Cooch <ECOOCH@PENNSAS.UPENN.EDU>
Subject:      slopes/CONTRAST/ESTIMATE and GLM
Comments: To: sas-l%marist.bitnet%cunyvm.cuny.edu@NOC2.DCCS.UPENN.EDU,
              stat-l%mcgill1.bitnet%cornellc.ccs.cornell.edu
              @NOC2.DCCS.UPENN.EDU

The saga continues, although we're getting near the end of the book! :-)

Based on the responses from several people to my query concerning
comparing subsets of slopes in ANCOVA, I've decided that a worked
example would serve as a useful reference.

In this example, I have a single classification variable (TRT), with
four level (A, B, C,and D). There is some arbitrary response variable Y,
and some linear covariate X. I want to "ask" the following questions:

(1) Is there overall heterogeneity among levels of TRT in the linear
relationship of Y on X?

(2) If there is heterogeneity, which slopes are different?

(3) Among the levels of TRT for which the slopes do not differ
significantly, is there a significant difference in the intercept?

I am analysing this using SAS, PROC GLM, with ESTIMATE and CONTRAST
statements. I include the data so that "people at home can play along
with our contestant".

data test;
 input trt $ x y;
cards;
a -0.31 -2.4
a 0.17 6.3
a 0.58 15.8
a 0.81 20.5
a 1.0  27.0
b -1.18 -7.0
b -0.65 2.1
b 0.10 17.8
b 0.50 27.3
b 0.67 32.0
c -1.79 -10.8
c -1.21 -2.8
c -0.35 14.2
c 0.08 25.5
c 0.49 35.7
c 0.65 41.2
d -1.5 -10.8
d -0.6 -4
d 0.2 0.6
d 0.5 5
d 1.1 10.6
*;

To answer the first question, I use a simple ANCOVA, code with GLM as

PROC GLM;
  CLASS TRT;
    MODEL Y=X TRT X*TRT;

Significance of the interaction term (X*TRT) indicates statistically
significant heterogeneity of slopes among levels of TRT. The results of
this analysis are:

Dependent Variable: Y
                                    Sum of           Mean
Source                  DF         Squares         Square   F Value     Pr > F

Model                    7     4931.033407     704.433344    222.79     0.0001

Error                   13       41.104688       3.161899

Corrected Total         20     4972.138095

                  R-Square            C.V.       Root MSE               Y Mean

                  0.991733        15.31650       1.778173           11.6095238

Source                  DF     Type III SS    Mean Square   F Value     Pr > F

TRT                      3     1762.772310     587.590770    185.83     0.0001
X                        1     2976.535651    2976.535651    941.38     0.0001
X*TRT                    3      486.869613     162.289871     51.33     0.0001


The interaction term is highly significant, thus I conclude that the
slopes differ significantly.

Now I want to know "which slopes are different"? Of course this is
analogous to the a posteriori pairs comparison in ANOVA, where you want
to know which sample means differ from which other ones. While there is
no simple equivalent to the MEANS option for ANCOVA, you can derive
equivalent comparisons using the CONTRAST statement.

First however, I'd like to at least look at what the slopes are that I'm
comparing (a wise sage has oft told me that looking at the data may
actually be useful in statistics. Novel concept! :-) I can either (a)
do individual regressions for each level of TRT, or (b) use the estimate
statement. If the error variances are homegenous across TRT, then the
two approaches should give essentially identical results. This was the
point of an earlier posting of mine. I'll be conservative here, and
assume that the error variances are homogenous to some extent, and
will simply use the ESTIMATE statemnt in GLM. This uses the total error
variance matrix to derive s.e's and significances, although the actual
value of the slopes will be the same as with using individual
regressions. The syntax of the code is...

PROC GLM;
  CLASS TRT;
    MODEL Y=X TRT X*TRT;
ESTIMATE 'Slope A' X 1 TRT*X 1 0 0 0;
ESTIMATE 'Slope B' X 1 TRT*X 0 1 0 0;
ESTIMATE 'Slope C' X 1 X*TRT 0 0 1 0;
ESTIMATE 'Slope D' X 1 X*TRT 0 0 0 1;

Of course, this code duplicates the basic ANOVA and ANCOVA results,
which I've edited out. The results of the ESTIMATE statements are

Parameter                  Estimate    Parameter=0                Estimate

a                       22.03076923          13.02     0.0001     1.69158126
b                       21.06855527          18.59     0.0001     1.13347289
c                       21.39405343          26.09     0.0001     0.81990044
d                        8.05571848           9.16     0.0001     0.87903505


Obviously, the slope for the level D of TRT "looks" very different from
the slopes for A, B or C. I set up the data set such that D would be
different. Now I want SAS to "confirm" my observation that D is
different, by performing paired-comparisons of the 4 slopes. I do this
using the CONTRAST statement, and the following code

PROC GLM;
 CLASS TRT;
   MODEL Y=X TRT Y*X;
CONTRAST 'A V B' X*TRT 1 -1 0 0;
CONTRAST 'A V C' X*TRT 1 0 -1 0;
CONTRAST 'A V D' X*TRT 1 0 0 -1;
CONTRAST 'B V C' X*TRT 0 1 -1 0;
CONTRAST 'B V D' X*TRT 0 1 0 -1;
CONTRAST 'C V D' X*TRT 0 0 1 -1;

The results of the paired contrasts are:

Contrast                DF     Contrast SS    Mean Square   F Value     Pr > F

a vs b                   1        0.706058       0.706058      0.22     0.6444
a vs c                   1        0.362753       0.362753      0.11     0.7402
a vs d                   1      169.922924     169.922924     53.74     0.0001
b vs c                   1        0.171181       0.171181      0.05     0.8196
b vs d                   1      260.231492     260.231492     82.30     0.0001
c vs d                   1      389.315439     389.315439    123.13     0.0001

As indicated, D differs significantly from all other slopes, while A, B
and C do not differ significantly from each other.

I want to confirm that these slopes don't differ, so I now use the
CONTRAST statement to simultaneously test several contrasts among
these three (thanks to Tim Dorcey for reminding me of this "trick").

PROC GLM;
  CLASS TRT;
   MODEL Y=X TRT X*TRT;
 CONTRAST 'slope a/b/c' X*TRT 1 -1 0 0, X*TRT 1 0 -1 0,
                        X*TRT 0 1 -1 0;

This contrast asks whether the slopes of A B and C differ, including all
the data in the analysis. Since the error variances for each level are
approcimately equal, then dropping D from the data set and treating
these separately in one ANCOVA would give analogous results.

The results of this test are:

slope a/b/c              2        0.707574       0.353787      0.11     0.8950

As seen, the slopes do not differ significantly. To confirm that this is
analogous to dropping D from the data set and running the ANCOVA on A ->
C alone, I did just that. The results...

Source                  DF     Type III SS    Mean Square   F Value     Pr > F

X                        1     2729.426339    2729.426339    744.01     0.0001
TRT                      2      784.017962     392.008981    106.86     0.0001
X*TRT                    2        0.707574       0.353787      0.10     0.9089

As you can see, the mean square and significances are almost identical
between the two approaches, as expected since the error variances are
almost identical.

Now, do the intercepts differ among A, B and C? This involves using
a CONTRAST statement analogous to the preceding one for slopes.

PROC GLM;
 CLASS TRT;
   MODEL Y=X TRT X*TRT;
CONTRAST 'INTCP A/B/C' TRT 1 -1 0 0, TRT 1 0 -1 0, TRT 0 1 -1 0;


The results,

trt a/b/c                2      784.017962     392.008981    123.98     0.0001

 There appears to be massively signifcant differences in the intercepts.
One way of checking this is to use the LSMEANS option.

PROC GLM;
  CLASS TRT;
   MODEL Y=X TRT X*TRT;
      LSMEANS TRT / STDERR PDIFF;


                       General Linear Models Procedure
                             Least Squares Means

            TRT             Y       Std Err     Pr > |T|   LSMEAN
                       LSMEAN        LSMEAN   H0:LSMEAN=0   Number

            a       2.7498315     1.1428581        0.0317     1
            b      16.0572624     0.7999688        0.0001     2
            c      24.0076699     0.7718276        0.0001     3
            d       0.4794749     0.7955210        0.5571     4

                       Pr > |T| H0: LSMEAN(i)=LSMEAN(j)

                        i/j     1       2       3       4
                        1   .      0.0001  0.0001  0.1270
                        2  0.0001   .      0.0001  0.0001
                        3  0.0001  0.0001   .      0.0001
                        4  0.1270  0.0001  0.0001   .

NOTE: To ensure overall protection level, only probabilities associated with
      pre-planned comparisons should be used.

As you can see, there are significant differences among the LSMEANS for
A, B and C, as expected if their intercepts are different and slopes
equal. As a final check, I dropp D from the data, and do a standard
ANCOVA without the interaction term (which tests for differences in
intercepts). The results...


Source                  DF     Type III SS    Mean Square   F Value     Pr > F

TRT                      2      988.880256     494.440128    158.67     0.0001
X                        1     3780.884367    3780.884367   1213.35     0.0001


In this case, the final F-statistic (158.67) is different from that
derived using the contrast statments (123.98), which does give pause for
thought as to why this is so.

   In conclusion, it seems obvious that through careful use of
CONTRAST statments in ANCOVA using PROC GLM in SAS, you can derive some
tests for slopes and intercepts. However, I think it is prudent to
consider some outstanding questions:

1) Do the significances of these post-hoc comparisons need to be
adjusted in some way, and if so, how?

2) Why do the F-statistics of the final intercepts tests differ? Should
the interaction term be included in the MODEL statement for this test?

3) Under what conditions is it better to drop D and treat A -> C in a
separate ANCOVA? Agfain, would significances need to be adjusted?

Forgive the length, but the number of people who have asked me to
forward answers I receive to this question seems to indicate general
interest (confusion?), which hopefully justifies this longish treatment.

I would appreciate private copies of any responses posted on the net.

Thanks in advance...

           _///_              +----------------------------+
           -. .-              |       Evan G. Cooch        |
           ( L )    \////     |   Department of Biology    |
         --(\=/)--  (   )     | University of Pennsylvania |
        /         \ /  /      | Philadelphia, Pennsylvania |
        I          V  /       |   Phone: (215) 898-7129    |
        I            /        |     FAX: (215) 898-8780    |
        I           /         |  ECOOCH@PENNSAS.UPENN.EDU  |
                              +----------------------------+
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU