Announcement

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

  • How to compare the slope gradients after mixed command

    Dear Stata experts,

    I have a repeated measures study design where subjects were followed over 5 visits and their HbA1c was measured throughout. There are some missing HbA1c values. I am able to generate the mixed commands, and plotted the graphs. Below is what I've obtained thus far.

    Code:
    . mixed hba1c_ j##track || record_id:, var reml
    
    Performing EM optimization:
    
    Performing gradient-based optimization:
    
    Iteration 0:   log restricted-likelihood = -1063.9138  
    Iteration 1:   log restricted-likelihood = -1063.9138  
    
    Computing standard errors:
    
    Mixed-effects REML regression                   Number of obs     =        547
    Group variable: record_id                       Number of groups  =        145
    
                                                    Obs per group:
                                                                  min =          2
                                                                  avg =        3.8
                                                                  max =          5
    
                                                    Wald chi2(9)      =     327.99
    Log restricted-likelihood = -1063.9138          Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
          hba1c_ |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
               j |
              1  |  -2.531488   .3016913    -8.39   0.000    -3.122792   -1.940183
              2  |   -3.01946   .4786132    -6.31   0.000    -3.957525   -2.081395
              3  |  -2.524065   .4322982    -5.84   0.000    -3.371354   -1.676776
              4  |  -2.323791   .4422862    -5.25   0.000    -3.190656   -1.456926
                 |
           track |
            yes  |   .3795789   .3109946     1.22   0.222    -.2299593    .9891171
                 |
         j#track |
          1#yes  |   .2095378   .3739649     0.56   0.575    -.5234199    .9424954
          2#yes  |   .4563514   .5540576     0.82   0.410    -.6295816    1.542284
          3#yes  |  -.2356258   .4859038    -0.48   0.628     -1.18798    .7167281
          4#yes  |  -.6247749   .4981435    -1.25   0.210    -1.601118    .3515685
                 |
           _cons |     10.732   .2517275    42.63   0.000     10.23862    11.22538
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    record_id: Identity          |
                      var(_cons) |   .9210646   .1912886       .613071    1.383787
    -----------------------------+------------------------------------------------
                   var(Residual) |   2.247272   .1607321      1.953327    2.585451
    ------------------------------------------------------------------------------
    LR test vs. linear model: chibar2(01) = 48.43         Prob >= chibar2 = 0.0000
    
    
    . margins, over(j track)  
    
    Predictive margins                              Number of obs     =        547
    
    Expression   : Linear prediction, fixed portion, predict()
    over         : j track
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
         j#track |
           0#no  |     10.732   .2517275    42.63   0.000     10.23862    11.22538
          0#yes  |   11.11158   .1826223    60.84   0.000     10.75365    11.46951
           1#no  |   8.200512   .2539557    32.29   0.000     7.702768    8.698257
          1#yes  |   8.789629   .1867404    47.07   0.000     8.423625    9.155634
           2#no  |    7.71254   .4500516    17.14   0.000     6.830455    8.594625
          2#yes  |    8.54847   .2528818    33.80   0.000     8.052831     9.04411
           3#no  |   8.207935   .4004468    20.50   0.000     7.423073    8.992796
          3#yes  |   8.351888   .1877782    44.48   0.000     7.983849    8.719926
           4#no  |   8.408209   .4112091    20.45   0.000     7.602254    9.214164
          4#yes  |   8.163013    .196392    41.56   0.000     7.778092    8.547935
    ------------------------------------------------------------------------------
    
    . marginsplot, x(j) title("Overall HbA1c trend split by Tracked group") ///
    >         xtitle("Visit") ytitle("Mean HbA1c")
    
      Variables that uniquely identify margins: j track


    What I'm struggling with is to obtain the slopes between each visit. I read from the Stata manual that the simple effects correspond to the slopes of each of the lines. So I attempted the following:

    Code:
    . contrast ar.j@track, pveffects
    
    Contrasts of marginal linear predictions
    
    Margins      : asbalanced
    
    -------------------------------------------------
                  |         df        chi2     P>chi2
    --------------+----------------------------------
    hba1c_        |
          j@track |
     (1 vs 0) no  |          1       70.41     0.0000
    (1 vs 0) yes  |          1      110.41     0.0000
     (2 vs 1) no  |          1        1.03     0.3105
    (2 vs 1) yes  |          1        0.73     0.3937
     (3 vs 2) no  |          1        0.75     0.3855
    (3 vs 2) yes  |          1        0.48     0.4866
     (4 vs 3) no  |          1        0.16     0.6935
    (4 vs 3) yes  |          1        0.66     0.4160
           Joint  |          8      327.98     0.0000
    -------------------------------------------------
    
    ------------------------------------------------------
                  |   Contrast   Std. Err.      z    P>|z|
    --------------+---------------------------------------
    hba1c_        |
          j@track |
     (1 vs 0) no  |  -2.531488   .3016913    -8.39   0.000
    (1 vs 0) yes  |   -2.32195   .2209798   -10.51   0.000
     (2 vs 1) no  |  -.4879724   .4811204    -1.01   0.310
    (2 vs 1) yes  |  -.2411588   .2827586    -0.85   0.394
     (3 vs 2) no  |   .4953947   .5709149     0.87   0.386
    (3 vs 2) yes  |  -.1965825   .2825823    -0.70   0.487
     (4 vs 3) no  |   .2002747   .5081325     0.39   0.693
    (4 vs 3) yes  |  -.1888744   .2322142    -0.81   0.416
    ------------------------------------------------------
    Looking at the Contrast values, it seems to be reflect the direction of the graph, but I'm not sure if these values are indeed the slope. However, the p-values are not what I'm after. What I'm interested in comparing is if the slope at each time point differs from the previous time-point and if this difference is statistically significant. Is it possible for this to be done?

    Thanks so much!
    Attached Files
    Last edited by Maudrene Tan; 19 Aug 2020, 06:00.

  • #2
    What do you mean by the slope "at each time point." Your time variable is discrete. There is a slope between each time point and the next. And your outputs give you those. But there is no such thing as the slope "at" each time point in this model.

    Comment


    • #3
      Dear Clyde,

      Thanks for correcting me. Yes, I will like to find out the slopes between time points. Do you mean that the following contrasts are the slopes?

      Code:
      ------------------------------------------------------
                    |   Contrast   Std. Err.      z    P>|z|
      --------------+---------------------------------------
      hba1c_        |
            j@track |
       (1 vs 0) no  |  -2.531488   .3016913    -8.39   0.000
      (1 vs 0) yes  |   -2.32195   .2209798   -10.51   0.000
       (2 vs 1) no  |  -.4879724   .4811204    -1.01   0.310
      (2 vs 1) yes  |  -.2411588   .2827586    -0.85   0.394
       (3 vs 2) no  |   .4953947   .5709149     0.87   0.386
      (3 vs 2) yes  |  -.1965825   .2825823    -0.70   0.487
       (4 vs 3) no  |   .2002747   .5081325     0.39   0.693
      (4 vs 3) yes  |  -.1888744   .2322142    -0.81   0.416
      ------------------------------------------------------
      If yes, how do I compare the slopes between timepoints. For example how can I compare the gradient between (4 vs 3) no to (3 vs 2) no? Is there a way to do that?

      Thanks so much for your advice.

      Comment


      • #4
        Oh, that's kind of "meta." Well, re-run your -contrast- command and add the -post- option. Now you can do -contrast- on those results.

        Comment


        • #5
          Dear Clyde,

          Thanks so much for your advice. I tried doing as you suggested, but I must have done something wrong because I got an error message:

          Code:
          . contrast ar.j@track, pveffects post
          
          Contrasts of marginal linear predictions
          
          Margins      : asbalanced
          
          -------------------------------------------------
                        |         df        chi2     P>chi2
          --------------+----------------------------------
          hba1c_        |
                j@track |
           (1 vs 0) no  |          1       70.41     0.0000
          (1 vs 0) yes  |          1      110.41     0.0000
           (2 vs 1) no  |          1        1.03     0.3105
          (2 vs 1) yes  |          1        0.73     0.3937
           (3 vs 2) no  |          1        0.75     0.3855
          (3 vs 2) yes  |          1        0.48     0.4866
           (4 vs 3) no  |          1        0.16     0.6935
          (4 vs 3) yes  |          1        0.66     0.4160
                 Joint  |          8      327.98     0.0000
          -------------------------------------------------
          
          ------------------------------------------------------
                        |   Contrast   Std. Err.      z    P>|z|
          --------------+---------------------------------------
          hba1c_        |
                j@track |
           (1 vs 0) no  |  -2.531488   .3016913    -8.39   0.000
          (1 vs 0) yes  |   -2.32195   .2209798   -10.51   0.000
           (2 vs 1) no  |  -.4879724   .4811204    -1.01   0.310
          (2 vs 1) yes  |  -.2411588   .2827586    -0.85   0.394
           (3 vs 2) no  |   .4953947   .5709149     0.87   0.386
          (3 vs 2) yes  |  -.1965825   .2825823    -0.70   0.487
           (4 vs 3) no  |   .2002747   .5081325     0.39   0.693
          (4 vs 3) yes  |  -.1888744   .2322142    -0.81   0.416
          ------------------------------------------------------
          
          
          .  contrast {j 0 0 0 0 1 0 -1 0}@0.track, effects
          contrast is not allowed with results from the contrast command

          Comment


          • #6
            Oh, ok. So, still do your -contrast- with the -post- option. Then run -contrast, coefl- to find out what Stata calls each of those terms: they should look something like _b[[email protected]] Then you can use -lincom- to calculate the difference between whichever pairs of those you're interested in.

            Comment


            • #7
              Thank you so much Clyde. This worked perfectly! Appreciate all your assistance.

              Comment

              Working...
              X