Edi Itelman
Edi Itelman

Reputation: 443

use labels in cox regression results

Trying to add labels to variable name to make it more coherent when displaying results The following

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

produces this result:

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

Upvotes: 0

Views: 287

Answers (1)

Edward
Edward

Reputation: 18543

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

Upvotes: 1

Related Questions