rcox-regressionsurvival

Why does the coefficient name not appear in the output when running the Cox Proportional Hazards model of the Survival package?


I'm running the coxph() function from the survival package, and am using an example from http://www.sthda.com/english/wiki/cox-proportional-hazards-model, using univariate Cox regression and the lung cancer data provided in the “lung” dataset of the survival package. When I run the code posted at the bottom, I get the output shown in the image immediately below for the res.cox object. It supposedly, per the link, compares the hazard (risk of death) of the female subset of the sex variable against the baseline subset of males. However, this output doesn't show which subset is being compared against which baseline of the variable under study. Is there way to run the coxph() function so the comparison bases are shown? I've read through the survival package documentation and couldn't find how to generate this. It should at a minimum indicate "female" for the regression coefficient, and it would be nice if it also showed the baseline that female is being compared against. In this case, there are only 2 subsets of the sex variable, but there are other variables with more than two subsets and it would be helpful to see the comparisons labeled.

enter image description here

Code:

library(survival)
library(survminer)

### Example data set ###
head(lung)

### Univariate Cox regression ###
res.cox <- coxph(Surv(time, status) ~ sex, data = lung)
res.cox

Solution

  • In such cases we sociologists usually create a female dummy.

    library(survival)
    
    lung$female <- +(lung$sex == 2)
    
    coxph(Surv(time, status) ~ female, data = lung)
    # Call:
    # coxph(formula = Surv(time, status) ~ female, data = lung)
    # 
    #           coef exp(coef) se(coef)      z       p
    # female -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