# Can I leave out certain variables that might be accounted for?

I have a dataset that I am trying to use to predict a patient's outcome based on a bunch of factors related to the pateint's care. One of the independent variables is a unique ID number of the primary care doctor. In addition to that variable, I have some attributes about the primary care doctor such as his age and gender. I'm not so much concerned about measuring the effects of age and gender on the outcome, but want to be sure I take variability due to it into account during my analysis. My question is, is it necessary to even include these doctor attributes (age and gender) in my analysis, or will this automatically be taken into account by including a doctor ID term in my analysis? It seems to me that if I leave a doctor ID term in the model, it will accounts for all the features/characteristics related to that doctor so I wouldn't need to include them separately. Is my intuition correct here?

If another title is more appropriate, please let me know. I'm not really sure what this problem is called (and hence I couldn't search for other posts like it).

• Note that while age is ordered, neither gender nor unique ID numbers are. Thus, using the ID number will not capture any property of the ordering of age (unless the orders miraculously agree). Feb 8, 2016 at 2:30

I have some attributes about the primary care doctor such as his age and gender. I'm not so much concerned about measuring the effects of age and gender on the outcome, but want to be sure I take variability due to it into account during my analysis.

If I interpret you correctly, then I believe, yes, you do want to include the other effects in your model.

As you state, a "doctor" can be thought of as a complex collection of features and characteristics that, in aggregate, characterize that given doctor. Two of these characteristics are their age and gender. If you include all the doctor ID (as a factor), the doctor age, and the doctor's gender in the model, then the parameter for any given doctor is measuring the effect of that given doctor on your outcome after accounting for the effect of age and gender. If you do not include age and gender, then you are accounting for all the possible effects in one place, and you will not be able to disitnagle them.

As an additional comment, this seems like an excellent place to fit, not a classical linear model, but a multi-level linear model. One statistical issue you are sure to encounter is that the different doctors will have differing numbers of patients/observations. This means that some doctors, who are relatively poorly represented in your data, will have thier parameter estimated very inaccurately (i.e. with very high variance). A classical linear model makes no attempt to rectify this, but a multilevel model does (shrinking the low confidence estimates).

In R, this would look like

M <- lmer(outcome ~ gender + age + (1 | doctor_id), ...)


The standard (and very friendly) reference on multi-level models is Gelman and Hill, be sure to check it out!

• This is very helpful, @Matthew Drury! Can you tell me if the R code you presented is similar to just having a random effect for doctor in the model? I using SAS for this, so, I'm not terribly familiar with the R syntax. Feb 7, 2016 at 23:03
• Yah, I believe that means the same thing. Feb 7, 2016 at 23:08
• Excellent. I think they are too and I've incoporated the doctor ID as a random effect. I've left out the other characteristics as I'm just concerned with making an accurate prediction, not interpreting the effects of doctor age or anything else. Your post was perfect! Feb 7, 2016 at 23:10

Summary: It depends on what you want to know, but I'd say leave out the IDs.

(I'm assuming you have each doctor represented for multiple samples in your dataset.)

If you choose to leave out the doctor-features and instead include the doctorID, you are modeling the outcome as a function of which doctor treated the patient. While this may be interesting if you know the doctor, it doesn't answer any general questions.

So unless you know the doctors in ways that are not captured in the dataset and want to know which one is better than the rest, I would exclude the doctorID and go with the generic doctor-features. Why? Because as scientists we are much more interested in knowing which generic attributes - such as gender and age - are important for an outcome, rather than focusing on case-specific variables.

• Unless of course you are trying to win a competition and get better prediction using the IDs, then go ahead! Feb 7, 2016 at 22:33