Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contrasts after xtmixed

    Hi Stata forum members

    I need help with "contrast" syntax. I have a continuous outcome measured at baseline and at three time points. There is an exposure variable (four-level) measured between the baseline and I am running the following random effects model:

    Code:
    xtmixed outcome i.exposure##time outcome_bl || id:
    How can I test the contrast (-1, 0.5, 0.5) in time i.e. between time period 1 and the average of time periods two and three?

    How can I then test the interaction of time--contrasting level 1 versus levels 2 and 3--and exposure?

    Thank you

    Rena

  • #2
    Well, there are several ways to do this. But for this particular contrast, the simplest way would be to generate a new time variable that collapses the distinction between 2 and 3: -recode time (3=2), gen(time23)- and then run your model using ib2.time23 in place of time. This will set the referent category to a variable that indifferently denotes 2 and 3, and you will get an explicit effect for time = 1 and the interactions of that with exposure in the output.

    This kind of trick, transforming the variables, is easy for this particular kind of contrast. For more general contrasts it can be very difficult to figure out what to do, and it won't be apparent when you come back months later just what you did or why. The more general approach is to use the -test- command for the hypothesis test, and the -lincom- command to estimate the contrast:

    Code:
    lincom 1.time - 0.5*2.time - 0.5*3.time
    test 1.time = 0.5*2.time + 0.5*3.time
    Last edited by Clyde Schechter; 11 Aug 2014, 08:12. Reason: Hit the Post Reply button too early by mistake. Needed to add more information.

    Comment


    • #3
      Thanks again Clyde. Just out of curiosity: would it be possible to test for interactions between time--contrasting as above--and exposure using the lincom approach?

      Comment


      • #4
        In the following example I use regress but the concepts follow even
        when used with mixed (or xtmixed in Stata 12).

        First consider a simpler model without the interaction:

        Code:
        . webuse margex
        (Artificial data for margins)
        
        .
        . regress y i.outcome i.group
        
              Source |       SS       df       MS              Number of obs =    3000
        -------------+------------------------------           F(  3,  2996) =   11.45
               Model |   15778.351     3  5259.45035           Prob > F      =  0.0000
            Residual |  1375654.65  2996   459.16377           R-squared     =  0.0113
        -------------+------------------------------           Adj R-squared =  0.0103
               Total |  1391433.01  2999  463.965657           Root MSE      =  21.428
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
           1.outcome |   -2.02553   1.102687    -1.84   0.066    -4.187631    .1365713
                     |
               group |
                  2  |  -.0217244   .9211469    -0.02   0.981    -1.827869     1.78442
                  3  |   4.782014   1.076471     4.44   0.000     2.671317     6.89271
                     |
               _cons |   68.99662   .7097933    97.21   0.000     67.60489    70.38835
        ------------------------------------------------------------------------------
        Clyde points out that we can use lincom to compute the contrast
        of interest.

        Code:
        . lincom 1.group - (2.group + 3.group)/2
        
         ( 1)  1b.group - .5*2.group - .5*3.group = 0
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 (1) |  -2.380145   .8549784    -2.78   0.005    -4.056549   -.7037405
        ------------------------------------------------------------------------------
        This can also be done with the Helmert contrast operator h..
        In the following output, the contrast of interested is labelled
        (1 vs >1).

        Code:
        . contrast h.group
        
        Contrasts of marginal linear predictions
        
        Margins      : asbalanced
        
        ------------------------------------------------
                     |         df           F        P>F
        -------------+----------------------------------
               group |
          (1 vs >1)  |          1        7.75     0.0054
          (2 vs  3)  |          1       21.16     0.0000
              Joint  |          2       12.61     0.0000
                     |
         Denominator |       2996
        ------------------------------------------------
        
        --------------------------------------------------------------
                     |   Contrast   Std. Err.     [95% Conf. Interval]
        -------------+------------------------------------------------
               group |
          (1 vs >1)  |  -2.380145   .8549784     -4.056549   -.7037405
          (2 vs  3)  |  -4.803738   1.044341     -6.851436    -2.75604
        --------------------------------------------------------------
        The reason I mention contrast is that it automatically accounts for
        interactions, while lincom requires more of the user when models
        contain interactions.

        To illustraite, let's refit the model to also include the interaction.

        Code:
        . regress y outcome##group
        
              Source |       SS       df       MS              Number of obs =    3000
        -------------+------------------------------           F(  5,  2994) =    9.24
               Model |  21137.6189     5  4227.52378           Prob > F      =  0.0000
            Residual |  1370295.39  2994   457.68049           R-squared     =  0.0152
        -------------+------------------------------           Adj R-squared =  0.0135
               Total |  1391433.01  2999  463.965657           Root MSE      =  21.393
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
           1.outcome |  -4.383724    1.32976    -3.30   0.001     -6.99106   -1.776388
                     |
               group |
                  2  |  -1.396504   1.006866    -1.39   0.166    -3.370722     .577715
                  3  |    4.07282   1.115188     3.65   0.000     1.886208    6.259433
                     |
             outcome#|
               group |
                1 2  |   8.495807   2.490864     3.41   0.001     3.611828    13.37978
                1 3  |     .89583   5.573102     0.16   0.872    -10.03167    11.82333
                     |
               _cons |   69.74007   .7466372    93.41   0.000      68.2761    71.20405
        ------------------------------------------------------------------------------
        If we use the same contrast with lincom we get

        Code:
        . lincom 1.group - (2.group + 3.group)/2
        
         ( 1)  1b.group - .5*2.group - .5*3.group = 0
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 (1) |  -1.338158    .918199    -1.46   0.145    -3.138523    .4622064
        ------------------------------------------------------------------------------
        which does not account for the interaction between group and outcome.
        But contrast will account for this in its calculations.

        Code:
        . contrast h.group
        
        Contrasts of marginal linear predictions
        
        Margins      : asbalanced
        
        ------------------------------------------------
                     |         df           F        P>F
        -------------+----------------------------------
               group |
          (1 vs >1)  |          1        5.33     0.0211
          (2 vs  3)  |          1        0.33     0.5654
              Joint  |          2        3.52     0.0297
                     |
         Denominator |       2994
        ------------------------------------------------
        
        --------------------------------------------------------------
                     |   Contrast   Std. Err.     [95% Conf. Interval]
        -------------+------------------------------------------------
               group |
          (1 vs >1)  |  -3.686068    1.59688      -6.81716    -.554975
          (2 vs  3)  |  -1.669336   2.903763     -7.362908    4.024236
        --------------------------------------------------------------
        We can also get contrast to produce contrasts of one factor variable
        for each level of the other. Here we ask for Helmert contrasts of group
        at each level of outcome.

        Code:
        . contrast h.group@outcome
        
        Contrasts of marginal linear predictions
        
        Margins      : asbalanced
        
        -------------------------------------------------
                      |         df           F        P>F
        --------------+----------------------------------
        group@outcome |
         (1 vs >1) 0  |          1        2.12     0.1451
         (1 vs >1) 1  |          1        3.89     0.0486
         (2 vs  3) 0  |          1       26.18     0.0000
         (2 vs  3) 1  |          1        0.14     0.7090
               Joint  |          4        9.25     0.0000
                      |
          Denominator |       2994
        -------------------------------------------------
        
        ---------------------------------------------------------------
                      |   Contrast   Std. Err.     [95% Conf. Interval]
        --------------+------------------------------------------------
        group@outcome |
         (1 vs >1) 0  |  -1.338158    .918199     -3.138523    .4622064
         (1 vs >1) 1  |  -6.033977   3.058923     -12.03178    -.036173
         (2 vs  3) 0  |  -5.469324   1.068873     -7.565124   -3.373525
         (2 vs  3) 1  |   2.130653   5.708315     -9.061964    13.32327
        ---------------------------------------------------------------
        This shows us that the lincom result is actually a partial effect of group
        when outcome is 0.
        Last edited by Jeff Pitblado (StataCorp); 12 Aug 2014, 13:51.

        Comment


        • #5
          Sorry I have been away and missed this reply. Thanks Jeff, that's very helpful.

          Comment

          Working...
          X