Linda Lei
2006-Jul-17 23:57 UTC
[R] use "factor" for categorical covariate in Cox PH model
Hi All, I'm learning the R codes for Cox PH modeling. Could I ask you what the function of "factor" in modeling? Thank you! When dealing with the categorical covariates (for example 3 groups), it will come out different results if we add the command "factor" in front of the categorical covariate or not: if we don't add "factor", there is only one hazard ratio; if we add "factor", there are two hazard ratios. So does the "factor" actually create some dummy variables for the calculation? Here is the code example: curve2=survfit(Surv(CR, statcr) ~ factor(X1),data=dat1) where X1 have three categories. Thanks! [[alternative HTML version deleted]]
Dieter Menne
2006-Jul-18 07:09 UTC
[R] use "factor" for categorical covariate in Cox PH model
Linda Lei <llei <at> bccrc.ca> writes:> > When dealing with the categorical covariates (for example 3 groups), it > will come out different results if we add the command "factor" in front > of the categorical covariate or notThe catch is here: the covariate is not a "categorial", but a number. In that case a regression is computed, and the ONE ration printed out has the meaning of a slope.> if we don't add "factor", there is > only one hazard ratio; if we add "factor", there are two hazard ratios. > > So does the "factor" actually create some dummy variables for the > calculation?Factor make the covariate a categorial one, and two contrasts are printed out, relative to the first level of the covariate. Dieter