Announcement

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

  • mixed linear model for longitudinal data

    I am interested in determining whether VarX changes over Time in my experiment. Both eyes of each subject was used.
    Code:
    xtmixed VarX Time || Patient: || Side: Time
    I'm not sure if this code is correct. I was told I need to account for the interaction between the left and right eye for each subject as well.
    If VarX does in fact vary between a certain time point compared to the baseline, I tried to perform post estimation using:
    Code:
    pwcompare Time
    but it doesn't seem to work.

    I could really appreciate any help, thanks.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(Patient Side) int Time double VarX
    1 1 0 1.28
    1 1 1 1.31
    1 1 2  1.2
    1 1 3 1.03
    1 1 4 1.27
    1 1 5 1.26
    1 1 6  1.3
    1 0 0  1.2
    1 0 1 1.13
    1 0 2 1.13
    1 0 3 1.09
    1 0 4  1.1
    1 0 5 1.11
    1 0 6  1.2
    2 1 0  1.1
    2 1 1  .81
    2 1 2  .91
    2 1 3  .98
    2 1 4  .84
    2 1 5 1.05
    2 1 6  .95
    2 0 0 1.13
    2 0 1  .84
    2 0 2  .86
    2 0 3  .85
    2 0 4  .88
    2 0 5  .89
    2 0 6  .99
    3 1 0 1.12
    3 1 1 1.08
    3 1 2 1.02
    3 1 3  .92
    3 1 4    .
    3 1 5    .
    3 1 6  .98
    3 0 0  .95
    3 0 1 1.02
    3 0 2  .94
    3 0 3  1.1
    3 0 4    .
    3 0 5    .
    3 0 6  .93
    4 1 0 1.02
    4 1 1 1.16
    4 1 2  1.1
    4 1 3  .89
    4 1 4 1.38
    4 1 5  .94
    4 1 6 1.04
    4 0 0 1.18
    4 0 1 1.07
    4 0 2 1.17
    4 0 3   .9
    4 0 4  1.5
    4 0 5  .98
    4 0 6 1.17
    5 1 0 1.43
    5 1 1  1.3
    5 1 2 1.32
    5 1 3 1.05
    5 1 4 1.26
    5 1 5 1.22
    5 1 6 1.26
    5 0 0 1.16
    5 0 1 1.23
    5 0 2 1.41
    5 0 3 1.14
    5 0 4 1.03
    5 0 5 1.11
    5 0 6 1.14
    6 1 0 1.24
    6 1 1 1.79
    6 1 2 1.27
    6 1 3 1.37
    6 1 4 1.32
    6 1 5 1.33
    6 1 6  1.3
    6 0 0 1.36
    6 0 1 1.28
    6 0 2 1.42
    6 0 3 1.42
    6 0 4 1.32
    6 0 5 1.34
    6 0 6  1.3
    7 1 0 1.22
    7 1 1 1.19
    7 1 2 1.08
    7 1 3 1.17
    7 1 4 1.13
    7 1 5 1.14
    7 1 6 1.15
    7 0 0 1.14
    7 0 1  1.2
    7 0 2  1.2
    7 0 3 1.23
    7 0 4 1.17
    7 0 5 1.13
    7 0 6 1.17
    8 1 0 1.07
    8 1 1  1.3
    end

  • #2
    Assuming you have treated 'Time' as a continuous variable, run 'margins' after 'mixed' (note: 'xtmixed' has been renamed to 'mixed' as of Stata 13)

    Code:
    margins, at(time=(0(1)6)) pwcompare

    Roman

    Comment


    • #3
      Thanks Roman, I ran the code below after 'mixed'. The p-values I obtained across all pairwise comparisons are identical, not sure if I'm missing something, thanks.

      Code:
      margins, at(Time=(0(1)6)) pwcompare(effects)

      Comment


      • #4
        Its because of using Time as a continuous variable. You can use Time as categorical variable if your hypothesis permits and do the pair-wise comparison. In that case Time categorical cannot be added to have random slopes for Side. Now it is you to decide how much information you are gaining if you avoid Time related random slopes for Side. To obtain estimates for Time as categorical:


        Code:
        mixed VarX i.Time || Patient: || Side:
        
         margins Time,
        
        Adjusted predictions                            Number of obs     =         96
        
        Expression   : Linear prediction, fixed portion, predict()
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                Time |
                  0  |   1.173694   .0512644    22.89   0.000     1.073217     1.27417
                  1  |   1.181027   .0512644    23.04   0.000     1.080551    1.281504
                  2  |   1.145775   .0523462    21.89   0.000     1.043179    1.248372
                  3  |   1.082204   .0523462    20.67   0.000     .9796072      1.1848
                  4  |   1.163028   .0539134    21.57   0.000     1.057359    1.268696
                  5  |   1.104694   .0539134    20.49   0.000     .9990258    1.210363
                  6  |   1.135061   .0523462    21.68   0.000     1.032464    1.237658
        ------------------------------------------------------------------------------
        
        
        margins Time, pwcompare(effects)
        
        Pairwise comparisons of adjusted predictions
        
        Expression   : Linear prediction, fixed portion, predict()
        
        ------------------------------------------------------------------------------
                     |            Delta-method    Unadjusted           Unadjusted
                     |   Contrast   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                Time |
             1 vs 0  |   .0073333   .0396734     0.18   0.853    -.0704252    .0850918
             2 vs 0  |  -.0279186   .0406275    -0.69   0.492    -.1075471    .0517098
             3 vs 0  |  -.0914901   .0406275    -2.25   0.024    -.1711185   -.0118616
             4 vs 0  |  -.0106663   .0426278    -0.25   0.802    -.0942154    .0728827
             5 vs 0  |  -.0689997   .0426278    -1.62   0.106    -.1525487    .0145493
             6 vs 0  |  -.0386329   .0406275    -0.95   0.342    -.1182613    .0409955
             2 vs 1  |   -.035252   .0406275    -0.87   0.386    -.1148804    .0443765
             3 vs 1  |  -.0988234   .0406275    -2.43   0.015    -.1784518   -.0191949
             4 vs 1  |  -.0179997   .0426278    -0.42   0.673    -.1015487    .0655493
             5 vs 1  |   -.076333   .0426278    -1.79   0.073     -.159882     .007216
             6 vs 1  |  -.0459662   .0406275    -1.13   0.258    -.1255947    .0336622
             3 vs 2  |  -.0635714   .0410659    -1.55   0.122    -.1440591    .0169163
             4 vs 2  |   .0172523   .0430459     0.40   0.689    -.0671161    .1016206
             5 vs 2  |  -.0410811   .0430459    -0.95   0.340    -.1254494    .0432873
             6 vs 2  |  -.0107143   .0410659    -0.26   0.794     -.091202    .0697734
             4 vs 3  |   .0808237   .0430459     1.88   0.060    -.0035447    .1651921
             5 vs 3  |   .0224904   .0430459     0.52   0.601     -.061878    .1068587
             6 vs 3  |   .0528571   .0410659     1.29   0.198    -.0276306    .1333449
             5 vs 4  |  -.0583333   .0443563    -1.32   0.188      -.14527    .0286033
             6 vs 4  |  -.0279666   .0430459    -0.65   0.516    -.1123349    .0564018
             6 vs 5  |   .0303668   .0430459     0.71   0.481    -.0540016    .1147351
        ------------------------------------------------------------------------------
        Roman

        Comment

        Working...
        X