Skip to content

Commit e5221f0

Browse files
committed
Add extrapolation_factor parameter to ppc_km_overlay and ppc_km_overlay_grouped
1 parent 23e00b5 commit e5221f0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

R/ppc-censoring.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ ppc_km_overlay <- function(
8888
status_y,
8989
left_truncation_y = NULL,
9090
size = 0.25,
91-
alpha = 0.7
91+
alpha = 0.7,
92+
extrapolation_factor = 1.2
9293
) {
9394
check_ignored_arguments(..., ok_args = "add_group")
9495
add_group <- list(...)$add_group
@@ -106,6 +107,10 @@ ppc_km_overlay <- function(
106107
}
107108
}
108109

110+
if (extrapolation_factor < 1) {
111+
stop("`extrapolation_factor` must be greater than or equal to 1.")
112+
}
113+
109114
data <- ppc_data(y, yrep, group = status_y)
110115

111116
# Modify the status indicator:
@@ -149,6 +154,10 @@ ppc_km_overlay <- function(
149154
fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1)
150155
fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1)
151156

157+
max_time_y <- max(y, na.rm = TRUE)
158+
fsf <- fsf %>%
159+
dplyr::filter(is_y_color != "yrep" | time <= max_time_y * extrapolation_factor)
160+
152161
# Ensure that the observed data gets plotted last by reordering the
153162
# levels of the factor "strata"
154163
fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata)))

0 commit comments

Comments
 (0)