R Under development (unstable) (2024-01-28 r85838 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(Greg) Loading required package: Gmisc Loading required package: Rcpp Loading required package: htmlTable Loading required package: forestplot Loading required package: grid Loading required package: checkmate Loading required package: abind > library(dplyr) Attaching package: 'dplyr' The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union > data("melanoma", package = "boot") > melanoma <- mutate(melanoma, + status = factor(status, + levels = 1:3, + labels = c("melanoma-specific death", "alive", "other death")), + ulcer = factor(ulcer, + levels = 0:1, + labels = c("Absent", "Present")), + time = time / 365.25) > > library(survival) > regular_model <- coxph(Surv(time, status == "melanoma-specific death") ~ + age + sex + year + thickness + ulcer, + data = melanoma, + x = TRUE, y = TRUE) > > spl_melanoma <- timeSplitter(melanoma, + by = .1, + event_var = "status", + event_start_status = "alive", + time_var = "time", + time_related_vars = c("age", "year")) > > interval_model <- update(regular_model, + Surv(Start_time, Stop_time, status == "melanoma-specific death") ~ ., + data = spl_melanoma) > > mismatch <- abs(sum(coef(interval_model) - coef(regular_model))) > if (mismatch > 10^-10) { + stop("Failed to match interval with regular cox model.", + " Total coefficient difference = ", mismatch, + "\n Regular: ", paste(txtRound(coef(regular_model), 3), + collapse = ", " + ), + "\n Interval: ", paste(txtRound(coef(interval_model), 3), + collapse = ", " + ) + ) + } > > proc.time() user system elapsed 3.95 0.98 4.87