I'm trying to extract the SE value from a coxph object, expanding from https://stats.stackexchange.com/questions/324042/get-standard-error-of-exponentiated-coefficient-in-cox-regression:
library(survival)
library(survey)
res.cox <- coxph(Surv(time, status) ~ sex, data = lung)
which shows a nice coxph object:
> res.cox
Call:
coxph(formula = Surv(time, status) ~ sex, data = lung)
coef exp(coef) se(coef) z p
sex -0.5310 0.5880 0.1672 -3.176 0.00149
Likelihood ratio test=10.63 on 1 df, p=0.001111
n= 228, number of events= 165
However, I need a way to extract the se(coef)
value, and I don't know how to do that through res.cox
, and such an extraction may not be possible, so I use survey
:
s <- svycontrast(res.cox, quote(exp(sex)))
which looks like
> s
nlcon SE
contrast 0.588 0.0983
but the SE
value is wrong!
How can I get the se(coef)
value from res.cox
?
CodePudding user response:
If you run summary
on a coxph object, you get a list-like object that contains several members, including the coefficients
table. You can pluck out the se(coef)
column with standard indexing, so in your example you could get at the se
with:
summary(res.cox)$coefficients[,"se(coef)"]
#> [1] 0.1671786