Skip to content

Commit

Permalink
single unit-test for residuals
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Nov 4, 2024
1 parent 7bbe4c6 commit a4843fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/Residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-smallCox.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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!!!
})


Expand Down

0 comments on commit a4843fe

Please sign in to comment.