text: user8654: 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 <- 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. 
  
  user3541: 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:
  > 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  
  
  
original_text: 8654: <p>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.</p>
  
  <pre><code>Model_1 &lt;- coxph(serve_object ~ GROUP + age+ Smoking+ Diabetes, data = DF
  summary(Model_1)
  </code></pre>
  
  <p>But the output is very confusing. it gives hazard ratio of 9 out of 10 groups. I think it dealt group as covariate. </p>
   3541: <p>The fact that you supplied <code>GROUP</code> as a covariate, you are getting 9 coefficients as one of the ten levels is used as the reference level.</p>
  
  <p>If you would like to fit one model per group (and in this scenario you would not be correcting for <code>GROUP</code>), you should first split your data frame and fit your models on the resulting list's elements:</p>
  
  <pre><code>lapply(split(DF, DF$GROUP),
         function(x) coxph(serve_object ~ age + Smoking + Diabetes, data = DF))
  </code></pre>
  
  <p>Example with the <code>mtcars</code> data set when grouped by number of cylinders, <code>cyl</code> having values of 4, 6 or 8:</p>
  
  <pre><code>&gt; lapply(split(mtcars, mtcars<span class="math-container">$cyl),
  +        function(x) lm(disp ~ hp, data = x))
  $</span>`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  
  </code></pre>
  