1
$\begingroup$

I'm aware that factors are the proper way to handle categorical variables but the explanation gets a little confusing when we start having factors with multiple levels.

For example, let's say I have a factor factor(department,levels=c('Finance','HR','Sales','Marketing'))

Now when I run a Cox regression to measure employee turnover, it will use Finance as the reference, or what ever reference I assign it using the relevelfunction. However, the interpretation is then confusing. I'm saying that if the exp(coef) is >1 for HR, I'm saying there is an increased risk in leaving the company for a member of HR compared to Finance. But the comparison is almost meaningless, because really I want to say "Increased risk of leaving because I'm in HR, compared to every other department".

So if I use dummy variables here, then I can say that, correct? If Department_HR is at an increase risk it's accounting for all other departments. Am I thinking about this the right way? I have read elsewhere that using one-hot encoding or dummy variable is less than ideal for survival analysis, could someone explain why this might be the case too?

$\endgroup$
  • $\begingroup$ In a word: yes. That is the way to go $\endgroup$ – Repmat Nov 7 '18 at 17:45
  • $\begingroup$ so use dummy variables? $\endgroup$ – Ted Mosby Nov 7 '18 at 20:14
  • $\begingroup$ There are many possible ways to set up "dummy variables" so I think the question and comments are collectively vague. $\endgroup$ – DWin Feb 2 at 1:50
2
$\begingroup$

The default coding of factor variables in R is "treatment contrasts" relative to the first level in the factor definition. There are many other possible contrast arrangements possible. This is not specific to Cox models but applies to all regression methods. Your desire is for a contrast type known in R as "contr.sum". See the UCLA tutorial: https://stats.idre.ucla.edu/r/library/r-library-contrast-coding-systems-for-categorical-variables/

Also see

?C
?constrasts
?contr.sum
| cite | improve this answer | |
$\endgroup$

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.