Announcement

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

  • Advice on applying a covariate in a mixed regression

    I’m returning with a problem not dissimilar to this one, but with a better idea of what is needed!

    We have measured the heart rate of embryos before and after a one-hour exposure to a drug at different pH levels. Different levels of pH were broadly established by adding different concentrations of sodium bicarbonate to the incubation medium, but sample pH was also measured at the same time as heart rate.

    So, I have a repeated-measures dependent variable of interest, hr; three independent factor variables, conc (concentration of drug), sb (concentration of sodium bicarbonate), and time; and a repeated-measures dependent continuous covariate, ph. Because both conc and sb can take decimal values, I have multiplied them by 10 so that they can be used as factor variables.

    For simplicity, let’s look at the control group, focussing solely on the interaction between sb and time. My model looks like this (in this instance, a sodium bicarbonate concentration of 17.9mM is the reference):

    Code:
    mixed hr ib179.sb10##time c.ph if conc==0
    or, omitting the covariate,
    Code:
    mixed hr ib179.sb10##time if conc==0
    Running the latter gives me the following:
    Code:
    . mixed hr ib179.sb10##time if conc==0 || id:
    
    Performing EM optimization: 
    
    Performing gradient-based optimization: 
    
    Iteration 0:   log likelihood =  -436.7289  
    Iteration 1:   log likelihood = -436.72557  
    Iteration 2:   log likelihood = -436.72557  
    
    Computing standard errors:
    
    Mixed-effects ML regression                     Number of obs     =        106
    Group variable: id                              Number of groups  =         53
    
                                                    Obs per group:
                                                                  min =          2
                                                                  avg =        2.0
                                                                  max =          2
    
                                                    Wald chi2(5)      =      78.34
    Log likelihood = -436.72557                     Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
              hr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            sb10 |
              0  |  -4.996337    6.29288    -0.79   0.427    -17.33016    7.337482
             15  |  -.4249084    6.29288    -0.07   0.946    -12.75873    11.90891
                 |
          1.time |  -3.179487   2.842858    -1.12   0.263    -8.751387    2.392413
                 |
       sb10#time |
            0 1  |  -28.82051    7.28761    -3.95   0.000    -43.10397   -14.53706
           15 1  |   -34.5348    7.28761    -4.74   0.000    -48.81825   -20.25134
                 |
           _cons |   187.2821    2.45482    76.29   0.000     182.4707    192.0934
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    id: Identity                 |
                      var(_cons) |   77.42346   33.98905      32.74865    183.0424
    -----------------------------+------------------------------------------------
                   var(Residual) |    157.596   30.61415      107.6944    230.6201
    ------------------------------------------------------------------------------
    LR test vs. linear model: chibar2(01) = 6.09          Prob >= chibar2 = 0.0068
    
    . margins sb10#time
    
    Adjusted predictions                            Number of obs     =        106
    
    Expression   : Linear prediction, fixed portion, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
       sb10#time |
            0 0  |   182.2857   5.794325    31.46   0.000      170.929    193.6424
            0 1  |   150.2857   5.794325    25.94   0.000      138.929    161.6424
           15 0  |   186.8571   5.794325    32.25   0.000     175.5005    198.2138
           15 1  |   149.1429   5.794325    25.74   0.000     137.7862    160.4995
          179 0  |   187.2821    2.45482    76.29   0.000     182.4707    192.0934
          179 1  |   184.1026    2.45482    75.00   0.000     179.2912    188.9139
    ------------------------------------------------------------------------------
    As you can see, there is a substantial reduction in heart rate when the concentration of sodium bicarbonate is 0mM or 1.5mM, compared to the reference.

    If I run the covariate model, there is a major problem:
    Code:
    . mixed hr ib179.sb10##time c.ph if conc==0 || id:
    
    Performing EM optimization: 
    
    Performing gradient-based optimization: 
    
    Iteration 0:   log likelihood = -435.33309  
    Iteration 1:   log likelihood = -435.33077  
    Iteration 2:   log likelihood = -435.33077  
    
    Computing standard errors:
    
    Mixed-effects ML regression                     Number of obs     =        106
    Group variable: id                              Number of groups  =         53
    
                                                    Obs per group:
                                                                  min =          2
                                                                  avg =        2.0
                                                                  max =          2
    
                                                    Wald chi2(6)      =      84.12
    Log likelihood = -435.33077                     Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
              hr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            sb10 |
              0  |   54.66829   35.83739     1.53   0.127    -15.57171    124.9083
             15  |    37.3623    23.2042     1.61   0.107    -8.117095    82.84169
                 |
          1.time |  -4.075213   2.822213    -1.44   0.149    -9.606648    1.456223
                 |
       sb10#time |
            0 1  |  -36.44387   8.415938    -4.33   0.000    -52.93881   -19.94894
           15 1  |  -37.57096   7.329471    -5.13   0.000    -51.93646   -23.20546
                 |
              ph |   35.28616   20.87117     1.69   0.091    -5.620595    76.19291
           _cons |  -70.74118   152.6358    -0.46   0.643    -369.9019    228.4196
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    id: Identity                 |
                      var(_cons) |   80.96055    33.8667      35.66206    183.7979
    -----------------------------+------------------------------------------------
                   var(Residual) |   149.8417   29.23925      102.2196      219.65
    ------------------------------------------------------------------------------
    LR test vs. linear model: chibar2(01) = 6.85          Prob >= chibar2 = 0.0044
    
    . margins sb10#time
    
    Predictive margins                              Number of obs     =        106
    
    Expression   : Linear prediction, fixed portion, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
       sb10#time |
            0 0  |   230.2311   28.93441     7.96   0.000     173.5207    286.9415
            0 1  |    189.712   24.01656     7.90   0.000     142.6405    236.7836
           15 0  |   212.9251   16.45329    12.94   0.000     180.6773     245.173
           15 1  |    171.279   14.29693    11.98   0.000     143.2575    199.3004
          179 0  |   175.5628   7.346201    23.90   0.000     161.1646    189.9611
          179 1  |   171.4876   7.848076    21.85   0.000     156.1057    186.8696
    ------------------------------------------------------------------------------
    While the adjusted margins for the reference group are similar to the unadjusted ones, those for the other two groups are way out, particularly at time 0!

    It seems that the covariate is correcting for pH differences between pH blocks, but that is already accounted for in the model by sb. What I really wanted to do with ph is to control for any influence on the change in pH upon hr within each.

    I cannot add an interaction with ph because it's collinear with sb. Any thoughts on how this could be remedied would be appreciated!


    Stata 14.2MP
    OS X

  • #2
    And the data:
    Code:
    . list if conc==0
    
         +--------------------------------------------------------------+
         |   id   time   vol   conc     sb    hr     ph   conc10   sb10 |
         |--------------------------------------------------------------|
     89. | 9221      0   2.5      0    1.5   176   6.13        0     15 |
     90. | 9221      1   2.5      0    1.5   164   6.34        0     15 |
     91. | 9222      0   2.5      0   17.9   188   7.27        0    179 |
     92. | 9222      1   2.5      0   17.9   164   7.38        0    179 |
     95. | 9224      0   2.5      0    1.5   180   6.23        0     15 |
         |--------------------------------------------------------------|
     96. | 9224      1   2.5      0    1.5   140   6.34        0     15 |
     97. | 9225      0   2.5      0   17.9   184   7.31        0    179 |
     98. | 9225      1   2.5      0   17.9   180   7.35        0    179 |
    101. | 9227      0   2.5      0    1.5   168   6.26        0     15 |
    102. | 9227      1   2.5      0    1.5   164   6.39        0     15 |
         |--------------------------------------------------------------|
    103. | 9228      0   2.5      0   17.9   176   7.33        0    179 |
    104. | 9228      1   2.5      0   17.9   172   7.36        0    179 |
    107. | 9231      0   2.5      0   17.9   208   7.33        0    179 |
    108. | 9231      1   2.5      0   17.9   208   7.34        0    179 |
    111. | 9233      0   2.5      0    1.5   196   6.27        0     15 |
         |--------------------------------------------------------------|
    112. | 9233      1   2.5      0    1.5   192   6.32        0     15 |
    115. | 9236      0   2.5      0    1.5   204   6.27        0     15 |
    116. | 9236      1   2.5      0    1.5    96   6.34        0     15 |
    117. | 9237      0   2.5      0   17.9   160   7.33        0    179 |
    118. | 9237      1   2.5      0   17.9   184   7.34        0    179 |
         |--------------------------------------------------------------|
    121. | 9239      0   2.5      0    1.5   196   6.26        0     15 |
    122. | 9239      1   2.5      0    1.5   176   6.37        0     15 |
    123. | 9240      0   2.5      0   17.9   160   7.32        0    179 |
    124. | 9240      1   2.5      0   17.9   152   7.31        0    179 |
    127. | 9243      0   2.5      0   17.9   184   7.33        0    179 |
         |--------------------------------------------------------------|
    128. | 9243      1   2.5      0   17.9   172   7.31        0    179 |
    131. | 9245      0   2.5      0    1.5   188   6.27        0     15 |
    132. | 9245      1   2.5      0    1.5   112   6.37        0     15 |
    133. | 9246      0   2.5      0   17.9   160   7.31        0    179 |
    134. | 9246      1   2.5      0   17.9   152   7.32        0    179 |
         |--------------------------------------------------------------|
    137. | 9249      0   2.5      0   17.9   156   7.35        0    179 |
    138. | 9249      1   2.5      0   17.9   168   7.31        0    179 |
    141. | 9251      0   2.5      0   17.9   188   7.33        0    179 |
    142. | 9251      1   2.5      0   17.9   184   7.34        0    179 |
    143. | 9255      0   2.5      0   17.9   184   7.38        0    179 |
         |--------------------------------------------------------------|
    144. | 9255      1   2.5      0   17.9   176   7.41        0    179 |
    145. | 9259      0   2.5      0   17.9   192   7.35        0    179 |
    146. | 9259      1   2.5      0   17.9   192   7.38        0    179 |
    147. | 9261      0   2.5      0   17.9   184   7.36        0    179 |
    148. | 9261      1   2.5      0   17.9   188   7.39        0    179 |
         |--------------------------------------------------------------|
    149. | 9262      0   2.5      0   17.9   184   7.33        0    179 |
    150. | 9262      1   2.5      0   17.9   192   7.34        0    179 |
    151. | 9267      0   2.5      0   17.9   196   7.31        0    179 |
    152. | 9267      1   2.5      0   17.9   188   7.31        0    179 |
    153. | 9272      0   2.5      0   17.9   184   7.32        0    179 |
         |--------------------------------------------------------------|
    154. | 9272      1   2.5      0   17.9   184   7.36        0    179 |
    157. | 9311      0   2.5      0   17.9   172   7.34        0    179 |
    158. | 9311      1   2.5      0   17.9   164   7.34        0    179 |
    159. | 9315      0   2.5      0   17.9   184   7.33        0    179 |
    160. | 9315      1   2.5      0   17.9   176   7.34        0    179 |
         |--------------------------------------------------------------|
    163. | 9319      0   2.5      0   17.9   184   7.32        0    179 |
    164. | 9319      1   2.5      0   17.9   184   7.36        0    179 |
    165. | 9322      0   2.5      0   17.9   188   7.33        0    179 |
    166. | 9322      1   2.5      0   17.9   180   7.38        0    179 |
    169. | 9325      0   2.5      0   17.9   196   7.35        0    179 |
         |--------------------------------------------------------------|
    170. | 9325      1   2.5      0   17.9   192   7.39        0    179 |
    173. | 9328      0   2.5      0   17.9   196   7.38        0    179 |
    174. | 9328      1   2.5      0   17.9   180   7.38        0    179 |
    179. | 9333      0   2.5      0   17.9   200   7.42        0    179 |
    180. | 9333      1   2.5      0   17.9   200   7.35        0    179 |
         |--------------------------------------------------------------|
    183. | 9338      0   2.5      0   17.9   188   7.35        0    179 |
    184. | 9338      1   2.5      0   17.9   188   7.32        0    179 |
    187. | 9341      0   2.5      0   17.9   208   7.36        0    179 |
    188. | 9341      1   2.5      0   17.9   192    7.4        0    179 |
    191. | 9345      0   2.5      0   17.9   196   7.28        0    179 |
         |--------------------------------------------------------------|
    192. | 9345      1   2.5      0   17.9   196   7.32        0    179 |
    193. | 9348      0   2.5      0   17.9   200   7.32        0    179 |
    194. | 9348      1   2.5      0   17.9   204   7.36        0    179 |
    217. | 9397      0   2.5      0   17.9   192   7.28        0    179 |
    218. | 9397      1   2.5      0   17.9   192   7.33        0    179 |
         |--------------------------------------------------------------|
    227. | 9406      0   2.5      0   17.9   200   7.34        0    179 |
    228. | 9406      1   2.5      0   17.9   192   7.36        0    179 |
    229. | 9411      0   2.5      0   17.9   196   7.35        0    179 |
    230. | 9411      1   2.5      0   17.9   184   7.37        0    179 |
    237. | 9418      0   2.5      0   17.9   200   7.41        0    179 |
         |--------------------------------------------------------------|
    238. | 9418      1   2.5      0   17.9   204   7.39        0    179 |
    241. | 9500      0   2.5      0   17.9   164    7.2        0    179 |
    242. | 9500      1   2.5      0   17.9   176   7.25        0    179 |
    243. | 9501      0   2.5      0      0   180   5.66        0      0 |
    244. | 9501      1   2.5      0      0   136   5.81        0      0 |
         |--------------------------------------------------------------|
    247. | 9504      0   2.5      0   17.9   176   7.22        0    179 |
    248. | 9504      1   2.5      0   17.9   192   7.27        0    179 |
    249. | 9507      0   2.5      0   17.9   200   7.24        0    179 |
    250. | 9507      1   2.5      0   17.9   184   7.29        0    179 |
    251. | 9508      0   2.5      0      0   180   5.92        0      0 |
         |--------------------------------------------------------------|
    252. | 9508      1   2.5      0      0   164   6.03        0      0 |
    253. | 9510      0   2.5      0      0   184   5.56        0      0 |
    254. | 9510      1   2.5      0      0   176   5.87        0      0 |
    257. | 9512      0   2.5      0      0   184   5.52        0      0 |
    258. | 9512      1   2.5      0      0   168   5.82        0      0 |
         |--------------------------------------------------------------|
    261. | 9514      0   2.5      0   17.9   200   7.24        0    179 |
    262. | 9514      1   2.5      0   17.9   196    7.3        0    179 |
    263. | 9515      0   2.5      0   17.9   180   7.29        0    179 |
    264. | 9515      1   2.5      0   17.9   180   7.34        0    179 |
    267. | 9518      0   2.5      0      0   168   5.59        0      0 |
         |--------------------------------------------------------------|
    268. | 9518      1   2.5      0      0   140   6.08        0      0 |
    271. | 9520      0   2.5      0      0   192   5.52        0      0 |
    272. | 9520      1   2.5      0      0   112   5.48        0      0 |
    273. | 9521      0   2.5      0   17.9   192   7.22        0    179 |
    274. | 9521      1   2.5      0   17.9   188    7.2        0    179 |
         |--------------------------------------------------------------|
    275. | 9524      0   2.5      0   17.9   204   7.15        0    179 |
    276. | 9524      1   2.5      0   17.9   184   7.29        0    179 |
    279. | 9526      0   2.5      0      0   188   5.58        0      0 |
    280. | 9526      1   2.5      0      0   156   5.95        0      0 |
    281. | 9527      0   2.5      0   17.9   200    7.2        0    179 |
         |--------------------------------------------------------------|
    282. | 9527      1   2.5      0   17.9   196   7.29        0    179 |
         +--------------------------------------------------------------+
    Stata 14.2MP
    OS X

    Comment


    • #3
      The problem here is that there is a very strong dependency, almost functional, relationship between ph and sb10 that -margins- does not know about. So in calculating its results, -margins- is allowing sb10 to vary independently of ph, but that is not valid in this situation. It is somewhat analogous to when people mistakenly code a quadratic model by having separate variables x and xsq (instead of correctly using c.x##c.x): then margins gives incorrect results because it varies x and xsq independently of each other rather than linking them. But in this case, there is nothing analogous to c.x##c.x to rescue it.

      I think, however, you may get better results if you try
      Code:
      margins time, over(sb10)
      This command will do separate calculations for each level of sb10, those calculations using only the observations with the particular value of sb10. Therefore, ph will be limited to the amount of variation it can exhibit within a level of xb10, which, I think, is fairly small. Now, this sounds like a designed experiment, with balanced assignment of both drug concentration and sodium bicarbonate concentration. In that case, the fact that this -over(sb10)- approach will not adjust for different distributions of other variables across sb groups may not be a problem, because it sounds like there won't be any such differences (except on pH, which is precisely what you are trying to avoid adjusting for!)

      Added: I would have loved to test this out on your data. But -list- output is difficult to import to Stata, and, frankly I don't have the time to wrestle with it. Had you used -dataex- to post your example data, I could have done it with a simple copy/paste operation. That's why all forum members are requested to use -dataex- whenever they post example data. You can install the -dataex- command by running -ssc install dataex-. Then read -help dataex- for the simple instructions for using it. Please use -dataex- in the future.
      Last edited by Clyde Schechter; 20 Jul 2017, 09:56.

      Comment


      • #4
        Wow, thank you Clyde, that seems to give me a more meaningful result!
        Code:
        . margins time, over(sb10)
        
        Predictive margins                              Number of obs     =        106
        
        Expression   : Linear prediction, fixed portion, predict()
        over         : sb10
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
           sb10#time |
                0 0  |   186.5453   6.270516    29.75   0.000     174.2553    198.8352
                0 1  |   146.0262   6.270516    23.29   0.000     133.7362    158.3162
               15 0  |   188.8231   5.858661    32.23   0.000     177.3403    200.3059
               15 1  |   147.1769   5.858661    25.12   0.000     135.6941    158.6597
              179 0  |   187.7299   2.447076    76.72   0.000     182.9337    192.5261
              179 1  |   183.6547   2.447076    75.05   0.000     178.8585    188.4509
        ------------------------------------------------------------------------------
        It's interesting, to me at least, as a complete ignoramus, that whereas the covariate analysis that I used originally gave me separate SE for each time point, this one gives me the same kind of 'shared'/pooled SE that the non-covariate analysis yielded.

        I suspect that the analysis will become more complicated when I add conc into the mix though.

        I apologise for not using -dataex- . This is the properly-formatted output:
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int id byte time double(vol conc sb) int hr double ph float(conc10 sb10)
        9221 0 2.5 0  1.5 176 6.13 0  15
        9221 1 2.5 0  1.5 164 6.34 0  15
        9222 0 2.5 0 17.9 188 7.27 0 179
        9222 1 2.5 0 17.9 164 7.38 0 179
        9224 0 2.5 0  1.5 180 6.23 0  15
        9224 1 2.5 0  1.5 140 6.34 0  15
        9225 0 2.5 0 17.9 184 7.31 0 179
        9225 1 2.5 0 17.9 180 7.35 0 179
        9227 0 2.5 0  1.5 168 6.26 0  15
        9227 1 2.5 0  1.5 164 6.39 0  15
        9228 0 2.5 0 17.9 176 7.33 0 179
        9228 1 2.5 0 17.9 172 7.36 0 179
        9231 0 2.5 0 17.9 208 7.33 0 179
        9231 1 2.5 0 17.9 208 7.34 0 179
        9233 0 2.5 0  1.5 196 6.27 0  15
        9233 1 2.5 0  1.5 192 6.32 0  15
        9236 0 2.5 0  1.5 204 6.27 0  15
        9236 1 2.5 0  1.5  96 6.34 0  15
        9237 0 2.5 0 17.9 160 7.33 0 179
        9237 1 2.5 0 17.9 184 7.34 0 179
        9239 0 2.5 0  1.5 196 6.26 0  15
        9239 1 2.5 0  1.5 176 6.37 0  15
        9240 0 2.5 0 17.9 160 7.32 0 179
        9240 1 2.5 0 17.9 152 7.31 0 179
        9243 0 2.5 0 17.9 184 7.33 0 179
        9243 1 2.5 0 17.9 172 7.31 0 179
        9245 0 2.5 0  1.5 188 6.27 0  15
        9245 1 2.5 0  1.5 112 6.37 0  15
        9246 0 2.5 0 17.9 160 7.31 0 179
        9246 1 2.5 0 17.9 152 7.32 0 179
        9249 0 2.5 0 17.9 156 7.35 0 179
        9249 1 2.5 0 17.9 168 7.31 0 179
        9251 0 2.5 0 17.9 188 7.33 0 179
        9251 1 2.5 0 17.9 184 7.34 0 179
        9255 0 2.5 0 17.9 184 7.38 0 179
        9255 1 2.5 0 17.9 176 7.41 0 179
        9259 0 2.5 0 17.9 192 7.35 0 179
        9259 1 2.5 0 17.9 192 7.38 0 179
        9261 0 2.5 0 17.9 184 7.36 0 179
        9261 1 2.5 0 17.9 188 7.39 0 179
        9262 0 2.5 0 17.9 184 7.33 0 179
        9262 1 2.5 0 17.9 192 7.34 0 179
        9267 0 2.5 0 17.9 196 7.31 0 179
        9267 1 2.5 0 17.9 188 7.31 0 179
        9272 0 2.5 0 17.9 184 7.32 0 179
        9272 1 2.5 0 17.9 184 7.36 0 179
        9311 0 2.5 0 17.9 172 7.34 0 179
        9311 1 2.5 0 17.9 164 7.34 0 179
        9315 0 2.5 0 17.9 184 7.33 0 179
        9315 1 2.5 0 17.9 176 7.34 0 179
        9319 0 2.5 0 17.9 184 7.32 0 179
        9319 1 2.5 0 17.9 184 7.36 0 179
        9322 0 2.5 0 17.9 188 7.33 0 179
        9322 1 2.5 0 17.9 180 7.38 0 179
        9325 0 2.5 0 17.9 196 7.35 0 179
        9325 1 2.5 0 17.9 192 7.39 0 179
        9328 0 2.5 0 17.9 196 7.38 0 179
        9328 1 2.5 0 17.9 180 7.38 0 179
        9333 0 2.5 0 17.9 200 7.42 0 179
        9333 1 2.5 0 17.9 200 7.35 0 179
        9338 0 2.5 0 17.9 188 7.35 0 179
        9338 1 2.5 0 17.9 188 7.32 0 179
        9341 0 2.5 0 17.9 208 7.36 0 179
        9341 1 2.5 0 17.9 192  7.4 0 179
        9345 0 2.5 0 17.9 196 7.28 0 179
        9345 1 2.5 0 17.9 196 7.32 0 179
        9348 0 2.5 0 17.9 200 7.32 0 179
        9348 1 2.5 0 17.9 204 7.36 0 179
        9397 0 2.5 0 17.9 192 7.28 0 179
        9397 1 2.5 0 17.9 192 7.33 0 179
        9406 0 2.5 0 17.9 200 7.34 0 179
        9406 1 2.5 0 17.9 192 7.36 0 179
        9411 0 2.5 0 17.9 196 7.35 0 179
        9411 1 2.5 0 17.9 184 7.37 0 179
        9418 0 2.5 0 17.9 200 7.41 0 179
        9418 1 2.5 0 17.9 204 7.39 0 179
        9500 0 2.5 0 17.9 164  7.2 0 179
        9500 1 2.5 0 17.9 176 7.25 0 179
        9501 0 2.5 0    0 180 5.66 0   0
        9501 1 2.5 0    0 136 5.81 0   0
        9504 0 2.5 0 17.9 176 7.22 0 179
        9504 1 2.5 0 17.9 192 7.27 0 179
        9507 0 2.5 0 17.9 200 7.24 0 179
        9507 1 2.5 0 17.9 184 7.29 0 179
        9508 0 2.5 0    0 180 5.92 0   0
        9508 1 2.5 0    0 164 6.03 0   0
        9510 0 2.5 0    0 184 5.56 0   0
        9510 1 2.5 0    0 176 5.87 0   0
        9512 0 2.5 0    0 184 5.52 0   0
        9512 1 2.5 0    0 168 5.82 0   0
        9514 0 2.5 0 17.9 200 7.24 0 179
        9514 1 2.5 0 17.9 196  7.3 0 179
        9515 0 2.5 0 17.9 180 7.29 0 179
        9515 1 2.5 0 17.9 180 7.34 0 179
        9518 0 2.5 0    0 168 5.59 0   0
        9518 1 2.5 0    0 140 6.08 0   0
        9520 0 2.5 0    0 192 5.52 0   0
        9520 1 2.5 0    0 112 5.48 0   0
        9521 0 2.5 0 17.9 192 7.22 0 179
        9521 1 2.5 0 17.9 188  7.2 0 179
        end
        Stata 14.2MP
        OS X

        Comment


        • #5
          Actually, I'm noticing something weird in the subsequent post-hoc analysis.

          If I read these correctly, the inclusion of ph in the model does not have a significant effect on the outcome:
          Code:
          . mixed hr ib179.sb10##time if conc==0
          
          Mixed-effects ML regression                     Number of obs     =        106
          
                                                          Wald chi2(5)      =      67.52
          Log likelihood =  -439.7699                     Prob > chi2       =     0.0000
          
          ------------------------------------------------------------------------------
                    hr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  sb10 |
                    0  |  -4.996337    6.29288    -0.79   0.427    -17.33016    7.337482
                   15  |  -.4249084    6.29288    -0.07   0.946    -12.75873    11.90891
                       |
                1.time |  -3.179487   3.471639    -0.92   0.360    -9.983775      3.6248
                       |
             sb10#time |
                  0 1  |  -28.82051   8.899477    -3.24   0.001    -46.26317   -11.37786
                 15 1  |   -34.5348   8.899477    -3.88   0.000    -51.97745   -17.09214
                       |
                 _cons |   187.2821    2.45482    76.29   0.000     182.4707    192.0934
          ------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
          -----------------------------+------------------------------------------------
                         var(Residual) |   235.0194    32.2824      179.5487    307.6276
          ------------------------------------------------------------------------------
          
          . mixed hr ib179.sb10##time c.ph if conc==0
          
          Mixed-effects ML regression                     Number of obs     =        106
          
                                                          Wald chi2(6)      =      70.87
          Log likelihood = -438.75655                     Prob > chi2       =     0.0000
          
          ------------------------------------------------------------------------------
                    hr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  sb10 |
                    0  |   43.54598   34.50261     1.26   0.207    -24.07789    111.1698
                   15  |   30.31824   22.37749     1.35   0.175    -13.54084    74.17733
                       |
                1.time |  -3.908237   3.476143    -1.12   0.261    -10.72135    2.904879
                       |
             sb10#time |
                  0 1  |  -35.02277    9.82347    -3.57   0.000    -54.27642   -15.76913
                 15 1  |  -37.00498    8.98236    -4.12   0.000    -54.61008   -19.39988
                       |
                    ph |   28.70833    20.0694     1.43   0.153    -10.62698    68.04363
                 _cons |  -22.64208   146.7738    -0.15   0.877    -310.3134    265.0292
          ------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
          -----------------------------+------------------------------------------------
                         var(Residual) |   230.5686   31.67103      176.1484    301.8017
          ------------------------------------------------------------------------------
          Yet, if I run margins, I get different outcomes when ph is included/excluded.

          Without ph:
          Code:
          . margins time, dydx(sb10)
          
          Conditional marginal effects                    Number of obs     =        106
          
          Expression   : Linear prediction, fixed portion, predict()
          dy/dx w.r.t. : 0.sb10 15.sb10
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          0.sb10       |
                  time |
                    0  |  -4.996337    6.29288    -0.79   0.427    -17.33016    7.337482
                    1  |  -33.81685    6.29288    -5.37   0.000    -46.15067   -21.48303
          -------------+----------------------------------------------------------------
          15.sb10      |
                  time |
                    0  |  -.4249084    6.29288    -0.07   0.946    -12.75873    11.90891
                    1  |  -34.95971    6.29288    -5.56   0.000    -47.29353   -22.62589
          ------------------------------------------------------------------------------
          Note: dy/dx for factor levels is the discrete change from the base level.
          with ph:
          Code:
          . margins time, dydx(sb10)
          
          Average marginal effects                        Number of obs     =        106
          
          Expression   : Linear prediction, fixed portion, predict()
          dy/dx w.r.t. : 0.sb10 15.sb10
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          0.sb10       |
                  time |
                    0  |   43.54598   34.50261     1.26   0.207    -24.07789    111.1698
                    1  |   8.523203   30.24822     0.28   0.778    -50.76221    67.80862
          -------------+----------------------------------------------------------------
          15.sb10      |
                  time |
                    0  |   30.31824   22.37749     1.35   0.175    -13.54084    74.17733
                    1  |  -6.686735   20.72457    -0.32   0.747    -47.30614    33.93267
          ------------------------------------------------------------------------------
          Note: dy/dx for factor levels is the discrete change from the base level.
          The absolute difference between the experimental and reference groups hardly changes, and is substantial, yet is no longer statistically significant. Is there something wrong with the model, or is this to be expected?
          Stata 14.2MP
          OS X

          Comment


          • #6
            I cannot use dydx without a comparison!
            Stata 14.2MP
            OS X

            Comment


            • #7
              When you have a model that includes two strongly correlated variables, like sb and ph, the results for each of those variables can be very unstable. These results do not surprise me. In a model containing sb but nob ph, sb is, in part, serving as a proxy for ph, in addition to exerting its own effects. Consequently when you add ph to the model, ph relieves sb of that part of its apparent effect in the earlier model, and probably also "steals" some of the effect directly away from sb. This kind of thing happens all the time when highly correlated variables co-occur in a regression model.

              Given the very strong association between ph and sb here, I do not think it is possible to reliably estimate their separate effects in this data. What you really need to do is to separately analyze each level of sb, to see the effect of ph within an sb level. That is, actually, what -margins, over(sb)- did for you. You can also get it to do this for the marginal effects of treatment:

              Code:
              margins, dydx(time) over(sb10)
              This will carry out, in effect, separate estimates of the marginal effect of time within each sb10 group. By using the -over()- syntax, you will prevent Stata from treating ph as a variable independent of sb10. Since time = 0 is a pre-treatment measure and time = 1 is a post-treatment measure, the marginal effect of the time variable is, in effect, the sb10-level specific effect of treatment on heart rate.

              Comment


              • #8
                Thank you once again, Clyde. That is very helpful!

                sb was set to establish fairly coarse differences between groups (ca. 1 pH unit), whereas the 'drift' in per sample pH over the course of one hour is relatively subtle (>0.2 pH units). Experimental sb were always set lower than the reference (i.e. the reference was neutral pH, and the experimental groups were acidic), whereas measured ph generally, but not exclusively, drifts upwards (i.e. towards neutral, albeit in a limited manner).

                But given the strong correlation between sb and ph in the model, and the fact that ph does not appear to add a significant contribution to the model for hr (p=0.153), do you think that it's justifiable to drop this covariate, and simplify the model?

                Code:
                . mixed hr ib179.sb10##time c.ph if conc==0
                
                Mixed-effects ML regression                     Number of obs     =        106
                
                                                                Wald chi2(6)      =      70.87
                Log likelihood = -438.75655                     Prob > chi2       =     0.0000
                
                ------------------------------------------------------------------------------
                          hr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                        sb10 |
                          0  |   43.54598   34.50261     1.26   0.207    -24.07789    111.1698
                         15  |   30.31824   22.37749     1.35   0.175    -13.54084    74.17733
                             |
                      1.time |  -3.908237   3.476143    -1.12   0.261    -10.72135    2.904879
                             |
                   sb10#time |
                        0 1  |  -35.02277    9.82347    -3.57   0.000    -54.27642   -15.76913
                       15 1  |  -37.00498    8.98236    -4.12   0.000    -54.61008   -19.39988
                             |
                          ph |   28.70833    20.0694     1.43   0.153    -10.62698    68.04363
                       _cons |  -22.64208   146.7738    -0.15   0.877    -310.3134    265.0292
                ------------------------------------------------------------------------------
                
                ------------------------------------------------------------------------------
                  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
                -----------------------------+------------------------------------------------
                               var(Residual) |   230.5686   31.67103      176.1484    301.8017
                ------------------------------------------------------------------------------
                Last edited by Nigel Moore; 21 Jul 2017, 02:03. Reason: Edited to include the regression output for clarity
                Stata 14.2MP
                OS X

                Comment


                • #9
                  I'm not a fan of using statistical significance criteria to decide on what to include in a model. Indeed, in this case the "significance" or lack thereof of ph may well be an artifact resulting from its strong correlation with sb10. So I think it's especially treacherous to rely on the p-value in this situation.

                  Here's how I would think about it. Your reason for considering ph is that you felt it might influence the outcome, but that concern was at the micro level, b which I mean, given two units with the same sb concentration but different ph, there was a worry that ph would exert some real influence on the outcome. You really were not interested in looking at macro-level effects of large differences in ph that come with different levels of sb concentration. So let's look at it that way.

                  What is the largest difference in ph values among study units having the same sb concentration? Multiply that maximum difference by 28.71 (the approximate ph coefficient in the regression). That product is the largest possible effect of ph on heart rate in your data when sb concentration is held constant. If that product is large enough to matter from a practical perspective, then ph should stay in the model. If it is small, so to speak, a "rounding error," then I would drop ph.

                  Comment


                  • #10
                    That's a good way of looking at it. In the pH neutral group (sb==17.9), the maximum effect is quite small (ca. -3bpm), but is also around the actual reduction in HR for that group. In the 0mM SB group, the maximal effect is much larger (ca. -14bpm). So I think you're right, ph has to remain in the model.

                    That's going to make things more challenging, and I'll probably check my workings back here. But I'll start another thread for that.

                    Thanks for all your help on this, Clyde. It's much appreciated!
                    Code:
                     
                    sb ∆HR (-ph) ∆HR (+ph)
                    17.9 3.2 4
                    1.5 37.8 41.6
                    0 32 40.5
                    Code:
                    . bysort sb: tabulate Δph if gd==11 & treat==0 & (niad=="N" | niad=="I")
                    
                    ----------------------------------------------------------------------------------------------------
                    -> sb = 0
                    
                            Δph |      Freq.     Percent        Cum.
                    ------------+-----------------------------------
                           -.49 |          1       14.29       14.29
                           -.37 |          1       14.29       28.57
                           -.31 |          1       14.29       42.86
                            -.3 |          1       14.29       57.14
                           -.15 |          1       14.29       71.43
                           -.11 |          1       14.29       85.71
                            .04 |          1       14.29      100.00
                    ------------+-----------------------------------
                          Total |          7      100.00
                    
                    ----------------------------------------------------------------------------------------------------
                    -> sb = 1.5
                    
                            Δph |      Freq.     Percent        Cum.
                    ------------+-----------------------------------
                           -.21 |          1       14.29       14.29
                           -.13 |          1       14.29       28.57
                           -.11 |          2       28.57       57.14
                            -.1 |          1       14.29       71.43
                           -.07 |          1       14.29       85.71
                           -.05 |          1       14.29      100.00
                    ------------+-----------------------------------
                          Total |          7      100.00
                    
                    ----------------------------------------------------------------------------------------------------
                    -> sb = 17.9
                    
                            Δph |      Freq.     Percent        Cum.
                    ------------+-----------------------------------
                           -.14 |          1        2.56        2.56
                           -.11 |          1        2.56        5.13
                           -.09 |          1        2.56        7.69
                           -.06 |          1        2.56       10.26
                           -.05 |          6       15.38       25.64
                           -.04 |          7       17.95       43.59
                           -.03 |          4       10.26       53.85
                           -.02 |          2        5.13       58.97
                           -.01 |          6       15.38       74.36
                              0 |          3        7.69       82.05
                            .01 |          1        2.56       84.62
                            .02 |          3        7.69       92.31
                            .03 |          1        2.56       94.87
                            .04 |          1        2.56       97.44
                            .07 |          1        2.56      100.00
                    ------------+-----------------------------------
                          Total |         39      100.00
                    Last edited by Nigel Moore; 21 Jul 2017, 09:56.
                    Stata 14.2MP
                    OS X

                    Comment


                    • #11
                      Sorry, I know I said that I would post anything new in another thread, but this is directly germain to this discussion.

                      If -order(sb10)- is used to limit the application of ph within sb groups, how can I compare effects at time between sb groups?
                      Stata 14.2MP
                      OS X

                      Comment


                      • #12
                        I would do:
                        Code:
                        margins, dydx(time) over(sb10) pwcompare(effects)

                        Comment


                        • #13
                          Thank you, Clyde!
                          Stata 14.2MP
                          OS X

                          Comment

                          Working...
                          X