I don't agree with Maarten a small point The Help and Manual entries for stcox post-estimation state that "hr" and "relative hazard" are equivalent terms. The reason that you have a CI with values <0 is that margins uses the delta method (Taylor series linearization) to compute standard errors. This method gives intervals of the form estimate \(\pm\) bound. The
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
\[
\widehat{hr} =\frac{ \widehat{h(t|x)}}{h(t|0)} = exp(\hat{\beta} x)
\]
If you increase \(x\) to \(x+1\), the relative hazard for X = x +1 vs X = x is:
\[
\frac{h(t|x+1)}{h(t|x)} = exp(\beta)
\]
In your case, there will be a different hazard ratio in each group.
Now, given that the hazard ratio already measures the effect of increase\(X\)by 1 unit, I wonder what additional information do you get with the dydx option. I think "none", in fact less than none. Maarten has already pointed out that the presence of the baseline hazard function\(h(t|0)\)makes the dydx option of margins problematic. With two categories there is a different hazard ratio for each category, but it is constant. I can tell you what margins is trying to calculate:
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, as I show in the program below.
\[
exp(\beta \bar{x}) \times\beta \bar{x}
\]
Do you find it useful? I don't.
As to why 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. In another setting, CIs for proportions can have values <0 or >1 for the same reason.
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
\[
\widehat{hr} =\frac{ \widehat{h(t|x)}}{h(t|0)} = exp(\hat{\beta} x)
\]
If you increase \(x\) to \(x+1\), the relative hazard for X = x +1 vs X = x is:
\[
\frac{h(t|x+1)}{h(t|x)} = exp(\beta)
\]
In your case, there will be a different hazard ratio in each group.
Now, given that the hazard ratio already measures the effect of increase\(X\)by 1 unit, I wonder what additional information do you get with the dydx option. I think "none", in fact less than none. Maarten has already pointed out that the presence of the baseline hazard function\(h(t|0)\)makes the dydx option of margins problematic. With two categories there is a different hazard ratio for each category, but it is constant. I can tell you what margins is trying to calculate:
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, as I show in the program below.
\[
exp(\beta \bar{x}) \times\beta \bar{x}
\]
Do you find it useful? I don't.
As to why 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. In another setting, CIs for proportions can have values <0 or >1 for the same reason.
Comment