diff --git a/R/Residuals.R b/R/Residuals.R index b96c229c..9d7f5cb4 100644 --- a/R/Residuals.R +++ b/R/Residuals.R @@ -27,6 +27,7 @@ #' either a vector of numbers or covariateId names #' @param type Character string indicating the type of residual desires. Possible #' values are "schoenfeld". +#' @param ... Additional parameters for compatibility with S3 parent function #' #' @importFrom stats residuals #' @@ -42,7 +43,7 @@ residuals.cyclopsFit <- function(object, parm, type = "schoenfeld", ...) { .checkInterface(object$cyclopsData, testOnly = TRUE) - res <- .cyclopsGetSchoenfeldResiduals(cyclopsFitRight$interface, NULL) + res <- .cyclopsGetSchoenfeldResiduals(object$interface, NULL) result <- res$residuals names(result) <- res$times diff --git a/tests/testthat/test-smallCox.R b/tests/testthat/test-smallCox.R index 873c5b77..9855350e 100644 --- a/tests/testthat/test-smallCox.R +++ b/tests/testthat/test-smallCox.R @@ -34,6 +34,21 @@ start, length, event, x1, x2 tolerance <- 1E-4 expect_equal(coef(cyclopsFitRight), coef(goldRight), tolerance = tolerance) + # Test residuals + + goldRes <- residuals(goldCounting, "schoenfeld")[,1] + cyclopsRes <- residuals(cyclopsFitRight, "schoenfeld") + + expect_equal(cyclopsRes, goldRes, tolerance = tolerance) + + # cox2.zph(goldCounting, transform = "identity") + # residuals2.coxph(goldCounting, type = "scaledsch") + # + # # rr <- rr * vv * ndead + coef + # + # hand <- rev(navg) * goldCounting$var[1,1] * sum(event) + coef(goldCounting) + # + # expect_equivalent(res2, hand) # scaled goldStrat <- coxph(Surv(length, event) ~ x1 + strata(x2), test) @@ -42,6 +57,10 @@ start, length, event, x1, x2 modelType = "cox") cyclopsFitStrat <- fitCyclopsModel(dataPtrStrat) expect_equal(coef(cyclopsFitStrat), coef(goldStrat), tolerance = tolerance) + + goldStratRes <- residuals(goldStrat, "schoenfeld") + cyclopsStratRes <- residuals(cyclopsFitStrat, "schoenfeld") + # TODO Not yet the same order!!! })