Announcement

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

  • Force model to go through 0/0 (repeated measures mixed model)

    Hi
    I would appreciate your help regarding this issue in a observational study (medical field). Is there a way to force this model to go through x=0 and y=0?

    I want to model
    the effect of a binary treatment variable: treatment
    on a continuous outcome measure that starts at value = 0: measure
    which is assessed repeatedly over time (time is continuous, not categorical): time
    in multiple subjecs: subject_id

    I did this using an approach like this:


    Code:
    mixed measure ///
               i.treatment##c.time_m##c.time_m ///   quadratic transformation
              || subject_id:
    Then I create marginal predictions


    Code:
    margins  i.treatment, at(time = (0(1)9))
     
    marginsplot, noci
    Which results in this graph: However, as measure starts at =0 in reality, the fact that Treatment 2 start below 0 would seem odd to a reviewer or reader of the article. Is there a way to force this model to go thorugh x=0 and y=0? I thought about the noconstant option but this doesn't work.

    Click image for larger version

Name:	image_34527.png
Views:	2
Size:	172.0 KB
ID:	1750962



  • #2
    As you don't give example data, I illustrate the approach using StataCorp's example childweight data set.
    Code:
    . webuse childweight, clear
    (Weight data on Asian children)
    
    .
    . mixed weight i.girl#c.age##c.age, nocons || id: // NOTE DISTINCTIVE USE OF # VS ##
    
    Performing EM optimization ...
    
    Performing gradient-based optimization:
    Iteration 0:  Log likelihood = -355.61291  
    Iteration 1:  Log likelihood = -355.61291  
    
    Computing standard errors ...
    
    Mixed-effects ML regression                         Number of obs    =     198
    Group variable: id                                  Number of groups =      68
                                                        Obs per group:
                                                                     min =       1
                                                                     avg =     2.9
                                                                     max =       5
                                                        Wald chi2(4)     = 2952.42
    Log likelihood = -355.61291                         Prob > chi2      =  0.0000
    
    ----------------------------------------------------------------------------------
              weight | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
          girl#c.age |
               Girl  |  -1.056917   .5738161    -1.84   0.065    -2.181575    .0677423
                     |
                 age |   9.174038   .3968372    23.12   0.000     8.396251    9.951824
                     |
    girl#c.age#c.age |
                Boy  |  -2.135763   .1502979   -14.21   0.000    -2.430342   -1.841185
               Girl  |  -1.821343   .1577031   -11.55   0.000    -2.130435    -1.51225
    ----------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
    -----------------------------+------------------------------------------------
    id: Identity                 |
                      var(_cons) |   9.937986   1.975423       6.73133    14.67222
    -----------------------------+------------------------------------------------
                   var(Residual) |    .554075   .0735825      .4270974    .7188035
    ------------------------------------------------------------------------------
    LR test vs. linear model: chibar2(01) = 83.66         Prob >= chibar2 = 0.0000
    
    .
    . margins girl, at(age = (0(0.5)2.5))
    
    Adjusted predictions                                       Number of obs = 198
    
    Expression: Linear prediction, fixed portion, predict()
    1._at: age =   0
    2._at: age =  .5
    3._at: age =   1
    4._at: age = 1.5
    5._at: age =   2
    6._at: age = 2.5
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
        _at#girl |
          1#Boy  |          0  (empty)
         1#Girl  |          0  (empty)
          2#Boy  |   4.053078   .1623266    24.97   0.000     3.734924    4.371232
         2#Girl  |   3.603225   .1692095    21.29   0.000      3.27158    3.934869
          3#Boy  |   7.038274   .2541935    27.69   0.000     6.540064    7.536484
         3#Girl  |   6.295778   .2640165    23.85   0.000     5.778316    6.813241
          4#Boy  |   8.955589   .2811197    31.86   0.000     8.404605    9.506573
         4#Girl  |    8.07766    .289765    27.88   0.000     7.509731    8.645589
          5#Boy  |   9.805022   .2602134    37.68   0.000     9.295013    10.31503
         5#Girl  |   8.948871   .2635516    33.95   0.000     8.432319    9.465423
          6#Boy  |   9.586573   .2503318    38.30   0.000     9.095932    10.07721
         6#Girl  |    8.90941   .2480882    35.91   0.000     8.423166    9.395654
    ------------------------------------------------------------------------------
    
    . marginsplot
    
    Variables that uniquely identify margins: age girl
    which produces the graph below. Note that there are no error bars around the (0,0) plotted points as these are forced values. (This model is not appropriate for this data, because children do not weigh 0 at age 0--but you can apply the same technique to your data to get these results.) You should not, however, represent this graph as being the output of the model that you originally ran--it is not that. And you should, in your presentation of these results, make it clear that the (0,0) point is constrained, not stochastic.


    Click image for larger version

Name:	childweight_demo.png
Views:	2
Size:	149.3 KB
ID:	1750987
    Attached Files
    Last edited by Clyde Schechter; 23 Apr 2024, 11:11.

    Comment


    • #3
      Dear Clyde
      Thank you very much!
      Those data are very similar to mine, if we change them a little bit and try to model the weight difference from birth.

      However, it fails to force through 0, when you include other fixed effects in the model (that are e.g. not also interacted with age) - is there an approach for such a case as well?
      The code produces the graph below, see x=0/y=0 in the right image...

      Code:
      webuse childweight, clear
      replace brthwt = brthwt/1000     // make it same unit as weight
      gen diff = weight-brthw           // make a weight difference variable
      
      * works as shown:
      mixed diff i.girl#c.age##c.age, nocons || id:
      margins i.girl, at(age = (0(0.5)2.5))
      marginsplot, name(one, replace)
      
      
      * adding brthwt to adjust for it (e.g. it likely is associated with weight change over time):
      mixed diff i.girl#c.age##c.age brthwt, nocons || id:
      margins i.girl, at(age = (0(0.5)2.5))
      marginsplot, name(two, replace)
      
      graph combine one two
      Click image for larger version

Name:	try.png
Views:	1
Size:	165.8 KB
ID:	1751005

      Last edited by Fabian Fortner; 23 Apr 2024, 13:26.

      Comment


      • #4
        Offhand, I can't think of how to do that. I'll ponder a while, and if I come up with a solution, I'll get back to you. In the meantime, if somebody else knows how to do this, do chime in.

        Comment


        • #5
          Ok, I found the solution: I centered the other independent variables... example:

          Code:
          webuse childweight, clear
          replace brthwt = brthwt/1000  // make it same unit as weight
          gen diff = weight-brthw           // make a weight difference variable
          egen bweight_mean = mean(brthwt)
          gen bweight_center = brthw-bweight_mean
          
          * works as shown
          mixed diff i.girl#c.age##c.age, nocons || id:
          margins i.girl, at(age = (0(0.5)2.5))
          marginsplot, name(one, replace)
          
          * adding brthwt
          mixed diff i.girl#c.age##c.age brthwt, nocons || id:
          margins i.girl, at(age = (0(0.5)2.5))
          marginsplot, name(two, replace)
          
          * adding brthwt centered instead
          mixed diff i.girl#c.age##c.age bweight_center, nocons  || id:
          margins i.girl, at(age = (0(0.5)2.5))
          marginsplot, name(three, replace)
          
          
          graph combine  one two three

          Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	213.6 KB
ID:	1751366

          Comment


          • #6
            Very nice! And thank you for sharing your solution.

            Comment

            Working...
            X