survminer icon indicating copy to clipboard operation
survminer copied to clipboard

Different behavior of confidence bands in ggcoxzph compared to plot.cox.zph

Open ter-hel opened this issue 5 years ago • 9 comments

Hello, I just encountered a problem with the ggcoxzph fuction while plotting the Schoenfeld residuals. The confidence bands seemed to be oddly wide. I compared the results to the plot from the function plot.cox.zph where they were much smaller.

Plot with ggcoxzph: Rplot

Plot with plot.cox.zph: Rplot01

I looked at the source code of both functions and noticed a difference:

# confidence bands in plot.cox.zph (v3.1-8 of survival package):
if (se) {
  bk <- backsolve(qmat$qr[1:df, 1:df], diag(df))
  xtx <- bk %*% t(bk)
  # seval <- d*((pmat%*% xtx) *pmat) %*% rep(1, df)
  seval <- ((pmat%*% xtx) *pmat) %*% rep(1, df)
}

# confidence bands in ggcoxzph (v0.4.6 of survminer package):
if (se) {
  bk <- backsolve(qmat$qr[1:df, 1:df], diag(df))
  xtx <- bk %*% t(bk)
  seval <- d * ((pmat %*% xtx) * pmat) %*% rep(1, df)
}

So it seems that the multiplication with d has been dropped in plot.cox.zph. The parameter d is defined earlier in both functions as:

yy <- x$y
d <- nrow(yy)

Should ggcoxzph be adjusted to match the results of plot.cox.zph? I prefer the smaller confidence bands of plot.cox.zph because it's earsier to see if the PH assumption is fulfilled from a visual point of view.

ter-hel avatar Jan 26 '20 12:01 ter-hel

thank you for reporting this; ggcoxzph needs to be adjusted

kassambara avatar Jan 26 '20 12:01 kassambara

Hello, I am experiencing the same problem. Has the ggcoxzph function been adjusted yet?

etyas avatar Jun 01 '20 13:06 etyas

thank you for reporting this; ggcoxzph needs to be adjusted

This has not been corrected yet.

bcfgothenburg avatar Nov 29 '20 15:11 bcfgothenburg

This is an important issue and would appreciate a fix. Thanks.

raheems avatar Apr 13 '21 17:04 raheems

Running into similar issue, hope this will be fixed soon

Hark-Jin avatar May 11 '21 19:05 Hark-Jin

Has anyone found an easy work around, meanwhile they fix it?

marcoguerzoni avatar Feb 10 '22 14:02 marcoguerzoni

@kassambara Is there any chance to fix that? I mean either delete the "d" or expose it as a parameter with default value=1?

Generalized avatar May 09 '22 01:05 Generalized

Has anyone found an easy work around, meanwhile they fix it?

Use plot.cox.zph instead. @kassambara Has acknowledged it and it should be a quick fix, so we'll just have to wait.

padj avatar May 19 '22 12:05 padj

@kassambara Is there any chance to fix that? I mean either delete the "d" or expose it as a parameter with default value=1?

Temporary fix: https://github.com/kassambara/survminer/issues/534#issuecomment-860125015

Also, pending PR: https://github.com/kassambara/survminer/pull/535

arielhasidim avatar Feb 13 '23 11:02 arielhasidim