Announcement

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

  • Comparison of marginal effect between groups

    Hello,

    I am performing an analysis of a longitudinal dataset examining the rates of change in quantitative retinal measures between controls and individuals with multiple sclerosis (MS). I am performing these analyses with mixed-effects models with 2 levels (subject and eye) with random slopes in follow-up time.

    I have found that age at study entry is associated with the rates of change in quantitative retinal measures, but this relationship differs for controls and MS individuals. I have performed analyses separately in each group including an age_baseline*time interaction term, as well as in one model including all individuals from both groups with baseline_age*time and a a three-way continuous*continuous*binary interaction term (baseline_age*time*diagnosis).

    This model is as follows:
    mixed y c.time##c.age_baseline c.time#i.diagnosis#c.age_baseline c.time##i.diagnosis c.age_baseline##i.diagnosis || id: || eye: time, mle cov(uns)

    Following this, I have used margins to calculate and plot the rates of change of y by age in controls and MS as follows:

    . margins diagnosis, dydx(time) at(baseline_age=(20(5)65)) post

    Average marginal effects Number of obs = 3,661

    Expression : Linear prediction, fixed portion, predict()
    dy/dx w.r.t. : time

    1._at : baseline_age = 20

    2._at : baseline_age = 25

    3._at : baseline_age = 30

    4._at : baseline_age = 35

    5._at : baseline_age = 40

    6._at : baseline_age = 45

    7._at : baseline_age = 50

    8._at : baseline_age = 55

    9._at : baseline_age = 60

    10._at : baseline_age = 65

    -------------------------------------------------------------------------------
    | Delta-method
    | dy/dx Std. Err. z P>|z| [95% Conf. Interval]
    --------------+----------------------------------------------------------------
    time |
    _at#diagnosis |
    1 0 | -.3512082 .1568349 -2.24 0.025 -.6585989 -.0438175
    1 1 | -.9290963 .0845973 -10.98 0.000 -1.094904 -.7632886
    2 0 | -.3621894 .1248761 -2.90 0.004 -.606942 -.1174367
    2 1 | -.8745289 .0708776 -12.34 0.000 -1.013446 -.7356114
    3 0 | -.3731706 .0985601 -3.79 0.000 -.5663447 -.1799964
    3 1 | -.8199615 .0578459 -14.17 0.000 -.9333374 -.7065857
    4 0 | -.3841518 .0834104 -4.61 0.000 -.5476333 -.2206703
    4 1 | -.7653942 .0460895 -16.61 0.000 -.8557279 -.6750605
    5 0 | -.395133 .0855786 -4.62 0.000 -.562864 -.227402
    5 1 | -.7108268 .0368499 -19.29 0.000 -.7830512 -.6386024
    6 0 | -.4061142 .1039869 -3.91 0.000 -.6099248 -.2023036
    6 1 | -.6562594 .0323599 -20.28 0.000 -.7196837 -.5928351
    7 0 | -.4170954 .1320077 -3.16 0.002 -.6758257 -.1583651
    7 1 | -.601692 .0345254 -17.43 0.000 -.6693605 -.5340236
    8 0 | -.4280766 .1648088 -2.60 0.009 -.751096 -.1050572
    8 1 | -.5471247 .0423369 -12.92 0.000 -.6301036 -.4641458
    9 0 | -.4390579 .2000526 -2.19 0.028 -.8311538 -.0469619
    9 1 | -.4925573 .0533705 -9.23 0.000 -.5971616 -.387953
    10 0 | -.4500391 .2366503 -1.90 0.057 -.913865 .0137869
    10 1 | -.4379899 .0660302 -6.63 0.000 -.5674068 -.308573
    -------------------------------------------------------------------------------

    And this is what the plot looks like:
    Click image for larger version

Name:	graph1.tif
Views:	1
Size:	39.0 KB
ID:	1456399





    So diseased individuals that are younger have faster decreases in the y variable than are expected with normal aging, but as their age increases, their rates of change approach those observed in the control group (normal aging).

    I am now interested in calculating the differences, 95% CI and p-values for the comparison between the rates of change of y between the control and MS groups, at specific ages (e.g. from 20-65 in 5-year increments). However, reading the instructions for the margins command it is not clear to me if this is possible to be obtained through that command.
    I attempted to use the calculated marginal effects outlined above and the variance-covariance matrix [.matrix list e(V)] to calculate the p-values from Z-scores calculated as follows: (b0-b1)/(varb0 + varb1 - 2*covb0b1) but the results seem odd to me (i.e. p-values are much lower than expected).

    I would greatly appreciate any input.

    Thanks!

    Last edited by Elias Sotirchos; 02 Aug 2018, 14:07.

  • #2
    Any margins or marginal effects that you can calculate with the -margins- command can also be tested for differences by adding the -pwcompare- option to the -margins- command.

    Added: You could have simplified your regression command to just:

    Code:
    mixed y c.time##c.age_baseline##i.diagnosis || id: || eye: time, mle cov(uns)
    which Stata will automatically expand to include all the contained terms and two-way interactions. It is better to do it this way rather than writing them all out separately because it is much too easy to forget one when you try to spell them all out.
    Last edited by Clyde Schechter; 02 Aug 2018, 14:41.

    Comment


    • #3
      You can do that with contrasts of margins:

      Code:
      sysuse auto, clear
      reg price c.mpg##i.foreign
      margins foreign, at(mpg = (10(5)25))
      marginsplot
      margins r.foreign, at(mpg = (10(5)25)) contrast(pveffects)
      marginsplot
      The second margins is doing the comparison of differences from the reference (base) level of domestic, so at mpg =10, the foreing-domestic diff is 10083.28 - 9307.987 = 775.293.

      You can see that the foreign versus domestic price gap is significant at mpg 20 and above, but not at 10 or 15 mpg. You can also reject the null that all price gaps are zero.


      Last edited by Dimitriy V. Masterov; 02 Aug 2018, 14:53.

      Comment


      • #4
        Thank you both for your responses! The -pwcompare- option worked perfectly. I somehow missed it when reading the instructions for -margins-.
        Thanks also for the tip on simplifying the command. That will make the code much more readable.

        Comment

        Working...
        X