Some residuals (like schoenfeld) are calculated for each failure time, not each observation.
Thus lines 91-94 will trigger an error because a data frame with schoenfeld residuals (n.rows = number of failure times) cannot be bind to vector of linear predictions for observations (=number of rows in the data).
The easiest fix is to replace xval <- 1:fit$n by xval <- 1:nrow(res)
and change the default value for linear.predictions e.g. by linear.predictions = type %in% c("martingale", "score", "dfbeta", ...)
Expected behaviour
Example for ggcoxdiagnostics() will work also for schoenfeld residuals
coxph.fit2 <- coxph(Surv(futime, fustat) ~ age + ecog.ps, data=ovarian)
ggcoxdiagnostics(coxph.fit2, type = "schoenfeld")
Actual behaviour
Error in `$<-.data.frame`(`*tmp*`, "xval", value = c(2.60222487953181, :
replacement has 26 rows, data has 12
Steps to reproduce the problem
coxph.fit2 <- coxph(Surv(futime, fustat) ~ age + ecog.ps, data=ovarian)
ggcoxdiagnostics(coxph.fit2, type = "schoenfeld")
Some residuals (like schoenfeld) are calculated for each failure time, not each observation.
Thus lines 91-94 will trigger an error because a data frame with schoenfeld residuals (n.rows = number of failure times) cannot be bind to vector of linear predictions for observations (=number of rows in the data).
The easiest fix is to replace
xval <- 1:fit$n
byxval <- 1:nrow(res)
and change the default value forlinear.predictions
e.g. bylinear.predictions = type %in% c("martingale", "score", "dfbeta", ...)
Expected behaviour
Example for ggcoxdiagnostics() will work also for schoenfeld residuals
Actual behaviour
Steps to reproduce the problem