Home > database >  Cox regression with more than 2 groups
Cox regression with more than 2 groups

Time:03-30

I am trying to get an Hazard Ratio for 4 survival curves according quartiles of delta_mon1_baselone_to_3d using this code:

quantile <- df$delta_mon1_baseline_to_d3
cox <- coxph(Surv(mace_months_date_vs_date_sample, mace) ~ findInterval(quantile, quantile(quantile, na.rm = TRUE)[-5]), data = df)
summary(cox)

But I only get one hazard ratio.

I have seen that I have to convert the predictor column delta_mon1_baselone_to_3d as factor using this code:

df$quantile <- as.factor(df$quantile)

but cox regression doesn't work after converting.

Converting directly df$quartile_mon1_delta3d <- as.factor(df$quartile_mon1_delta3d) gives me the same feedback.

Here are my data:

      ID age     sex  mace mace_months_date_vs_date_sample trop egfr  dm smoke  delta_mon1_baseline_to_d3
 1    44 52        1     1                              30 2600  56    1     0                       -822.  
 2    32 66        1     0                              73 1710  90    1     0                       -562.  
 3    20 56        1     1                               5 NA    75    0     1                       -502.  
 4    17 44        1     0                              77 840   71    0     0                       -389.  
 5    52 49        1     0                              74 1740  71    0     1                       -372.  
 6    57 58        1     0                              74 5010  68    0     1                       -308.  
 7    79 68        1     0                              45 776   90    0     0                       -284.  
 8    14 74        1     1                               6 7120  78    0     0                       -279.  
 9   223 63        1     0                              46 4281  90    0     0                       -218.  
10    56 43        1     0                              70 1360  90    1     0                       -173.  
11    50 54        1     0                              70 15300 90    0     1                       -163.  
12    31 47        0     0                              72 6490  77    1     1                        -95.7 
13    35 47        1     0                              77 NA    83    0     0                        -71.0 
14    36 64        1     1                               5 15940 52    0     1                        -69.7 
15    15 65        1     1                              43 6300  49    1     0                        -69.6 
16    12 57        1     0                              71 6020  88    0     1                        -66.5 
17    43 59        0     0                              74 2100  84    0     1                        -58.8 
18    22 46        1     0                              77 5330  88    0     1                        -29.3 
19    54 59        1     0                              71 1500  81    1     1                        -25.7 
20    26 66        1     0                              77 500   51    0     0                        -12.5 
21    29 73        0     0                              77 NA    51    0     0                         -2.99
22    25 54        1     0                              73 1080  87    0     0                          2.81
23    39 54        1     0                              74 990   77    0     0                         32.9 
24    47 62        1     0                              69 1420  85    0     0                         33.0 
25    49 54        1     1                              28 NA    76    1     0                         44.1 
26    24 47        1     0                              77 2390  90    0     1                         47.7 
27    45 51        0     0                              73 3710  65    0     1                         55.9 
28    30 73        0     0                              68 3340  48    1     1                        117.  
29    16 57        1     0                              73 180   99    0     1                        131.  
30    55 47        1     0                              70 NA    90    0     1                        131.  
31    37 81        1     0                              74 NA    99    1     1                        147.  
32    21 46        1     0                              75 3600  87    0     1                        153.  
33    60 72        1     0                              76 470   62    0     0                        160.  
34    18 56        1     0                              69 6390  90    0     1                        165.  
35    13 53        1     0                              69 1970  87    1     1                        180.  
36    19 66        1     0                              78 9320  59    0     0                        180.  
37    33 59        1     0                              69 2260  79    0     1                        193.  
38   139 39        0     0                              58 NA    90    0     1                        209.  
39    38 55        1     0                              78 3930  90    1     0                        244.  
40    27 28        1     0                              71 6440  90    0     1                        248.  
41    58 36        1     0                              76 NA    78    1     1                        327.  
42    61 48        1     0                              76 4470  90    0     1                        336.  
43    42 38        1     0                              69 1800  69    0     1                        375.  
44    28 76        1     0                              71 40    90    1     1                        419.  

Any help would be great! Thanks

CodePudding user response:

If I understand you correctly, you want to use the quantile as a categorical dependent variable in the Cox PH model. I can't recreate your error, but this produces coefficient estimates for each quantile using the first quantile as the reference:

# Determine quantiles

df$quantile <- cut(df$delta_mon1_baseline_to_d3, quantile(df$delta_mon1_baseline_to_d3))

# Run model (per OP model) 
cox <- survival::coxph(survival::Surv(mace_months_date_vs_date_sample, mace) ~ df$quantile, data = df)

# survival::coxph(formula = survival::Surv(mace_months_date_vs_date_sample, 
#                                          mace) ~ df$quantile, data = df)
# 
# coef  exp(coef)   se(coef)      z     p
# df$quantile(-113,17.9] -1.490e-01  8.616e-01  1.000e 00 -0.149 0.882
# df$quantile(17.9,161]  -8.902e-01  4.106e-01  1.225e 00 -0.727 0.467
# df$quantile(161,419]   -1.990e 01  2.274e-09  1.331e 04 -0.001 0.999

CodePudding user response:

From the data you have provided, you can do:

library(survival)

df$quantile <- df$delta_mon1_baseline_to_d3
df$stratum <- findInterval(df$quantile, quantile(df$quantile, na.rm = TRUE)[-5])
df$stratum <- factor(df$stratum)

cox <- coxph(Surv(mace_months_date_vs_date_sample, mace) ~ stratum, data = df)

summary(cox)
#> Call:
#> coxph(formula = Surv(mace_months_date_vs_date_sample, mace) ~ 
#>     stratum, data = df)
#> 
#>   n= 44, number of events= 6 
#> 
#>                coef  exp(coef)   se(coef)      z Pr(>|z|)
#> stratum2 -4.780e-01  6.201e-01  9.135e-01 -0.523    0.601
#> stratum3 -1.211e 00  2.980e-01  1.155e 00 -1.048    0.295
#> stratum4 -2.015e 01  1.767e-09  1.277e 04 -0.002    0.999
#> 
#>          exp(coef) exp(-coef) lower .95 upper .95
#> stratum2 6.201e-01  1.613e 00   0.10348     3.715
#> stratum3 2.980e-01  3.356e 00   0.03097     2.867
#> stratum4 1.767e-09  5.661e 08   0.00000       Inf
#> 
#> Concordance= 0.731  (se = 0.08 )
#> Likelihood ratio test= 4.99  on 3 df,   p=0.2
#> Wald test            = 1.14  on 3 df,   p=0.8
#> Score (logrank) test = 3.86  on 3 df,   p=0.3

This shows 3 hazard ratios (comparisons of quantiles 2-4 to quantile 1).

  •  Tags:  
  • r
  • Related