First off, sorry if this is a simple question. I've been asked to get stuck in with some clinical epidemiology. The internet is my only support group as I am not a student under the supervision of an expert.

I am performing Cox regression over a list of drugs (categorical) and I am adjusting for the covariate age (amongst others, gender, income, etc). I am not sure whether I should be treating age as a categorical or quantitative covariate.

From my basic understanding, age is usually treated as a quantitative variable, whereas a categorical variable would be "are you a smoker?", Yes/No. Favourite colour? etc.

Firstly, investigating the impact of a drug in R:


                       coef exp(coef)  se(coef)      z        p
drugNamecodeine_based  0.150117  1.161970  0.022199  6.762 1.36e-11
drugNameporpranolol    0.237963  1.268662  0.023608 10.080  < 2e-16
drugNameparacetamol    0.202408  1.224347  0.021519  9.406  < 2e-16

And then, controlling for a patients age by treating age as quantitative:


                        coef  exp(coef)   se(coef)       z        p
drugNamecodeine_based  0.1393446  1.1495202  0.0222008   6.277 3.46e-10
drugNameporpranolol    0.1849390  1.2031450  0.0236432   7.822 5.20e-15
drugNameparacetamol    0.1939401  1.2140235  0.0215203   9.012  < 2e-16
adjustedAge           -0.0225542  0.9776982  0.0005415 -41.650  < 2e-16

Treating age as a quantitative variable makes some minor adjustments to the drug being taken. This makes sense, however, if I then control for a categorical age not only do I get a breakdown of risk associated by ages (in years), but the adjustment to each drug is different.


                         coef exp(coef) se(coef)       z        p
drugNamecodeine_based     0.14077   1.15116  0.02222   6.334 2.38e-10
drugNameporpranolol       0.18819   1.20706  0.02367   7.949 1.88e-15
drugNameparacetamol       0.19453   1.21474  0.02155   9.028  < 2e-16
as.factor(adjustedAge)19  0.04519   1.04622  0.07329   0.617 0.537554
as.factor(adjustedAge)20  0.08761   1.09157  0.06905   1.269 0.204510
as.factor(adjustedAge)21  0.02948   1.02992  0.07030   0.419 0.674937
as.factor(adjustedAge)38 -0.48611   0.61501  0.06367  -7.635 2.26e-14
as.factor(adjustedAge)39 -0.54026   0.58260  0.06362  -8.492  < 2e-16
as.factor(adjustedAge)40 -0.48973   0.61279  0.06416  -7.633 2.29e-14
as.factor(adjustedAge)41 -0.46459   0.62839  0.06286  -7.391 1.46e-13
as.factor(adjustedAge)42 -0.57269   0.56401  0.06272  -9.131  < 2e-16

I really like that I can see the calculations per age. However, whether the effected treating the age variable as is correct or not in terms of the results for the drug I am not sure.

And, it is worth noting, a patient is only observed once. So their age is not time-dependent.

My main questions in summary:

1) It seems great that I can now see the risk associated with each year group, however, why should this change the exp(coef) of each drug between age being treated as quantitative and categorical?

2) If I want to control for age when measuring the impact a particular drug has on patient time-outcome, should this be quantitative or categorical?

3) If I become more interested in the risk associated with the age of a patient (rather than what drugs they have), surely I need to treat age as a categorical variable? Would I perform a separate calculation with just ~age?

Many thanks for your help.

EDIT 1 The replies have been excellent and most useful. Forgive my basic understanding of statistics. From the sounds of it, I will be treating age as a quantitative covariate.

What I don't understand, and again I'm not in a position where I can ask an expert besides those who kindly reply to my posts, is why would I add a quadratic or cubic term to my model? What will that achieve?

  • $\begingroup$ I've addressed your "Edit 1" in my answer. In the future, other questions should be asked as separate questions on Cross-Validated. If you need to, you can reference your original question here in any new questions you post. Thank and best of luck to you. $\endgroup$ Jun 16, 2019 at 15:27

2 Answers 2


Generally speaking, you should treat age as a quantitative variable, assuming you have the actual ages and not age brackets. There are several reasons for this. Perhaps most importantly, if you use age as a categorical variable, you typically would need $c-1$ variables to represent the age categories, $c$, in a regression model, and would lose degrees of freedom for each of these categories. This results in less powerful tests. On the other hand, using a single quantitative/numeric variable age requires only a single variable and a single degree of freedom.

Age as a quantitative variable contains more information than as a categorical variable. If you were to represent age as a categorical variable, then you are doing away with the natural ordering of the ages you'd have by leaving it as a quantitative variable. In other words, a model with categorical ages is unable to tell that 70 years old is closer to 80 years old than 5 years old (because 70 comes 10 before 80, but if you modeled age as a category, there is no information that indicates to your model that category A -- which might represent your first age category -- comes before category C, which might represent another age category). You will get different coefficient estimates for a quantitative age model than a qualitative age model because the models make different assumptions.

There are several other important reasons why it's generally not a good idea to treat your quantitative measures as categories. Frank Harrell has a good list of additional reasons here.

There is no need to treat age as a category to estimate risks associated with a subject's age. You can simply estimate the risk at any given age by multiplying the estimated coefficient for age by the subject's age (in years) and exponentiating.

Update to your "EDIT 1"

What I don't understand, ..., is why would I add a quadratic or cubic term to my model? What will that achieve?

First, let me say that I'm glad to see you've decided to use age as a quantitative variable. I think all of us applaud you on that decision.

The reason we've suggested the possibility of trying quadratic or cubic terms to your model is that age may not have a strictly linear relationship to your outcome. Without loss of generality to your exact problem and model, I think it's easier and more instructive to think about this in terms of a simple linear regression model.

Let's assume you had a simple linear regression model in which you regressed weight on age. If you included age as a linear term (e.g. $\beta_{age} \times X_{age}$) in your model, then you are assuming that weight increases steadily as as person ages, no matter how old a person gets (see Linear Model graph below). This may not be the appropriate functional relationship. Instead, in reality, what typically happens is that a person gains weight as they age, but as they enter old age they begin to lose weight. This would not be well modeled as a linear function, because of this drop-off in weight in old-age. Instead, if one included a quadratic term (e.g. $\beta_{age} \times X_{age}^2$) in addition to the linear term, this could better capture the non-linearity and quadratic nature of the relationship between weight and age. Using an $X_{age}^2$ term allows the regression model to predict an increasing weight as one ages up to a point, and then the model will start to predict a decrease in weight as one ages (see Quadratic Model graph below). If you simply included a linear term, your model would not be able to capture this drop-off in weight in old age. Instead, your model will simply continue predicting increases in weight well into old age. The same concept applies to your model.

Besides including quadratic or linear terms in your model, you may also want to explore the use of splines or generalized additive models (GAMs) to model these types of non-linear relationships.

Linear Model:

Linear Model]

Quadratic Model:

Quadratic Model

PS. Keep in mind I just made up these graphs. They don't really represent real weights and ages in real life. For example, in real life someone doesn't only weigh 8 pounds upon reaching 100, but I think you get the general idea.

  • 1
    $\begingroup$ It seems unfortunate that there is nothing in your answer about the degree to which including age as a linear predictor makes a strong assumption about the relationship between age and the outcome. I think we should keep in mind the motivation for categorizing age and explain how to get some increased flexibility in the relationship without categirizing. Getting the functional form of the relationship approximately correct could be important. $\endgroup$
    – jsk
    Jun 16, 2019 at 2:56
  • $\begingroup$ @jsk - I do believe age as a linear predictor and how to pull that information out of the relationship is what I'm trying to do (sorry for the drop in statistical terms, I'm not a statistician). $\endgroup$ Jun 16, 2019 at 10:27
  • 4
    $\begingroup$ Age is typically a very important predictor and has a nonlinear effect. My default assumption is only that the age effect is smooth, and I use regression splines to model that. $\endgroup$ Jun 16, 2019 at 12:46
  • 2
    $\begingroup$ @jsk, I think deciding how to model age and the functional form of the model with age is a separate question all together. Indeed after deciding not to categorize age, one would need to explore the functional form of the model by exploring quadratic, cubic, quartic,... terms and exploring diagnostics. That aside, Harrell's #3 in my answer also touches on your concern, so in that sense it, along with my comment above addresses this, I think. $\endgroup$ Jun 16, 2019 at 14:36

I do not think it's a very good idea to categorize age in this way. This is not only for statistical reasons, but also because the outcome has only limited value: your output states, that a 39 year old person has a lesser risk than a 38 or 40 year old person. I guess the general interpretation - that age lowers the risk - might get lost this way.

There are other ways to get more information about the variable 'age'. You could add a quadratic or cubic term to test if the effect of age is linear.

2) If I want to control for age when measuring the impact a particular drug has on patient time-outcome, should this be quantitative or categorical?

You can estimate more then one model. First, fit a model in which you only include the drugs as explanatory variables. Then you fit another model where you add variables that might also have an effect, and check if the effects of the drugs have changed. Are they still the same? In that case, then the drug is the causal reason. If they get a lot lower, it just correlated with the effect of other variables.

  • $\begingroup$ Thank you! This is a very helpful response. Could explain more in terms of "add a quadratic or cubic term to test if the effect of age is linear"? $\endgroup$ Jun 16, 2019 at 10:24
  • 1
    $\begingroup$ The model with 'age' as a numerical variable is showing a linear effekt. With every additional year , the outcome get's -0.0225542 lower. I guess you (automatically) used 18years as the base category. So for a 19 year old , the output would be 1x -0.0225542 lower and for a twenty year old it would be 2x -0.0225542 lower and so on and so on but if you believe that the effect of age is not linear but exponential, you might add another term to your regression: (age x age) = (age)² $\endgroup$
    – Niko P
    Jun 16, 2019 at 11:00
  • $\begingroup$ That made so much sense!! Thank you. Any suggestions (for publication and presentation purposes) what would be the best way to display this increasing linear effect of age on the disease outcome? $\endgroup$ Jun 16, 2019 at 11:36
  • $\begingroup$ there are typical ways to visualize Survival regression. just google survival plot r they are generally for displaying the survival in addition to a categoric variable maybe, that's ok for you already or you try or search a bit around, if this combination (numeric regressor 'age' + survival plot) is possible or transform the years back to categories, just to design a nice plot you display the survival plot with your categoric varioables (eg. drug1 : yes or no) and think of another way , to show the effect of age graphically (eg: with a scatterplot of age and survival time or status $\endgroup$
    – Niko P
    Jun 16, 2019 at 12:28
  • 1
    $\begingroup$ "In that case, then the drug is the causal reason." This is not a causal model. One of the reasons is there could be other unmeaaured confounders. All you can say is you're estimating the association between the drugs and survival after adjusting for the effect of age. $\endgroup$
    – jsk
    Jun 16, 2019 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.