kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
509 stars 164 forks source link

Confidence band in the ggcoxzph() function #576

Closed pdeninis closed 1 year ago

pdeninis commented 2 years ago

Expected behavior

df <-
structure(list(PAT = 1:40, TREAT = structure(c(2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), .Label = c("Control", "TEST"), class = "factor"), 
     AU = c(0L, 0L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 
     0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 0L, 4L, 4L, 0L, 4L, 
     4L, 0L, 4L, 4L, 0L, 4L, 4L, 0L, 4L, 4L, 0L, 4L), H.W = c(3L, 
     2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 
     3L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 
     3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L), Healed = c(1L, 1L, 1L, 
     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
     1L, 1L, 1L, 1L, 1L, 1L, 1L)), row.names = c(NA, 40L), class = "data.frame")

library(survival)
fnewL <- coxph(Surv(H.W, Healed) ~ TREAT, data = df)

dev.new();plot(cox.zph(fnewL), df=3)

image

Actual behavior

With the 0.4.9 version of survminer, the line:

dev.new(); survminer:::ggcoxzph(cox.zph(fnewL), df=3)

prints the following plot:

image

This link https://stats.stackexchange.com/questions/560975/how-to-interpret-schoenfield-residual-plot suggests a mistake could be present in the function at the line:

seval <- d * ((pmat %*% xtx) * pmat) %*% rep(1, df)

By removing the d factor (the string "d*") as explained in the link, the following plot is printed:

image

Is the actual SE formula wrong? Maybe it has some other meaning? Have you some reference for it? I believe it deserves a check.

PDN

Steps to reproduce the problem

session_info()

> devtools::session_info()
- Session info ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 4.0.5 (2021-03-31)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       Rgui                        
 language (EN)                        
 collate  Italian_Italy.1252          
 ctype    Italian_Italy.1252          
 tz       Europe/Berlin               
 date     2022-03-26                  

- Packages -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package      * version    date       lib source        
 abind          1.4-5      2016-07-21 [1] CRAN (R 4.0.3)
 assertthat     0.2.1      2019-03-21 [1] CRAN (R 4.0.3)
 backports      1.2.1      2020-12-09 [1] CRAN (R 4.0.3)
 brglm        * 0.7.2      2021-04-22 [1] CRAN (R 4.0.5)
 broom          0.7.9      2021-07-27 [1] CRAN (R 4.0.5)
 cachem         1.0.6      2021-08-19 [1] CRAN (R 4.0.5)
 callr          3.7.0      2021-04-20 [1] CRAN (R 4.0.5)
 car            3.0-11     2021-06-27 [1] CRAN (R 4.0.5)
 carData        3.0-4      2020-05-22 [1] CRAN (R 4.0.3)
 cellranger     1.1.0      2016-07-27 [1] CRAN (R 4.0.3)
 cli            3.0.1      2021-07-17 [1] CRAN (R 4.0.5)
 coda           0.19-4     2020-09-30 [1] CRAN (R 4.0.4)
 codetools      0.2-18     2020-11-04 [2] CRAN (R 4.0.5)
 colorspace     2.0-2      2021-06-24 [1] CRAN (R 4.0.5)
 crayon         1.4.1      2021-02-08 [1] CRAN (R 4.0.5)
 curl           4.3.2      2021-06-23 [1] CRAN (R 4.0.5)
 data.table     1.14.0     2021-02-21 [1] CRAN (R 4.0.5)
 DBI            1.1.1      2021-01-15 [1] CRAN (R 4.0.5)
 desc           1.3.0      2021-03-05 [1] CRAN (R 4.0.5)
 devtools       2.4.2      2021-06-07 [1] CRAN (R 4.0.5)
 digest         0.6.27     2020-10-24 [1] CRAN (R 4.0.5)
 dplyr          1.0.7      2021-06-18 [1] CRAN (R 4.0.5)
 ellipsis       0.3.2      2021-04-29 [1] CRAN (R 4.0.5)
 emmeans      * 1.6.3      2021-08-20 [1] CRAN (R 4.0.5)
 estimability   1.3        2018-02-11 [1] CRAN (R 4.0.3)
 fansi          0.5.0      2021-05-25 [1] CRAN (R 4.0.5)
 farver         2.1.0      2021-02-28 [1] CRAN (R 4.0.5)
 fastmap        1.1.0      2021-01-25 [1] CRAN (R 4.0.4)
 forcats        0.5.1      2021-01-27 [1] CRAN (R 4.0.5)
 foreign        0.8-81     2020-12-22 [1] CRAN (R 4.0.3)
 fs             1.5.0      2020-07-31 [1] CRAN (R 4.0.3)
 generics       0.1.0      2020-10-31 [1] CRAN (R 4.0.3)
 ggplot2      * 3.3.5      2021-06-25 [1] CRAN (R 4.0.5)
 ggpubr       * 0.4.0      2020-06-27 [1] CRAN (R 4.0.5)
 ggsignif       0.6.3      2021-09-09 [1] CRAN (R 4.0.5)
 ggtext         0.1.1      2020-12-17 [1] CRAN (R 4.0.5)
 glue           1.4.2      2020-08-27 [1] CRAN (R 4.0.3)
 gridExtra    * 2.3        2017-09-09 [1] CRAN (R 4.0.3)
 gridtext       0.1.4      2020-12-10 [1] CRAN (R 4.0.5)
 gtable         0.3.0      2019-03-25 [1] CRAN (R 4.0.3)
 haven          2.4.3      2021-08-04 [1] CRAN (R 4.0.5)
 hms            1.1.0      2021-05-17 [1] CRAN (R 4.0.5)
 interactions * 1.1.5      2021-07-02 [1] CRAN (R 4.0.5)
 jtools         2.1.4      2021-09-03 [1] CRAN (R 4.0.5)
 km.ci          0.5-2      2009-08-30 [1] CRAN (R 4.0.5)
 KMsurv         0.1-5      2012-12-03 [1] CRAN (R 4.0.3)
 knitr          1.34       2021-09-09 [1] CRAN (R 4.0.5)
 labeling       0.4.2      2020-10-20 [1] CRAN (R 4.0.3)
 lattice        0.20-41    2020-04-02 [2] CRAN (R 4.0.5)
 lifecycle      1.0.0      2021-02-15 [1] CRAN (R 4.0.5)
 magrittr       2.0.1      2020-11-17 [1] CRAN (R 4.0.3)
 markdown       1.1        2019-08-07 [1] CRAN (R 4.0.3)
 MASS           7.3-54     2021-05-03 [1] CRAN (R 4.0.5)
 Matrix         1.3-2      2021-01-06 [2] CRAN (R 4.0.5)
 memoise        2.0.0      2021-01-26 [1] CRAN (R 4.0.5)
 mgcv           1.8-36     2021-06-01 [1] CRAN (R 4.0.5)
 multcomp       1.4-17     2021-04-29 [1] CRAN (R 4.0.5)
 munsell        0.5.0      2018-06-12 [1] CRAN (R 4.0.3)
 mvtnorm        1.1-2      2021-06-07 [1] CRAN (R 4.0.5)
 nlme           3.1-152    2021-02-04 [2] CRAN (R 4.0.5)
 numDeriv       2016.8-1.1 2019-06-06 [1] CRAN (R 4.0.3)
 openxlsx       4.2.4      2021-06-16 [1] CRAN (R 4.0.5)
 ordinal      * 2019.12-10 2019-12-15 [1] CRAN (R 4.0.5)
 pander         0.6.4      2021-06-13 [1] CRAN (R 4.0.5)
 pillar         1.6.2      2021-07-29 [1] CRAN (R 4.0.5)
 pkgbuild       1.2.0      2020-12-15 [1] CRAN (R 4.0.5)
 pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 4.0.3)
 pkgload        1.2.2      2021-09-11 [1] CRAN (R 4.0.5)
 plyr           1.8.6      2020-03-03 [1] CRAN (R 4.0.3)
 prettyunits    1.1.1      2020-01-24 [1] CRAN (R 4.0.3)
 processx       3.5.2      2021-04-30 [1] CRAN (R 4.0.5)
 profileModel * 0.6.1      2021-01-08 [1] CRAN (R 4.0.5)
 ps             1.6.0      2021-02-28 [1] CRAN (R 4.0.5)
 purrr          0.3.4      2020-04-17 [1] CRAN (R 4.0.3)
 R6             2.5.1      2021-08-19 [1] CRAN (R 4.0.5)
 RColorBrewer   1.1-2      2014-12-07 [1] CRAN (R 4.0.3)
 Rcpp           1.0.7      2021-07-07 [1] CRAN (R 4.0.5)
 readxl         1.3.1      2019-03-13 [1] CRAN (R 4.0.3)
 remotes        2.4.0      2021-06-02 [1] CRAN (R 4.0.5)
 rio            0.5.27     2021-06-21 [1] CRAN (R 4.0.5)
 rlang          0.4.11     2021-04-30 [1] CRAN (R 4.0.5)
 rprojroot      2.0.2      2020-11-15 [1] CRAN (R 4.0.3)
 rstatix        0.7.0      2021-02-13 [1] CRAN (R 4.0.5)
 sandwich       3.0-1      2021-05-18 [1] CRAN (R 4.0.5)
 scales         1.1.1      2020-05-11 [1] CRAN (R 4.0.3)
 sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 4.0.5)
 stringi        1.7.4      2021-08-25 [1] CRAN (R 4.0.5)
 stringr        1.4.0      2019-02-10 [1] CRAN (R 4.0.5)
 survival     * 3.2-10     2021-03-16 [2] CRAN (R 4.0.5)
 survminer    * 0.4.9      2021-03-09 [1] CRAN (R 4.0.5)
 survMisc       0.5.5      2018-07-05 [1] CRAN (R 4.0.5)
 survRM2      * 1.0-3      2020-06-13 [1] CRAN (R 4.0.5)
 testthat       3.0.4      2021-07-01 [1] CRAN (R 4.0.5)
 TH.data        1.0-10     2019-01-21 [1] CRAN (R 4.0.4)
 tibble         3.1.4      2021-08-25 [1] CRAN (R 4.0.5)
 tidyr          1.1.3      2021-03-03 [1] CRAN (R 4.0.5)
 tidyselect     1.1.1      2021-04-30 [1] CRAN (R 4.0.5)
 tree         * 1.0-41     2021-08-17 [1] CRAN (R 4.0.5)
 ucminf         1.1-4      2016-08-18 [1] CRAN (R 4.0.3)
 usethis        2.0.1      2021-02-10 [1] CRAN (R 4.0.5)
 utf8           1.2.2      2021-07-24 [1] CRAN (R 4.0.5)
 vctrs          0.3.8      2021-04-29 [1] CRAN (R 4.0.5)
 withr          2.4.2      2021-04-18 [1] CRAN (R 4.0.5)
 xfun           0.26       2021-09-14 [1] CRAN (R 4.0.5)
 xml2           1.3.2      2020-04-23 [1] CRAN (R 4.0.3)
 xtable         1.8-4      2019-04-21 [1] CRAN (R 4.0.3)
 zip            2.2.0      2021-05-31 [1] CRAN (R 4.0.5)
 zoo            1.8-9      2021-03-09 [1] CRAN (R 4.0.5)

[1] D:/Paolo/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.5/library
MarcinKosinski commented 2 years ago

Hey @pdeninis will that get fixed once this PR is merged? https://github.com/kassambara/survminer/pull/535 that reflects https://github.com/kassambara/survminer/pull/534 this issue?

pdeninis commented 2 years ago

Hi, Marcin.

Sorry, I was unaware that the issue had already been signaled. As I wrote in my post, removing the d multiplier makes the graph identical to the Therneau's one. I read the comments in https://github.com/kassambara/survminer/issues/534#issuecomment-860125015 and they are consistent with my knowledge.

I do not know which fix have you prefigured, but I suppose it substantively makes the graph to look identical to that of Therenau, and this solves the problem I reported.

pdeninis commented 2 years ago

Hi, Marcin.

Sorry, I was unaware that the issue had already been signaled. As I wrote in my post, removing the d multiplier makes the graph identical to the Therneau's one. I read the comments in #534 (comment) https://github.com/kassambara/survminer/issues/534#issuecomment-860125015 and they are consistent with my knowledge.

I do not know which fix have you prefigured, but I suppose it substantively makes the graph to look identical to that of Therenau, and this solves the problem I reported.

Il giorno lun 16 mag 2022 alle ore 15:13 Marcin Kosiński < @.***> ha scritto:

Hey @pdeninis https://github.com/pdeninis will that get fixed once this PR is merged? #535 https://github.com/kassambara/survminer/pull/535 that reflects #534 https://github.com/kassambara/survminer/issues/534 this issue?

— Reply to this email directly, view it on GitHub https://github.com/kassambara/survminer/issues/576#issuecomment-1127657549, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIO4PDVVI4XC7WQ35S3QUD3VKJCY5ANCNFSM5RW63ZKA . You are receiving this because you were mentioned.Message ID: @.***>

kassambara commented 1 year ago

fixed in #535