R Under development (unstable) (2025-10-16 r88927 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 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("mlt") Loading required package: basefun Loading required package: variables > library("survival") > options(digits = 4) > set.seed(29) > > y <- rexp(10) > d <- rep(c(TRUE, FALSE), length = length(y)) > ### right > (s <- Surv(y, d, type = "right")) [1] 2.67434 1.45784+ 0.16998 2.56883+ 0.65634 0.08317+ 0.20866 1.79566+ [9] 0.65482 0.32506+ > attr(s, "type") [1] "right" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67434 NA NA 2.6743 NA NA 2.6743 2 1.45784+ NA 1.45784 NA Inf NA 2.0661 3 0.16998 NA NA 0.1700 NA NA 0.1700 4 2.56883+ NA 2.56883 NA Inf NA 2.6216 5 0.65634 NA NA 0.6563 NA NA 0.6563 6 0.08317+ NA 0.08317 NA Inf NA 1.3788 7 0.20866 NA NA 0.2087 NA NA 0.2087 8 1.79566+ NA 1.79566 NA Inf NA 2.2350 9 0.65482 NA NA 0.6548 NA NA 0.6548 10 0.32506+ NA 0.32506 NA Inf NA 1.4997 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### right censored, left truncated > (s <- Surv(y, y + 1, d)) [1] (2.67434,3.674] (1.45784,2.458+] (0.16998,1.170] (2.56883,3.569+] [5] (0.65634,1.656] (0.08317,1.083+] (0.20866,1.209] (1.79566,2.796+] [9] (0.65482,1.655] (0.32506,1.325+] > attr(s, "type") [1] "counting" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 (2.67434,3.674] 2.67434 NA 3.674 NA NA 3.674 2 (1.45784,2.458+] 1.45784 2.458 NA Inf NA 3.066 3 (0.16998,1.170] 0.16998 NA 1.170 NA NA 1.170 4 (2.56883,3.569+] 2.56883 3.569 NA Inf NA 3.622 5 (0.65634,1.656] 0.65634 NA 1.656 NA NA 1.656 6 (0.08317,1.083+] 0.08317 1.083 NA Inf NA 2.379 7 (0.20866,1.209] 0.20866 NA 1.209 NA NA 1.209 8 (1.79566,2.796+] 1.79566 2.796 NA Inf NA 3.235 9 (0.65482,1.655] 0.65482 NA 1.655 NA NA 1.655 10 (0.32506,1.325+] 0.32506 1.325 NA Inf NA 2.500 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### left censored > (s <- Surv(y, d, type = "left")) [1] 2.67434 1.45784- 0.16998 2.56883- 0.65634 0.08317- 0.20866 1.79566- [9] 0.65482 0.32506- > attr(s, "type") [1] "left" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67434 NA NA 2.6743 NA NA 2.67434 2 1.45784- NA -Inf NA 1.45784 NA 0.77050 3 0.16998 NA NA 0.1700 NA NA 0.16998 4 2.56883- NA -Inf NA 2.56883 NA 1.32600 5 0.65634 NA NA 0.6563 NA NA 0.65634 6 0.08317- NA -Inf NA 0.08317 NA 0.08317 7 0.20866 NA NA 0.2087 NA NA 0.20866 8 1.79566- NA -Inf NA 1.79566 NA 0.93942 9 0.65482 NA NA 0.6548 NA NA 0.65482 10 0.32506- NA -Inf NA 0.32506 NA 0.20411 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### interval > dd <- rep(0:3, length = length(y)) > (s <- Surv(y, y + 1, dd, type = "interval")) [1] 2.67434+ 1.45784 0.16998- [2.56883, 3.569] [5] 0.65634+ 0.08317 0.20866- [1.79566, 2.796] [9] 0.65482+ 0.32506 > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67434+ NA 2.6743 NA Inf NA 3.12158 2 1.45784 NA NA 1.45784 NA NA 1.45784 3 0.16998- NA -Inf NA 0.1700 NA 0.12658 4 [2.56883, 3.569] NA 2.5688 NA 3.5688 NA 3.06883 5 0.65634+ NA 0.6563 NA Inf NA 2.11258 6 0.08317 NA NA 0.08317 NA NA 0.08317 7 0.20866- NA -Inf NA 0.2087 NA 0.14592 8 [1.79566, 2.796] NA 1.7957 NA 2.7957 NA 2.29566 9 0.65482+ NA 0.6548 NA Inf NA 2.11183 10 0.32506 NA NA 0.32506 NA NA 0.32506 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### interval2 > (s <- Surv(y, y + 1, type = "interval2")) [1] [2.67434, 3.674] [1.45784, 2.458] [0.16998, 1.170] [2.56883, 3.569] [5] [0.65634, 1.656] [0.08317, 1.083] [0.20866, 1.209] [1.79566, 2.796] [9] [0.65482, 1.655] [0.32506, 1.325] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 [2.67434, 3.674] NA 2.67434 NA 3.674 NA 3.1743 2 [1.45784, 2.458] NA 1.45784 NA 2.458 NA 1.9578 3 [0.16998, 1.170] NA 0.16998 NA 1.170 NA 0.6700 4 [2.56883, 3.569] NA 2.56883 NA 3.569 NA 3.0688 5 [0.65634, 1.656] NA 0.65634 NA 1.656 NA 1.1563 6 [0.08317, 1.083] NA 0.08317 NA 1.083 NA 0.5832 7 [0.20866, 1.209] NA 0.20866 NA 1.209 NA 0.7087 8 [1.79566, 2.796] NA 1.79566 NA 2.796 NA 2.2957 9 [0.65482, 1.655] NA 0.65482 NA 1.655 NA 1.1548 10 [0.32506, 1.325] NA 0.32506 NA 1.325 NA 0.8251 > stopifnot(all.equal(s, as.Surv(R(s)))) > > (s <- Surv(y, ifelse(d, Inf, y + 1), type = "interval2")) [1] 2.67434+ [1.45784, 2.458] 0.16998+ [2.56883, 3.569] [5] 0.65634+ [0.08317, 1.083] 0.20866+ [1.79566, 2.796] [9] 0.65482+ [0.32506, 1.325] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67434+ NA 2.67434 NA Inf NA 3.1216 2 [1.45784, 2.458] NA 1.45784 NA 2.458 NA 1.9578 3 0.16998+ NA 0.16998 NA Inf NA 1.8694 4 [2.56883, 3.569] NA 2.56883 NA 3.569 NA 3.0688 5 0.65634+ NA 0.65634 NA Inf NA 2.1126 6 [0.08317, 1.083] NA 0.08317 NA 1.083 NA 0.5832 7 0.20866+ NA 0.20866 NA Inf NA 1.8887 8 [1.79566, 2.796] NA 1.79566 NA 2.796 NA 2.2957 9 0.65482+ NA 0.65482 NA Inf NA 2.1118 10 [0.32506, 1.325] NA 0.32506 NA 1.325 NA 0.8251 > stopifnot(all.equal(s, as.Surv(R(s)))) > > (s <- Surv(y, ifelse(d, NA, y + 1), type = "interval2")) [1] 2.67434+ [1.45784, 2.458] 0.16998+ [2.56883, 3.569] [5] 0.65634+ [0.08317, 1.083] 0.20866+ [1.79566, 2.796] [9] 0.65482+ [0.32506, 1.325] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67434+ NA 2.67434 NA Inf NA 3.1216 2 [1.45784, 2.458] NA 1.45784 NA 2.458 NA 1.9578 3 0.16998+ NA 0.16998 NA Inf NA 1.8694 4 [2.56883, 3.569] NA 2.56883 NA 3.569 NA 3.0688 5 0.65634+ NA 0.65634 NA Inf NA 2.1126 6 [0.08317, 1.083] NA 0.08317 NA 1.083 NA 0.5832 7 0.20866+ NA 0.20866 NA Inf NA 1.8887 8 [1.79566, 2.796] NA 1.79566 NA 2.796 NA 2.2957 9 0.65482+ NA 0.65482 NA Inf NA 2.1118 10 [0.32506, 1.325] NA 0.32506 NA 1.325 NA 0.8251 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### this is not the same as R(s) because of censoring! > as.numeric(R(s)) [1] 2.6743 1.9578 0.1700 3.0688 0.6563 0.5832 0.2087 2.2957 0.6548 0.8251 > as.double(R(s)) [1] 2.6743 1.9578 0.1700 3.0688 0.6563 0.5832 0.2087 2.2957 0.6548 0.8251 > > R(list(runif(10), rnorm(10))) [1] 0.3621 0.8667 0.3626 0.6659 0.6183 0.9729 0.9823 0.6217 0.3513 [10] 0.4874 1.2770 -0.9917 -1.1177 0.5891 -1.2843 -0.4791 -1.4983 -2.8433 [19] 0.4759 1.1154 > > proc.time() user system elapsed 1.65 0.28 1.93