r语言 - 在 Cox 回归结果中使用标签



尝试向变量名称添加标签以使其在显示结果时更加连贯 以下

library(survival)
data(lung)
Hmisc::label(lung$sex) <- "Gender"
res.cox <- coxph(Surv(time, status) ~
as.factor(sex) 
, data = lung)
res.cox

产生以下结果:

Call:
coxph(formula = Surv(time, status) ~ as.factor(sex), data = lung)
coef exp(coef) se(coef)      z       p
as.factor(sex)2 -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 

我想把as.factor(sex)2改成Gender = 2

也许只需使用factor命令:

lung$Gender <- factor(lung$sex, labels=c(" = 1"," = 2"))
res.cox <- coxph(Surv(time, status) ~ Gender, data = lung)
res.cox

Call:
coxph(formula = Surv(time, status) ~ Gender, data = lung)
coef exp(coef) se(coef)      z       p
Gender = 2 -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