Announcement

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

  • Question about tvc in Cox

    Hello!

    I have run a cox regression model in which my main exposure of interest is a significant time-varying covariate when I have used the tvc texp(ln_t) commands in stata.
    Hence, I am trying to show the HR at different time points i.e. 7 days, 14 days, 30 days.
    I am doing this manually by entering HRs of the main variable and the tvc into this, e.g. at 30 days:
    display exp(log(0.7576) + log(30)*log(1.2797))

    However, in doing so I do not get a SE or 95%CI.

    Is there an equivalent of a lincom command for the tvc? so that I could easily get the HR, standard error and 95%CI at different _t points, using the coefficients I have for my main variable and its interaction with ln_t using the tvc texp commands.

    Many thanks for any help!!!


  • #2
    Because you do not show the actual Cox regression command you used, it is not possible to give you specific code to do this. But you need, first, to be sure that you run your Cox regression using factor variable notation for the interaction, and then the -margins- command will give you what you are looking for after that. -help fvvarlist- -help margins-.

    Comment


    • #3
      Hi Clyde, thank you so much for your reply. Sorry I had not included the code. This is it (both 'dd' and 'bin' were significant tvc). My exposure of interest is dd.

      ----> stcox i.dd i.age i.sex i.ethnicity charts i.adm i.lll i.bin, tvc(dd bin) texp(ln(_t))

      my time is in days, and I would like the HR for 'dd' with SE, 95%CI, and p-value if possible at time 14 days and 30 days.

      I am not sure how to make the tvc command a factor variable notation..

      Would be very grateful for your help based on above code!

      Many thanks!

      Comment


      • #4
        OK, sorry. I don't know if the -tvc()- mechanism will work for these variables, as they are not continuous. Moreover, when writing #2 I forgot that most predictions are not available after the use of -tvc()-. I'm afraid I don't know how to do what you want. I hope somebody else will respond here.

        Comment


        • #5
          I assume your factor dd is binary. The tvc() creates an interaction so the effect of dd==1 will vary by time, and the log(HR) on time = 14 may be calculated:
          Code:
           lincom _b[main:1.dd] + 14 * _b[tvc:dd]
          To display the HR, use the lincom option hr
          Code:
          . lincom _b[main:1.dd] + 14 * _b[tvc:dd] , hr
          To see the notation for the coeffecients one might use the expression builder (display) after an estimation command and look for Coefficients.
          Code:
          db display
          Let's say you fit the following model:
          Code:
          stcox i.dd , nohr nolog noshow tvc(dd) texp(ln(_t))
          An alternative, depending on the size of data/available memory, can be to split the data and generate interactions:
          Code:
          stsplit, at(failures)
          gen ddlnt = dd * ln(_t)
          stcox i.dd ddlnt , nohr nolog noshow
          The two Cox models above will give identical estimates.

          An example using simulated data:
          Code:
          clear
          set obs 100000 /* 1000 make estimation fast */
          gen byte dd = mod(_n,2)
          
          * Generate times from a Weibull model including a binary variable dd
          * with log(HR) = -1, interacting dd with log time -0.1
          
          survsim time event, lambdas(0.1) gammas(1.5) cov(dd -1) tde(dd -0.1) maxt(30)
          
          * expecting a HR of dd at time 14 = exp( -1 + 14 * -0.1 ) = 0.09
          
          stset time , f(event)  
          
          * Fit a Cox model to the data and include an interaction of dd with ln(_t).
          
          stcox i.dd , nohr nolog noshow tvc(dd) texp(ln(_t))
          
          /*
          
          Cox regression -- no ties
          
          No. of subjects =      100,000                  Number of obs    =     100,000
          No. of failures =       99,490
          Time at risk    =  667125.1797
                                                          LR chi2(2)       =    25464.93
          Log likelihood  =   -1035893.2                  Prob > chi2      =      0.0000
          
          ------------------------------------------------------------------------------
                    _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          main         |
                  1.dd |  -1.002624     .01355   -73.99   0.000    -1.029181    -.976066
          -------------+----------------------------------------------------------------
          tvc          |
                    dd |  -.1030681   .0084043   -12.26   0.000    -.1195403   -.0865959
          ------------------------------------------------------------------------------
          Note: Variables in tvc equation interacted with ln(_t).
          
          * use lincom to get log(HR) and HR for dd at time 14:
          
          */
          
          . lincom _b[main:1.dd] + 14 * _b[tvc:dd]
          
          /*
          
           ( 1)  [main]1.dd + 14*[tvc]dd = 0
          
          ------------------------------------------------------------------------------
                    _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   (1) |  -2.445577   .1063885   -22.99   0.000    -2.654095    -2.23706
          ------------------------------------------------------------------------------
          
          */
          
          . lincom _b[main:1.dd] + 14 * _b[tvc:dd] , hr
          
          /*
          
           ( 1)  [main]1.dd + 14*[tvc]dd = 0
          
          ------------------------------------------------------------------------------
                    _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   (1) |   .0866761   .0092213   -22.99   0.000     .0703625     .106772
          ------------------------------------------------------------------------------
          
          */

          Comment


          • #6
            Hello!

            I'm facing the same type of issues as Siv Siv.

            I'm wondering why we don't include ln(_t) in the lincom command pasted below.

            Why do we do that:
            lincom _b[main:1.dd] + 14 * _b[tvc:dd] Instead of lincom _b[main:1.dd] + ln(14) * _b[tvc:dd]?

            Is it because ln is already included in tvc? I tried to look into the documentation but couldn't find anything.

            I know lincom _b[main:1.dd] + ln(14) * _b[tvc:dd] will return an error but I'm wondering if I could simply calculate ln(14) and replace it with the actual value in the command.

            When I don't include ln(), my HR are very hard to read.

            Thanks in advance.

            Comment


            • #7
              Originally posted by Claire Ric View Post
              Hello!

              I'm facing the same type of issues as Siv Siv.

              I'm wondering why we don't include ln(_t) in the lincom command pasted below.

              Why do we do that:
              lincom _b[main:1.dd] + 14 * _b[tvc:dd] Instead of lincom _b[main:1.dd] + ln(14) * _b[tvc:dd]?

              Is it because ln is already included in tvc? I tried to look into the documentation but couldn't find anything.

              I know lincom _b[main:1.dd] + ln(14) * _b[tvc:dd] will return an error but I'm wondering if I could simply calculate ln(14) and replace it with the actual value in the command.

              When I don't include ln(), my HR are very hard to read.

              Thanks in advance.
              Hi,

              I am wondering if you found out an answer to your question. I am facing the same issue. I am specifying a Cox model with time-varying coefficeinets tvc(ln(_t)). If I for example want to calculate the HR for time = 10 the HR makes much more sense if I use:
              Code:
              lincom _b[main:dd]+2.3025851*_b[tvc:1.dd], hr
              ln(10) = 2.3025851

              instead of:
              Code:
              lincom _b[main:fall]+10*_b[tvc:1.fall], hr

              I guess that I need to use the ln of time in the lincom phase to get the correct HR, but I can not find any answer to this. Does anyone know?

              Comment


              • #8
                Yes, the coefficients in _b[ ] are the logs of the hazard ratios. Because you specified tvc(ln(_t)), you are also saying that the modification of the hazard ratio by time is done with ln(t), not with t itself. So you are correct that the right command is -lincom _b[main:fall] +2.3025851*_b[tvc:1.dd]- If you don't want to look up the value of ln 2 when writing the code, you can also write this as --lincom _b[main:fall] +`=ln(10)'*_b[tvc:1.dd]-

                Comment


                • #9
                  Originally posted by Clyde Schechter View Post
                  Yes, the coefficients in _b[ ] are the logs of the hazard ratios. Because you specified tvc(ln(_t)), you are also saying that the modification of the hazard ratio by time is done with ln(t), not with t itself. So you are correct that the right command is -lincom _b[main:fall] +2.3025851*_b[tvc:1.dd]- If you don't want to look up the value of ln 2 when writing the code, you can also write this as --lincom _b[main:fall] +`=ln(10)'*_b[tvc:1.dd]-
                  Thank you very much (once again!) Clyde!

                  Comment

                  Working...
                  X