R Under development (unstable) (2023-08-20 r84995 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 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") > set.seed(29) > > y <- rexp(10) > d <- rep(c(TRUE, FALSE), length = length(y)) > ### right > (s <- Surv(y, d, type = "right")) [1] 2.67433818 1.45783672+ 0.16997763 2.56883009+ 0.65633521 0.08317242+ [7] 0.20866373 1.79566143+ 0.65482017 0.32505510+ > attr(s, "type") [1] "right" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67433818 NA NA 2.6743382 NA NA 2.6743382 2 1.45783672+ NA 1.45783672 NA Inf NA 2.0660874 3 0.16997763 NA NA 0.1699776 NA NA 0.1699776 4 2.56883009+ NA 2.56883009 NA Inf NA 2.6215841 5 0.65633521 NA NA 0.6563352 NA NA 0.6563352 6 0.08317242+ NA 0.08317242 NA Inf NA 1.3787553 7 0.20866373 NA NA 0.2086637 NA NA 0.2086637 8 1.79566143+ NA 1.79566143 NA Inf NA 2.2349998 9 0.65482017 NA NA 0.6548202 NA NA 0.6548202 10 0.32505510+ NA 0.32505510 NA Inf NA 1.4996966 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### right censored, left truncated > (s <- Surv(y, y + 1, d)) [1] (2.67433818,3.674338] (1.45783672,2.457837+] (0.16997763,1.169978] [4] (2.56883009,3.568830+] (0.65633521,1.656335] (0.08317242,1.083172+] [7] (0.20866373,1.208664] (1.79566143,2.795661+] (0.65482017,1.654820] [10] (0.32505510,1.325055+] > attr(s, "type") [1] "counting" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 (2.67433818,3.674338] 2.67433818 NA 3.674338 NA NA 3.674338 2 (1.45783672,2.457837+] 1.45783672 2.457837 NA Inf NA 3.066087 3 (0.16997763,1.169978] 0.16997763 NA 1.169978 NA NA 1.169978 4 (2.56883009,3.568830+] 2.56883009 3.568830 NA Inf NA 3.621584 5 (0.65633521,1.656335] 0.65633521 NA 1.656335 NA NA 1.656335 6 (0.08317242,1.083172+] 0.08317242 1.083172 NA Inf NA 2.378755 7 (0.20866373,1.208664] 0.20866373 NA 1.208664 NA NA 1.208664 8 (1.79566143,2.795661+] 1.79566143 2.795661 NA Inf NA 3.235000 9 (0.65482017,1.654820] 0.65482017 NA 1.654820 NA NA 1.654820 10 (0.32505510,1.325055+] 0.32505510 1.325055 NA Inf NA 2.499697 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### left censored > (s <- Surv(y, d, type = "left")) [1] 2.67433818 1.45783672- 0.16997763 2.56883009- 0.65633521 0.08317242- [7] 0.20866373 1.79566143- 0.65482017 0.32505510- > attr(s, "type") [1] "left" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67433818 NA NA 2.6743382 NA NA 2.67433818 2 1.45783672- NA -Inf NA 1.45783672 NA 0.77050457 3 0.16997763 NA NA 0.1699776 NA NA 0.16997763 4 2.56883009- NA -Inf NA 2.56883009 NA 1.32600125 5 0.65633521 NA NA 0.6563352 NA NA 0.65633521 6 0.08317242- NA -Inf NA 0.08317242 NA 0.08317242 7 0.20866373 NA NA 0.2086637 NA NA 0.20866373 8 1.79566143- NA -Inf NA 1.79566143 NA 0.93941693 9 0.65482017 NA NA 0.6548202 NA NA 0.65482017 10 0.32505510- NA -Inf NA 0.32505510 NA 0.20411376 > 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.67433818+ 1.45783672 0.16997763- [4] [2.56883009, 3.568830] 0.65633521+ 0.08317242 [7] 0.20866373- [1.79566143, 2.795661] 0.65482017+ [10] 0.32505510 > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright 1 2.67433818+ NA 2.6743382 NA Inf NA 2 1.45783672 NA NA 1.45783672 NA NA 3 0.16997763- NA -Inf NA 0.1699776 NA 4 [2.56883009, 3.568830] NA 2.5688301 NA 3.5688301 NA 5 0.65633521+ NA 0.6563352 NA Inf NA 6 0.08317242 NA NA 0.08317242 NA NA 7 0.20866373- NA -Inf NA 0.2086637 NA 8 [1.79566143, 2.795661] NA 1.7956614 NA 2.7956614 NA 9 0.65482017+ NA 0.6548202 NA Inf NA 10 0.32505510 NA NA 0.32505510 NA NA approxy 1 3.12158413 2 1.45783672 3 0.12657503 4 3.06883009 5 2.11258265 6 0.08317242 7 0.14591808 8 2.29566143 9 2.11182513 10 0.32505510 > stopifnot(all.equal(s, as.Surv(R(s)))) > > ### interval2 > (s <- Surv(y, y + 1, type = "interval2")) [1] [2.67433818, 3.674338] [1.45783672, 2.457837] [0.16997763, 1.169978] [4] [2.56883009, 3.568830] [0.65633521, 1.656335] [0.08317242, 1.083172] [7] [0.20866373, 1.208664] [1.79566143, 2.795661] [0.65482017, 1.654820] [10] [0.32505510, 1.325055] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 [2.67433818, 3.674338] NA 2.67433818 NA 3.674338 NA 3.1743382 2 [1.45783672, 2.457837] NA 1.45783672 NA 2.457837 NA 1.9578367 3 [0.16997763, 1.169978] NA 0.16997763 NA 1.169978 NA 0.6699776 4 [2.56883009, 3.568830] NA 2.56883009 NA 3.568830 NA 3.0688301 5 [0.65633521, 1.656335] NA 0.65633521 NA 1.656335 NA 1.1563352 6 [0.08317242, 1.083172] NA 0.08317242 NA 1.083172 NA 0.5831724 7 [0.20866373, 1.208664] NA 0.20866373 NA 1.208664 NA 0.7086637 8 [1.79566143, 2.795661] NA 1.79566143 NA 2.795661 NA 2.2956614 9 [0.65482017, 1.654820] NA 0.65482017 NA 1.654820 NA 1.1548202 10 [0.32505510, 1.325055] NA 0.32505510 NA 1.325055 NA 0.8250551 > stopifnot(all.equal(s, as.Surv(R(s)))) > > (s <- Surv(y, ifelse(d, Inf, y + 1), type = "interval2")) [1] 2.67433818+ [1.45783672, 2.457837] 0.16997763+ [4] [2.56883009, 3.568830] 0.65633521+ [0.08317242, 1.083172] [7] 0.20866373+ [1.79566143, 2.795661] 0.65482017+ [10] [0.32505510, 1.325055] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67433818+ NA 2.67433818 NA Inf NA 3.1215841 2 [1.45783672, 2.457837] NA 1.45783672 NA 2.457837 NA 1.9578367 3 0.16997763+ NA 0.16997763 NA Inf NA 1.8694039 4 [2.56883009, 3.568830] NA 2.56883009 NA 3.568830 NA 3.0688301 5 0.65633521+ NA 0.65633521 NA Inf NA 2.1125826 6 [0.08317242, 1.083172] NA 0.08317242 NA 1.083172 NA 0.5831724 7 0.20866373+ NA 0.20866373 NA Inf NA 1.8887469 8 [1.79566143, 2.795661] NA 1.79566143 NA 2.795661 NA 2.2956614 9 0.65482017+ NA 0.65482017 NA Inf NA 2.1118251 10 [0.32505510, 1.325055] NA 0.32505510 NA 1.325055 NA 0.8250551 > stopifnot(all.equal(s, as.Surv(R(s)))) > > (s <- Surv(y, ifelse(d, NA, y + 1), type = "interval2")) [1] 2.67433818+ [1.45783672, 2.457837] 0.16997763+ [4] [2.56883009, 3.568830] 0.65633521+ [0.08317242, 1.083172] [7] 0.20866373+ [1.79566143, 2.795661] 0.65482017+ [10] [0.32505510, 1.325055] > attr(s, "type") [1] "interval" > cbind(s, R(s)) s tleft cleft exact cright tright approxy 1 2.67433818+ NA 2.67433818 NA Inf NA 3.1215841 2 [1.45783672, 2.457837] NA 1.45783672 NA 2.457837 NA 1.9578367 3 0.16997763+ NA 0.16997763 NA Inf NA 1.8694039 4 [2.56883009, 3.568830] NA 2.56883009 NA 3.568830 NA 3.0688301 5 0.65633521+ NA 0.65633521 NA Inf NA 2.1125826 6 [0.08317242, 1.083172] NA 0.08317242 NA 1.083172 NA 0.5831724 7 0.20866373+ NA 0.20866373 NA Inf NA 1.8887469 8 [1.79566143, 2.795661] NA 1.79566143 NA 2.795661 NA 2.2956614 9 0.65482017+ NA 0.65482017 NA Inf NA 2.1118251 10 [0.32505510, 1.325055] NA 0.32505510 NA 1.325055 NA 0.8250551 > 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.6743382 1.9578367 0.1699776 3.0688301 0.6563352 0.5831724 0.2086637 [8] 2.2956614 0.6548202 0.8250551 > as.double(R(s)) [1] 2.6743382 1.9578367 0.1699776 3.0688301 0.6563352 0.5831724 0.2086637 [8] 2.2956614 0.6548202 0.8250551 > > R(list(runif(10), rnorm(10))) [1] 0.3621201 0.8667453 0.3626263 0.6658932 0.6183130 0.9728763 [7] 0.9823095 0.6216898 0.3513491 0.4874011 1.2770250 -0.9917289 [13] -1.1176913 0.5891399 -1.2842866 -0.4791048 -1.4982747 -2.8433133 [19] 0.4758929 1.1153928 > > proc.time() user system elapsed 1.67 0.20 1.85