Announcement

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

  • margins after stcox

    Hi All,

    I've estimated a survival model using stcox. One of the key covariates is an interaction between X1 (a continuous variable) and X2 (an indicator on a 1/0 scale). I'm using the margins command to compute the hazard ratio of a one-unit change in X1 at both values of the X2. My question concerns interpreting the results. Here's the code and output:

    stcox dv c.X1##i.X2, robust nohr

    margins X2, dydx(X1) atmeans noatlegend level(90)

    Conditional marginal effects Number of obs = 872
    Model VCE : Robust

    Expression : Relative hazard, predict()
    dy/dx w.r.t. : dv

    ------------------------------------------------------------------------------
    | Delta-method
    | dy/dx Std. Err. z P>|z| [90% Conf. Interval]
    -------------+----------------------------------------------------------------
    X1 |
    X2 |
    0 | .2511091 .2013735 1.25 0.212 -.0801209 .5823391
    1 | .6222435 .3686444 1.69 0.091 .0158775 1.22861
    ------------------------------------------------------------------------------

    I assumed that the margins output contained hazard ratios (the output indicates "relative hazard" at the top). However, a hazard ratio close to 1.0 is an insignificant effect (where a hazard ratio < 1 indicates a negative effect and a hazard ratio >1 indicates a positive effect). Why, then, is margins computing the significance of X1 at the values of X2 as if 0 is an insignificant effect (notice the confidence interval at X2=0 is insignificant and contains 0).

    Perhaps a better way of phrasing the question is: "What the heck does 0.2511 and 0.6222 in the output indicate?" Is it simply the increase in the size of the hazard ratio (where the interpretation at X2=0 would be a one-unit increase in X1 increases the probability of [the dependent variable occurring] by 25%).

    Sorry, I know I'm missing something, but for the life of me I can't figure it out. Please help!

  • #2
    I don't think the margins command you used gives you hazard ratios. Instead it gives you marginal effects on the relative hazard. Marginal effects in a Cox model is problematic, as it depends on the baseline hazard, and the whole purpose of Cox regression is to avoid estimating the baseline hazard. Instead you can just use tricks discussed here: http://www.stata-journal.com/article...article=st0250 or here: http://maartenbuis.nl/publications/interactions.html . Here is an example that applies it to Cox regression:

    Code:
    . sysuse cancer
    (Patient Survival in Drug Trial)
    
    . stcox i.drug#c.age i.drug, nolog
    
             failure _d:  died
       analysis time _t:  studytime
    
    Cox regression -- Breslow method for ties
    
    No. of subjects =           48                  Number of obs    =          48
    No. of failures =           31
    Time at risk    =          744
                                                    LR chi2(5)       =       36.91
    Log likelihood  =   -81.456452                  Prob > chi2      =      0.0000
    
    ------------------------------------------------------------------------------
              _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
      drug#c.age |
              1  |    1.11156   .0547048     2.15   0.032     1.009349    1.224121
              2  |   1.152784   .0758289     2.16   0.031     1.013344    1.311412
              3  |   1.079613   .0946951     0.87   0.382     .9090908     1.28212
                 |
            drug |
              2  |   .0211826   .1002649    -0.81   0.415     1.98e-06    226.4762
              3  |   .2595464   1.469272    -0.24   0.812     3.94e-06    17092.31
    ------------------------------------------------------------------------------
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3

      I want to correct Maarten on a small point: The Help and Manual entries for stcox post-estimation state that predicted "hr" and "relative hazard" are equivalent .

      To answer your questions and make some other points:

      1. Why does the CI from margins contains numbers <0?

      Margins uses the delta method to compute standard errors, then forms CIs by adding \(\pm\) a multiple of the standard error. As a general purpose command, margins doesn't "know" that hazard ratios are supposed to be positive, so the CI extends below zero. The same thing can happen if you use the proportion command: CIs can have values <0 or >1 for the same reason.

      2. The hazard ratio for a continuous covariate x already measures the effect of increasing x by one unit. The dydx option isn't needed.

      The hazard function with a continuous covariate X is:
      \[
      h(t|x) = h(t|X=x) = exp(\beta x) \times h(t|X=0)
      \]

      The predicted hazard ratio for an observation with covariate X = x is just

      \begin{equation}
      \widehat{hr} =\frac{ \widehat{h(t|x)}}{h(t|0)} = exp(\hat{\beta} x)
      \end{equation}

      If you increase \(x\) to \(x+1\), the ratio of hazards for X = x +1 and X = x is:
      \[
      \frac{h(t|x+1)}{h(t|x)} = exp(\beta)
      \]


      Now, for a continuous variable X that interacts with a categorical variable X there will be a different hazard function in each group and, therefore, a different hazard ratio in each group.

      3. What is margins calculating? The derivative of the hazard ratio (1) w.r.t X, evaluated at the sample mean of X:

      By elementary calculus:

      \[
      \frac{dy}{dx} h(t|x) = (exp(\beta x) \times {\beta x}) \thinspace h(t|0)
      \]

      With the default "atmeans" option, Stata computes only the part in the parentheses evaluated at the mean of x.
      \[
      exp(\beta \bar{x}) \times\beta \bar{x}
      \]

      I show this in the accompanying code sequence with the cancer dataset. (Maarten inadvertently omitted the main effect of the continuous covariate).

      Code:
       sysuse cancer, clear
      (Patient Survival in Drug Trial)
      
      . sum age
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
               age |         48      55.875    5.659205         47         67
      
      . local age_av = r(mean)
      
      .
       stcox i.drug#c.age i.drug, nolog
      
      [Output omitted. See Maarten's post.]
       
      . /* average partial effects at means by direct calculation */
      
      . di exp(_b[age]*`age_av')*(_b[age])
      38.979107
      .
      . di  exp(_b[2.drug] + _b[age]*`age_av' + _b[2.drug#c.age]*`age_av')*(_b[age] + _b[2.drug#c.age])
      8.4914304
      .
      . di  exp(_b[3.drug] + _b[age]*`age_av' + _b[3.drug#c.age]*`age_av')*(_b[age] + _b[3.drug#c.age])
      1.4364898
      
      .
      . /*Via Margins*/
      .
      . margins drug, atmeans dydx(age)
      
      Conditional marginal effects                    Number of obs     =         48
      Model VCE    : OIM
      
      Expression   : Relative hazard, predict()
      dy/dx w.r.t. : age
      at           : 1.drug          =    .4166667 (mean)
                     2.drug          =    .2916667 (mean)
                     3.drug          =    .2916667 (mean)
                     age             =      55.875 (mean)
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      age          |
              drug |
                1  |   38.97911   125.3248     0.31   0.756     -206.653    284.6113
                2  |   8.491431   23.71612     0.36   0.720    -37.99131    54.97417
                3  |    1.43649   4.299919     0.33   0.738    -6.991197    9.864176
      ------------------------------------------------------------------------------
      4. atmeans can give expected results for margins off non-linear functions of parameters. See the following:


      http://www.stata.com/statalist/archi.../msg01596.html
      and the follow-up of Michael Norman Mitchell

      A Stata Journal article by Tamas Bartus:
      http://www.stata-journal.com/sjpdf.h...iclenum=st0086
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #4
        Dear Maarten and Steve,

        Thanks a lot for your insights. I have a follow up question:

        I am testing a model that is similar to Bob's model. That is, my independent variable is a continuous variable (X1) and my moderator is a binary variable (X2), and I use cox hazard model to see the effect of the interaction of X1 and X2 on the dependent variable. The results of the Cox model show that the interaction is significant at (p < 0.005). The results are significant to different measures and variations, etc, so I am confident about the presence of the effect.

        It is expected in my field to show the significant of results through plots. Maarten mentioned that marginal effects are tricky in cox models, and the discussion by Steve suggests that margins option in Stata needs to be carefully used (or not at all used?) to calculate marginal effects - this all tells me that marginsplot option in stata is not the best option to plot the effects. I have already tried several suggestions on statalists (including following some of the links in this post) but most of them result in "funny" plots that do not make sense, especially with regard to the confidence intervals.

        Given all this, my question is: is there is a suitable way to plot interactions effect results for cox models? And if not, what are some of the alternative suggestions to deal with concerns of the field that have resulted in expectation of a plot to show results (the main concern in the field is that signficance of an independent variable is sometimes not useful and results need to be plotted to visually show the effect)? What I have done already is to use linear models such as logit and probit for the same data, got similar results, and used margins and marginsplot to get plots that made sense.

        Thanks a lot.

        Best,
        Yasir
        PhD candidate
        Tilburg University

        Comment


        • #5
          Unfortunately, your plot question has little to do with the original topic here, now two years old. I suggest that you start a new topic. If you haven't already done so, read FAQ 12 about how to ask a good question. People will want to see code, output, and graphs, posted as the FAQ suggests (between CODE delimiters for the first two, as .png files for the graphs). You're also more apt to get advice if you post sample data, built with dataex from SSC, or use a built-in data set or one available via webuse.
          Last edited by Steve Samuels; 13 Oct 2017, 14:49.
          Steve Samuels
          Statistical Consulting
          [email protected]

          Stata 14.2

          Comment


          • #6
            Thank you Steve for your kind suggestion, and my sincere apologies for not following the expected norms. I posted the question in detail in the following post: https://www.statalist.org/forums/for...ts-after-stcox

            Comment

            Working...
            X