# Dealing with categorical variables on cox regression

I am trying to fit a Cox regression model to my time-to event data and have a categorical variable with 5 different levels. If I don't leave one of the levels out, then I will have multicollinearity, so I assume I need to leave one category out as the 'reference' category. If I leave one level out, then how will I interpret the resulting cox coefficients? What is the effect of the left-out category? Does it contribute the baseline hazard?

I am using CoxTimeVaryingFitter from lifelines library in Python.

Say category 1 is the reference. If $$b_2$$ is the regression coefficient of category 2 then you can interpret $$e^{b_2}$$ in general as follows: the hazard of category 2 is $$e^{b_2}$$ times as large as the hazard in reference category 1.

For example, if $$b_2=0.3$$ then $$e^{0.3}=1.35$$ meaning that the hazard in category 2 is 1.35 times as high as in category 1. Another way to put this is: the hazard for category 2 is 35% higher than for category 1.

Another example, if $$b_2=-0.3$$ then $$e^{-0.3}=0.74$$ meaning that the hazard in category 2 is 0.74 times as "high" as in category 1. So the hazard in category 2 is lower now! Another way to put this is: the hazard for category 2 is 26% lower than for category 1.

Expression like $$e^{0.3}$$ can be derived in R by using the function

exp(0.3)


Note that only these hazard ratio's are estimated in Cox regression models, NOT the hazards themselves, neither for the baseline (reference category) nor for the other categories.

• (+1) You are correct that the Cox regression itself doesn't estimate the baseline hazard, but you can use the regression coefficients it provides to estimate the (cumulative) baseline hazard and thus the baseline survival function. See this page, for example.
– EdM
Commented Jul 9 at 18:04
• What if one of the levels of a category have very little number of elements? If I leave that category out because it has little number of elements, how would it contribute to the interpretation of coefficients, how should I handle such cases? @BenP Commented Jul 9 at 21:21
• @smgtkn It will not be different as for e.g. linear regression. If you you leave the category out and these cases happen to have high income values, then the influence of income will be different. If you leave them in, the std. error for that dummy will be relatively large and hence it's effect (difference with the reference) will be less significant. Better not treat the small category as reference itself. Instead of removing, it may make sense to merge the small category with a larger one. In general I would prefer to keep them in, not as reference though.
– BenP
Commented Jul 10 at 7:10
• If I don't leave them out, the model do not converge. If I leave them out, the problem is that I am also leaving the 'reference' category out and I'm concerned if leaving both out introduces a bias on reference category. So I am curious of the effect of 'leaving out' both the reference category and the category with small number of elements on the hazard ratios. @BenP Commented Jul 11 at 9:54