Skip to content

Commit 81b4dfe

Browse files
committed
Make ppc_km_overlay()'s indentation match that of similar functions.
1 parent ecb1676 commit 81b4dfe

File tree

1 file changed

+64
-63
lines changed

1 file changed

+64
-63
lines changed

R/ppc-censoring.R

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -57,74 +57,75 @@ NULL
5757
#' @param status_y The status indicator for the observations from `y`. This must
5858
#' be a numeric vector of the same length as `y` with values in \{0, 1\} (0 =
5959
#' right censored, 1 = event).
60-
ppc_km_overlay <-
61-
function(y,
62-
yrep,
63-
...,
64-
status_y,
65-
size = 0.25,
66-
alpha = 0.7) {
67-
check_ignored_arguments(...)
60+
ppc_km_overlay <- function(
61+
y,
62+
yrep,
63+
...,
64+
status_y,
65+
size = 0.25,
66+
alpha = 0.7
67+
) {
68+
check_ignored_arguments(...)
6869

69-
if(!requireNamespace("survival", quietly = TRUE)){
70-
abort("Package 'survival' required.")
71-
}
72-
if(!requireNamespace("ggfortify", quietly = TRUE)){
73-
abort("Package 'ggfortify' required.")
74-
}
70+
if(!requireNamespace("survival", quietly = TRUE)){
71+
abort("Package 'survival' required.")
72+
}
73+
if(!requireNamespace("ggfortify", quietly = TRUE)){
74+
abort("Package 'ggfortify' required.")
75+
}
7576

76-
stopifnot(is.numeric(status_y))
77-
stopifnot(all(status_y %in% c(0, 1)))
77+
stopifnot(is.numeric(status_y))
78+
stopifnot(all(status_y %in% c(0, 1)))
7879

79-
data <- ppc_data(y, yrep, group = status_y)
80+
data <- ppc_data(y, yrep, group = status_y)
8081

81-
# Modify the status indicator:
82-
# * For the observed data ("y"), convert the status indicator back to
83-
# a numeric.
84-
# * For the replicated data ("yrep"), set the status indicator
85-
# to 1 ("event"). This way, the Kaplan-Meier estimator reduces
86-
# to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative
87-
# distribution function.
88-
data <- data %>%
89-
dplyr::mutate(group = ifelse(.data$is_y,
90-
as.numeric(as.character(.data$group)),
91-
1))
82+
# Modify the status indicator:
83+
# * For the observed data ("y"), convert the status indicator back to
84+
# a numeric.
85+
# * For the replicated data ("yrep"), set the status indicator
86+
# to 1 ("event"). This way, the Kaplan-Meier estimator reduces
87+
# to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative
88+
# distribution function.
89+
data <- data %>%
90+
dplyr::mutate(group = ifelse(.data$is_y,
91+
as.numeric(as.character(.data$group)),
92+
1))
9293

93-
sf <- survival::survfit(
94-
survival::Surv(value, group) ~ rep_label,
95-
data = data
96-
)
97-
fsf <- fortify(sf)
94+
sf <- survival::survfit(
95+
survival::Surv(value, group) ~ rep_label,
96+
data = data
97+
)
98+
fsf <- fortify(sf)
9899

99-
fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata)))
100-
fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1)
101-
fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1)
100+
fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata)))
101+
fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1)
102+
fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1)
102103

103-
# Ensure that the observed data gets plotted last by reordering the
104-
# levels of the factor "strata"
105-
fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata)))
104+
# Ensure that the observed data gets plotted last by reordering the
105+
# levels of the factor "strata"
106+
fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata)))
106107

107-
ggplot(data = fsf,
108-
mapping = aes_(x = ~ time,
109-
y = ~ surv,
110-
color = ~ is_y_color,
111-
group = ~ strata,
112-
size = ~ is_y_size,
113-
alpha = ~ is_y_alpha)) +
114-
geom_step() +
115-
hline_at(
116-
c(0, 0.5, 1),
117-
size = c(0.2, 0.1, 0.2),
118-
linetype = 2,
119-
color = get_color("dh")
120-
) +
121-
scale_size_identity() +
122-
scale_alpha_identity() +
123-
scale_color_ppc_dist() +
124-
scale_y_continuous(breaks = c(0, 0.5, 1)) +
125-
xlab(y_label()) +
126-
yaxis_title(FALSE) +
127-
xaxis_title(FALSE) +
128-
yaxis_ticks(FALSE) +
129-
bayesplot_theme_get()
130-
}
108+
ggplot(data = fsf,
109+
mapping = aes_(x = ~ time,
110+
y = ~ surv,
111+
color = ~ is_y_color,
112+
group = ~ strata,
113+
size = ~ is_y_size,
114+
alpha = ~ is_y_alpha)) +
115+
geom_step() +
116+
hline_at(
117+
c(0, 0.5, 1),
118+
size = c(0.2, 0.1, 0.2),
119+
linetype = 2,
120+
color = get_color("dh")
121+
) +
122+
scale_size_identity() +
123+
scale_alpha_identity() +
124+
scale_color_ppc_dist() +
125+
scale_y_continuous(breaks = c(0, 0.5, 1)) +
126+
xlab(y_label()) +
127+
yaxis_title(FALSE) +
128+
xaxis_title(FALSE) +
129+
yaxis_ticks(FALSE) +
130+
bayesplot_theme_get()
131+
}

0 commit comments

Comments
 (0)