How to run Cox proportional Hazard model for each group in R? My population is divided into 10 groups. I want to run the cox-proportional hazard model separately for each of these 10 groups so that in the end i can compare which groups has highest hazard ratio depending uopn the covariates.
How can i do this in R? Earlier i was using this formula.

Model_1 &lt;- coxph(serve_object ~ GROUP + age+ Smoking+ Diabetes, data = DF
summary(Model_1)


But the output is very confusing. it gives hazard ratio of 9 out of 10 groups. I think it dealt group as covariate.
The fact that you supplied GROUP as a covariate, you are getting 9 coefficients as one of the ten levels is used as the reference level.

If you would like to fit one model per group (and in this scenario you would not be correcting for GROUP), you should first split your data frame and fit your models on the resulting list's elements:

lapply(split(DF, DF$GROUP),
       function(x) coxph(serve_object ~ age + Smoking + Diabetes, data = DF))


Example with the mtcars data set when grouped by number of cylinders, cyl having values of 4, 6 or 8:

&gt; lapply(split(mtcars, mtcars$cyl),
+        function(x) lm(disp ~ hp, data = x))
$`4`

Call:
lm(formula = disp ~ hp, data = x)

Coefficients:
(Intercept)           hp  
    59.0369       0.5579  


$`6`

Call:
lm(formula = disp ~ hp, data = x)

Coefficients:
(Intercept)           hp  
   290.9178      -0.8799  


$`8`

Call:
lm(formula = disp ~ hp, data = x)

Coefficients:
(Intercept)           hp  
   320.2083       0.1572