tests/testthat/test-zph_phregr.R

library(dplyr, warn.conflicts = FALSE)
library(survival)

testthat::test_that("zph_phregr: right-censored data", {
  fit1 <- phregr(data = liver, time = "Time", event = "Status", 
                 covariates = c("log(Bilirubin)", "log(Protime)", 
                                "log(Albumin)", "Age", "Edema"))
  
  fit2 <-  coxph(Surv(Time, Status) ~ log(Bilirubin) + log(Protime) + 
                   log(Albumin) + Age + Edema, data = liver)
  
  zph1 <- zph_phregr(fit1, transform = "log")
  zph2 <- cox.zph(fit2, transform = "log")
  
  rownames(zph2$y) <- NULL
  zph2$call <- NULL
  
  testthat::expect_equal(zph1, zph2)
})

Try the trtswitch package in your browser

Any scripts or data that you put into this service are public.

trtswitch documentation built on Jan. 10, 2026, 5:08 p.m.