在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 

I would like to change as.factor(sex)2 into Gender = 2

评论
DJHongKong
DJHongKong

Maybe just use the factor command:

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
点赞
评论