Announcement

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

  • Margins after stcox- baseline predicted hazard not 1 after introducing covariates?

    I am trying to visualize the impact of offer number (max_offer) on 3-year graft failure (deathorretx3). So I am using the following code- stcox, then margins and marginsplot to visualize the change in predicted hazard of graft failure over different values of offer number.

    stset px_stat_time_yrs3, fail(deathorretx3) id(pt_code)
    stcox maxoffer
    margins, at(maxoffer=(1(1)20))
    marginsplot

    Click image for larger version

Name:	Screenshot 2025-03-17 at 6.21.35 PM.png
Views:	1
Size:	198.7 KB
ID:	1774510


    This code turns out how I expect it (i.e. predicted hazard on the y-axis is 1, or baseline, for offer number=1).
    However, when I try to plot with adjustment for covariates, using a multivariable Cox model that I developed, the baseline is no longer 1 and the predicted hazard is greater than 1 for offer number=1. Why is this happening and is there a way to recenter the graph to have all the hazards for offer numbers>1 compared to a baseline of hazard = 1 for offer number=1?
    Thank you!

    stset px_stat_time_yrs3, fail(deathorretx3) id(pt_code)
    stcox maxoffer age60 race_nonwhite bmi_calc dm dialysis smoking surg2 dayswait_chron newera crt_2 tbili_3 pvr_recip_3 age_don_55 cva_ddr ischtime6
    margins, at(maxoffer=(1(1)20))
    marginsplot
    Click image for larger version

Name:	Screenshot 2025-03-17 at 6.22.39 PM.png
Views:	1
Size:	227.5 KB
ID:	1774511

  • #2
    Even your first graph does not have the property you are looking for. If you look closely you will see that the hr for maxoffer == 1 is slightly greater than 1, not equal to it. Because you entered maxoffer into the regression as a continuous variable, the baseline value is 0, not 1. When maxoffer == 0, hr = 1. I suspect that maxoffer == 0 is not a possible value in the real world, but as the effect of maxoffer == 1 compared to 0 is nearly the same thing, your graph almost starts out at hr = 1, but not exactly.

    Now, remember that the baseline hazard corresponds to the case where all of the model variables are zero. So for a discrete variable, that's the reference category of the variable's representation as indicators, and for continuous variables it's when they are zero. So a hazard ratio of 1 is obtained in this model when maxoffer == 0 and age60 == 0 and racenonwhite == 0, etc. I don't know what all of your variables are--in particular while I can imagine that tbili_3 has something to do with total bilirubin, I can't guess what the 3 refers to. But I suspect that for some of these variables, 0 is simply not a real-world possibility. Even if each of the variables can actually take on a zero value, it's a fair guess that no real world person has all of them zero. So your baseline for this model is probably an artificial construct, not a possible living human.

    Now, even if I have that wrong and all of your variables are actually centered on mean values, so that hazard ratios equal to or very near 1 are not only possible, but frequent, you still won't get that out of a margins plot like this. The -margins- command calculates predictions that are averaged over the entire estimation sample. And since the hazard is a highly non-linear function of xb, the distribution of predicted hazard ratios will not have 1 as its mean. If you want a plot that displays the effect of maxoffer while constrained so that the hazard ratio for maxoffer = 0 is 1, then you will have to constrain the other variables to 0 using the -at()- option in your -margins- command. (Of course, if all-zero values is unrealistic or impossible, it probably isn't a good idea to do this anyway as you would be graphing a relationship that cannot exist in the real world.)

    Comment


    • #3
      Thank you so much for your insights! Yes, it is correct that maxoffer==0 is not a possible value in the real world. It seems that it's not incorrect that the hazard ratio for maxoffer=0 is not 1.
      Interestingly, even when I constrained all categorical covariates to 0 (baseline) and set the continuous covariates to their means, or even ran this code eliminating the continuous covariates and only using the categorical covariates, the hazard ratio for maxoffer=0 was still not 1.

      Comment


      • #4
        Interestingly, even when I constrained all categorical covariates to 0 (baseline) and set the continuous covariates to their means, or even ran this code eliminating the continuous covariates and only using the categorical covariates, the hazard ratio for maxoffer=0 was still not 1.
        Setting the continuous covariates to their means will not do what you are trying to get. The values of the covariates that are actually part of the model must all be set to zero. If those covariates are, in fact, mean-centered versions of other variables, that corresponds, in principle, to those other variables being set to their means, but the actual covariates in the model must be set to zero.

        Comment

        Working...
        X