Skip to content

Commit 6194c04

Browse files
committed
Add left_truncation_y parameter to ppc_km_overlay() and ppc_km_overlay_grouped()
1 parent 4d40ba6 commit 6194c04

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

R/ppc-censoring.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ppc_km_overlay <- function(
7070
yrep,
7171
...,
7272
status_y,
73+
left_truncation_y = NULL,
7374
size = 0.25,
7475
alpha = 0.7
7576
) {
@@ -82,8 +83,20 @@ ppc_km_overlay <- function(
8283
stopifnot(is.numeric(status_y))
8384
stopifnot(all(status_y %in% c(0, 1)))
8485

86+
if (!is.null(left_truncation_y)) {
87+
if (!is.numeric(left_truncation_y) || length(left_truncation_y) != length(y)) {
88+
stop("`left_truncation_y` must be a numeric vector of the same length as `y`.")
89+
}
90+
}
91+
8592
data <- ppc_data(y, yrep, group = status_y)
8693

94+
if (!is.null(left_truncation_y)) {
95+
data$left_trunc <- left_truncation_y[data$y_id]
96+
} else {
97+
data$left_trunc <- 0
98+
}
99+
87100
# Modify the status indicator:
88101
# * For the observed data ("y"), convert the status indicator back to
89102
# a numeric.
@@ -96,7 +109,7 @@ ppc_km_overlay <- function(
96109
as.numeric(as.character(.data$group)),
97110
1))
98111

99-
sf_form <- survival::Surv(value, group) ~ rep_label
112+
sf_form <- survival::Surv(time = data$left_trunc, time2 = data$value, event = data$group) ~ rep_label
100113
if (!is.null(add_group)) {
101114
data <- dplyr::inner_join(data,
102115
tibble::tibble(y_id = seq_along(y),
@@ -164,6 +177,7 @@ ppc_km_overlay_grouped <- function(
164177
group,
165178
...,
166179
status_y,
180+
left_truncation_y = NULL,
167181
size = 0.25,
168182
alpha = 0.7
169183
) {
@@ -175,6 +189,7 @@ ppc_km_overlay_grouped <- function(
175189
add_group = group,
176190
...,
177191
status_y = status_y,
192+
left_truncation_y = left_truncation_y,
178193
size = size,
179194
alpha = alpha
180195
)

0 commit comments

Comments
 (0)