Confidence interval of median, R versus SPSS

Hello everybody,

I am kind of new to R and Rstudio and if it is possible I need some advice. I plotted a survival curve and want to calculate the median survival with the confidence interval using surfvit(formula);

#survival fit
sfit <- survfit(Surv(tvar1, evar1) ~ gvar1, data=sdat1)
survfit(formula = Surv(tvar1, evar1) ~ gvar1)              # print a short summary of your KM-curve
pval <- surv_pvalue(sfit, data = sdat1)$pval

With a median (95% CI) of 21.1 (15.8 - 55.2) for group 1 and 82.0 (51.3 - NA) for group 2. However, before I plotted the survival curves with the median survival (95% confidence interval) in SPSS and I got different 95% confidence intervals (15.4 - 26.7) for group 1 and (0 - 167.6) for group 2.

Since the numbers used in SPSS are already widely spread I would like to replicate the confidence intervals of SPSS in R. I prefer using R to perform all my future analyses. Could anyone explain to me why there is a difference in 95% confidence intervals of the median between R and SPSS. Is it possible to replicate the 95% confidence intervals of SPSS in R?

Regards,
Berend

Hi, could you provide a reproducible example, called a reprex. It would look like

library(survival)
with(aml, Surv(time, status))
#>  [1]   9   13   13+  18   23   28+  31   34   45+  48  161+   5    5    8 
#> [15]   8   12   16+  23   27   30   33   43   45
survfit(Surv(time, status) ~ ph.ecog, data=lung)
#> Call: survfit(formula = Surv(time, status) ~ ph.ecog, data = lung)
#> 
#>    1 observation deleted due to missingness 
#>             n events median 0.95LCL 0.95UCL
#> ph.ecog=0  63     37    394     348     574
#> ph.ecog=1 113     82    306     268     429
#> ph.ecog=2  50     44    199     156     288
#> ph.ecog=3   1      1    118      NA      NA
Surv(heart$start, heart$stop, heart$event) 
#>   [1] (  0.0,  50.0]  (  0.0,   6.0]  (  0.0,   1.0+] (  1.0,  16.0] 
#>   [5] (  0.0,  36.0+] ( 36.0,  39.0]  (  0.0,  18.0]  (  0.0,   3.0] 
#>   [9] (  0.0,  51.0+] ( 51.0, 675.0]  (  0.0,  40.0]  (  0.0,  85.0] 
#>  [13] (  0.0,  12.0+] ( 12.0,  58.0]  (  0.0,  26.0+] ( 26.0, 153.0] 
#>  [17] (  0.0,   8.0]  (  0.0,  17.0+] ( 17.0,  81.0]  (  0.0,  37.0+]
#>  [21] ( 37.0,1387.0]  (  0.0,   1.0]  (  0.0,  28.0+] ( 28.0, 308.0] 
#>  [25] (  0.0,  36.0]  (  0.0,  20.0+] ( 20.0,  43.0]  (  0.0,  37.0] 
#>  [29] (  0.0,  18.0+] ( 18.0,  28.0]  (  0.0,   8.0+] (  8.0,1032.0] 
#>  [33] (  0.0,  12.0+] ( 12.0,  51.0]  (  0.0,   3.0+] (  3.0, 733.0] 
#>  [37] (  0.0,  83.0+] ( 83.0, 219.0]  (  0.0,  25.0+] ( 25.0,1800.0+]
#>  [41] (  0.0,1401.0+] (  0.0, 263.0]  (  0.0,  71.0+] ( 71.0,  72.0] 
#>  [45] (  0.0,  35.0]  (  0.0,  16.0+] ( 16.0, 852.0]  (  0.0,  16.0] 
#>  [49] (  0.0,  17.0+] ( 17.0,  77.0]  (  0.0,  51.0+] ( 51.0,1587.0+]
#>  [53] (  0.0,  23.0+] ( 23.0,1572.0+] (  0.0,  12.0]  (  0.0,  46.0+]
#>  [57] ( 46.0, 100.0]  (  0.0,  19.0+] ( 19.0,  66.0]  (  0.0,   4.5+]
#>  [61] (  4.5,   5.0]  (  0.0,   2.0+] (  2.0,  53.0]  (  0.0,  41.0+]
#>  [65] ( 41.0,1408.0+] (  0.0,  58.0+] ( 58.0,1322.0+] (  0.0,   3.0] 
#>  [69] (  0.0,   2.0]  (  0.0,  40.0]  (  0.0,   1.0+] (  1.0,  45.0] 
#>  [73] (  0.0,   2.0+] (  2.0, 996.0]  (  0.0,  21.0+] ( 21.0,  72.0] 
#>  [77] (  0.0,   9.0]  (  0.0,  36.0+] ( 36.0,1142.0+] (  0.0,  83.0+]
#>  [81] ( 83.0, 980.0]  (  0.0,  32.0+] ( 32.0, 285.0]  (  0.0, 102.0] 
#>  [85] (  0.0,  41.0+] ( 41.0, 188.0]  (  0.0,   3.0]  (  0.0,  10.0+]
#>  [89] ( 10.0,  61.0]  (  0.0,  67.0+] ( 67.0, 942.0+] (  0.0, 149.0] 
#>  [93] (  0.0,  21.0+] ( 21.0, 343.0]  (  0.0,  78.0+] ( 78.0, 916.0+]
#>  [97] (  0.0,   3.0+] (  3.0,  68.0]  (  0.0,   2.0]  (  0.0,  69.0] 
#> [101] (  0.0,  27.0+] ( 27.0, 842.0+] (  0.0,  33.0+] ( 33.0, 584.0] 
#> [105] (  0.0,  12.0+] ( 12.0,  78.0]  (  0.0,  32.0]  (  0.0,  57.0+]
#> [109] ( 57.0, 285.0]  (  0.0,   3.0+] (  3.0,  68.0]  (  0.0,  10.0+]
#> [113] ( 10.0, 670.0+] (  0.0,   5.0+] (  5.0,  30.0]  (  0.0,  31.0+]
#> [117] ( 31.0, 620.0+] (  0.0,   4.0+] (  4.0, 596.0+] (  0.0,  27.0+]
#> [121] ( 27.0,  90.0]  (  0.0,   5.0+] (  5.0,  17.0]  (  0.0,   2.0] 
#> [125] (  0.0,  46.0+] ( 46.0, 545.0+] (  0.0,  21.0]  (  0.0, 210.0+]
#> [129] (210.0, 515.0+] (  0.0,  67.0+] ( 67.0,  96.0]  (  0.0,  26.0+]
#> [133] ( 26.0, 482.0+] (  0.0,   6.0+] (  6.0, 445.0+] (  0.0, 428.0+]
#> [137] (  0.0,  32.0+] ( 32.0,  80.0]  (  0.0,  37.0+] ( 37.0, 334.0] 
#> [141] (  0.0,   5.0]  (  0.0,   8.0+] (  8.0, 397.0+] (  0.0,  60.0+]
#> [145] ( 60.0, 110.0]  (  0.0,  31.0+] ( 31.0, 370.0+] (  0.0, 139.0+]
#> [149] (139.0, 207.0]  (  0.0, 160.0+] (160.0, 186.0]  (  0.0, 340.0] 
#> [153] (  0.0, 310.0+] (310.0, 340.0+] (  0.0,  28.0+] ( 28.0, 265.0+]
#> [157] (  0.0,   4.0+] (  4.0, 165.0]  (  0.0,   2.0+] (  2.0,  16.0] 
#> [161] (  0.0,  13.0+] ( 13.0, 180.0+] (  0.0,  21.0+] ( 21.0, 131.0+]
#> [165] (  0.0,  96.0+] ( 96.0, 109.0+] (  0.0,  21.0]  (  0.0,  38.0+]
#> [169] ( 38.0,  39.0+] (  0.0,  31.0+] (  0.0,  11.0+] (  0.0,   6.0]

Created on 2019-06-25 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.