24
24
# ' @section Plot Descriptions:
25
25
# ' \describe{
26
26
# ' \item{`ppc_km_overlay()`}{
27
- # ' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid,
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.
27
+ # ' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, with
28
+ # ' the Kaplan-Meier estimate (Kaplan and Meier, 1958) for `y` itself on top
29
+ # ' (and in a darker shade). This is a PPC suitable for right-censored `y`.
30
+ # ' Note that the replicated data from `yrep` is assumed to be uncensored. Left
31
+ # ' truncation (delayed entry) times for `y` can be specified using
32
+ # ' `left_truncation_y`.
32
33
# ' }
33
34
# ' \item{`ppc_km_overlay_grouped()`}{
34
35
# ' The same as `ppc_km_overlay()`, but with separate facets by `group`.
40
41
# ' @template reference-km
41
42
# '
42
43
# ' @examples
44
+ # ' \donttest{
43
45
# ' color_scheme_set("brightblue")
44
- # ' y <- example_y_data()
46
+ # '
45
47
# ' # For illustrative purposes, (right-)censor values y > 110:
48
+ # ' y <- example_y_data()
46
49
# ' status_y <- as.numeric(y <= 110)
47
50
# ' y <- pmin(y, 110)
51
+ # '
48
52
# ' # In reality, the replicated data (yrep) would be obtained from a
49
53
# ' # model which takes the censoring of y properly into account. Here,
50
54
# ' # for illustrative purposes, we simply use example_yrep_draws():
51
55
# ' yrep <- example_yrep_draws()
52
56
# ' dim(yrep)
53
- # ' \donttest{
57
+ # '
58
+ # ' # Overlay 25 curves
54
59
# ' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y)
55
- # ' }
60
+ # '
56
61
# ' # With extrapolation_factor = 1 (no extrapolation)
57
- # ' \donttest{
58
62
# ' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y, extrapolation_factor = 1)
59
- # ' }
63
+ # '
60
64
# ' # With extrapolation_factor = Inf (show all posterior predictive draws)
61
- # ' \donttest{
62
65
# ' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y, extrapolation_factor = Inf)
63
- # ' }
66
+ # '
64
67
# ' # With separate facets by group:
65
68
# ' group <- example_group_data()
66
- # ' \donttest{
67
69
# ' ppc_km_overlay_grouped(y, yrep[1:25, ], group = group, status_y = status_y)
68
- # ' }
70
+ # '
69
71
# ' # With left-truncation (delayed entry) times:
70
72
# ' min_vals <- pmin(y, apply(yrep, 2, min))
71
73
# ' left_truncation_y <- rep(0, length(y))
74
76
# ' runif(sum(condition), min = 0.6, max = 0.99) * y[condition],
75
77
# ' min_vals[condition] - 0.001
76
78
# ' )
77
- # ' \donttest{
78
79
# ' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y,
79
80
# ' left_truncation_y = left_truncation_y)
80
81
# ' }
@@ -102,9 +103,9 @@ ppc_km_overlay <- function(
102
103
... ,
103
104
status_y ,
104
105
left_truncation_y = NULL ,
106
+ extrapolation_factor = 1.2 ,
105
107
size = 0.25 ,
106
- alpha = 0.7 ,
107
- extrapolation_factor = 1.2
108
+ alpha = 0.7
108
109
) {
109
110
check_ignored_arguments(... , ok_args = " add_group" )
110
111
add_group <- list (... )$ add_group
@@ -113,17 +114,23 @@ ppc_km_overlay <- function(
113
114
suggested_package(" ggfortify" )
114
115
115
116
if (! is.numeric(status_y ) || length(status_y ) != length(y ) || ! all(status_y %in% c(0 , 1 ))) {
116
- stop(" `status_y` must be a numeric vector of 0s and 1s the same length as `y`." )
117
+ stop(" `status_y` must be a numeric vector of 0s and 1s the same length as `y`." , call. = FALSE )
117
118
}
118
119
119
120
if (! is.null(left_truncation_y )) {
120
121
if (! is.numeric(left_truncation_y ) || length(left_truncation_y ) != length(y )) {
121
- stop(" `left_truncation_y` must be a numeric vector of the same length as `y`." )
122
+ stop(" `left_truncation_y` must be a numeric vector of the same length as `y`." , call. = FALSE )
122
123
}
123
124
}
124
125
125
126
if (extrapolation_factor < 1 ) {
126
- stop(" `extrapolation_factor` must be greater than or equal to 1." )
127
+ stop(" `extrapolation_factor` must be greater than or equal to 1." , call. = FALSE )
128
+ }
129
+ if (extrapolation_factor == 1.2 ) {
130
+ message(
131
+ " Note: `extrapolation_factor` now defaults to 1.2 (20%).\n " ,
132
+ " To display all posterior predictive draws, set `extrapolation_factor = Inf`."
133
+ )
127
134
}
128
135
129
136
data <- ppc_data(y , yrep , group = status_y )
@@ -218,9 +225,9 @@ ppc_km_overlay_grouped <- function(
218
225
... ,
219
226
status_y ,
220
227
left_truncation_y = NULL ,
228
+ extrapolation_factor = 1.2 ,
221
229
size = 0.25 ,
222
- alpha = 0.7 ,
223
- extrapolation_factor = 1.2
230
+ alpha = 0.7
224
231
) {
225
232
check_ignored_arguments(... )
226
233
0 commit comments