R version 4.4.0 RC (2024-04-16 r86458 ucrt) -- "Puppy Cup" 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. > # > # Make sure that useless intervals do not cause issues, i.e., any that do > # not overlap at least one event time > # > library(survival) > test2 <- data.frame(time1 =c(1, 2, 5, 2, 1, 7, 3, 4, 8, 8, 3), + time2 =c(2, 3, 6, 7, 8, 9, 9, 9,14,17, 5), + event =c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0), + x =c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 500) ) > > # The data set is the same as book3.R, except for the wild observation > # with x=500 whose time interval of (4,5) overlaps no events. > > fit1 <- coxph(Surv(time1, time2, event) ~ x, test2, subset=(x<100)) > fit2 <- coxph(Surv(time1, time2, event) ~ x, test2) > > ii <- match(c("coefficients", "var", "loglik", "score", "iter", + "wald.test", "concordance"), names(fit1)) > all.equal(fit1[ii], fit2[ii]) [1] TRUE > all.equal(c(fit1$residuals,0), fit2$residuals, check.attributes=FALSE) [1] TRUE > > # The mean differs condiderably, and so to the linear predictors > > # Now the same with a penalized model > fit3 <- coxph(Surv(time1, time2, event) ~ ridge(x, theta=.1), test2, + subset= (x< 100)) > fit4 <- coxph(Surv(time1, time2, event) ~ ridge(x, theta=.1), test2) > fit5 <- coxph(Surv(time1,time2, event) ~ x, test2, + iter=0, init=fit4$coef) > > all.equal(fit3[ii], fit4[ii]) [1] TRUE > all.equal(c(fit3$residuals,0), fit4$residuals, check.attributes=FALSE) [1] TRUE > all.equal(fit4$residuals, fit5$residuals) [1] TRUE > > proc.time() user system elapsed 0.96 0.07 1.04