[R] use "factor" for categorical covariate in Cox PH model

From: Linda Lei <llei_at_bccrc.ca>
Date: Tue 18 Jul 2006 - 09:57:47 EST

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.  


        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 18 10:09:26 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 18 Jul 2006 - 18:16:31 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.