55# ' predictive distribution. See the **Plot Descriptions** section, below, for
66# ' details.
77# '
8- # ' Although some of the other plots can be used with censored data,
9- # ' `ppc_km_overlay()` is currently the only plotting function designed
8+ # ' Although some of the other \pkg{bayesplot} plots can be used with censored
9+ # ' data, `ppc_km_overlay()` is currently the only plotting function designed
1010# ' *specifically* for censored data. We encourage you to suggest or contribute
11- # ' additional plots at [https://github.com/stan-dev/bayesplot](github.com/stan-dev/bayesplot).
12- # '
13- # '
11+ # ' additional plots at
12+ # ' [https://github.com/stan-dev/bayesplot](github.com/stan-dev/bayesplot).
1413# '
1514# ' @name PPC-censoring
1615# ' @family PPCs
2625# ' \describe{
2726# ' \item{`ppc_km_overlay()`}{
2827# ' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid,
29- # ' with the Kaplan-Meier estimate (Kaplan and Meier, 1958) for `y` itself
30- # ' on top (and in a darker shade). This is a PPC suitable for
31- # ' right-censored `y`. Note that the replicated data from `yrep` is assumed
32- # ' to be uncensored.
28+ # ' with the Kaplan-Meier estimate (Kaplan and Meier, 1958) for `y` itself on
29+ # ' top (and in a darker shade). This is a PPC suitable for right-censored
30+ # ' `y`. Note that the replicated data from `yrep` is assumed to be
31+ # ' uncensored.
3332# ' }
3433# ' }
3534# '
@@ -74,11 +73,9 @@ ppc_km_overlay <-
7473 abort(" Package 'ggfortify' required." )
7574 }
7675
77- # Checks for 'status_y':
7876 stopifnot(is.numeric(status_y ))
7977 stopifnot(all(status_y %in% c(0 , 1 )))
8078
81- # Create basic PPC dataset:
8279 data <- ppc_data(y , yrep , group = status_y )
8380
8481 # Modify the status indicator:
@@ -93,23 +90,20 @@ ppc_km_overlay <-
9390 as.numeric(as.character(.data $ group )),
9491 1 ))
9592
96- # Create 'survfit' object and 'fortify' it
9793 sf <- survival :: survfit(
9894 survival :: Surv(value , group ) ~ rep_label ,
9995 data = data
10096 )
10197 fsf <- fortify(sf )
10298
103- # Add variables specifying color, size, and alpha:
10499 fsf $ is_y_color <- as.factor(sub(" \\ [rep\\ ] \\ (.*$" , " rep" , sub(" ^italic\\ (y\\ )" , " y" , fsf $ strata )))
105100 fsf $ is_y_size <- ifelse(fsf $ is_y_color == " yrep" , size , 1 )
106101 fsf $ is_y_alpha <- ifelse(fsf $ is_y_color == " yrep" , alpha , 1 )
107102
108103 # Ensure that the observed data gets plotted last by reordering the
109- # levels of the factor "strata":
104+ # levels of the factor "strata"
110105 fsf $ strata <- factor (fsf $ strata , levels = rev(levels(fsf $ strata )))
111106
112- # Plot:
113107 ggplot(data = fsf ,
114108 mapping = aes_(x = ~ time ,
115109 y = ~ surv ,
0 commit comments