Is the New Treatment Safer — or Are Patients Simply Stopping It Earlier?
A time-to-event analysis with competing risks
A pharmaceutical company has completed a randomized study comparing an experimental therapy with standard of care in patients with a chronic inflammatory disease. The clinical team is concerned about peripheral neuropathy, an adverse event that may develop with prolonged treatment exposure. Initial summaries suggest fewer neuropathy events in the experimental arm. The team asks whether this means the new therapy has a more favorable neuropathy safety profile. Not every patient remains on randomized treatment. Some permanently discontinue treatment for reasons including tolerability, lack of efficacy, and patient preference. The study captures the first occurrence of neuropathy, permanent discontinuation, or the end of available follow-up.
Using visualization as your primary tool, explore whether the observed neuropathy results support the proposed safety claim. What additional questions arise from the way follow-up and treatment discontinuation are recorded?
Deliverable: up to three visualizations plus a short commentary (approximately 250–500 words) describing your key discoveries, assumptions, and limitations. Any statistical software is welcome. The challenge is open and free to participate.
The accompanying Excel workbook is provided in Excel format. contains 300 simulated randomized patients (150 per treatment arm). Each record is one patient. Variables include treatment, age, sex, baseline severity, prior neurotoxic exposure, follow-up time, first-event code and label, discontinuation reason, and administrative follow-up duration. See the Data dictionary worksheet for definitions. Event coding: 0 = no event observed (censored); 1 = neuropathy; 2 = permanent treatment discontinuation before neuropathy. Times are in months. The dataset does not systematically record neuropathy after discontinuation. All records are synthetic and are not evidence about a real treatment.
data2 <- data %>%
group_by(treatment, first_event_label) %>%
summarise(count = n()) %>%
mutate(percent = count/sum(count))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by treatment and first_event_label.
## ℹ Output is grouped by treatment.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(treatment, first_event_label))` for per-operation
## grouping (`?dplyr::dplyr_by`) instead.
data2$first_event_label <- factor(data2$first_event_label, levels = c("No event observed", "Neuropathy", "Permanent treatment discontinuation"))
ggplot(data = data2, aes(x = treatment, y = percent)) +
geom_bar(aes(fill = first_event_label), colour = "black", stat = "identity") +
scale_fill_discrete_qualitative(palette = "Harmonic") +
labs(title = "Distribution of first events by treatment",
x = "Treatment",
y = "Proportion of participants",
fill = "Event") +
theme_classic()
In the Standard-of-care group, more participants were able to complete the expected follow-up period without an event observed, which suggests that neuropathy and premature discontinuations affected smaller proportion of participants in this group.
dt1 <- data[data$first_event_code %in% c(0, 1),]
dt1$cnsr <- ifelse(dt1$first_event_code == 0, 0, 1)
km1 <- survfit(Surv(time=followup_months, event=cnsr) ~ treatment, data = dt1)
dt2 <- data[data$first_event_code %in% c(0, 2),]
dt2$cnsr <- ifelse(dt2$first_event_code == 0, 0, 1)
km2 <- survfit(Surv(time=followup_months, event=cnsr) ~ treatment, data = dt2)
p1 <- ggsurvplot(km1,
data = dt1,
fun = 'event',
surv.scale = 'percent',
break.time.by = 1,
conf.int = FALSE,
risk.table = TRUE,
cumevents = TRUE,
cumcensor = TRUE)
p2 <- ggsurvplot(km2,
data = dt2,
fun = 'event',
surv.scale = 'percent',
break.time.by = 1,
conf.int = FALSE,
risk.table = TRUE,
cumevents = TRUE,
cumcensor = TRUE)
kmdata1 <- p1$data.survplot
risktable1 <- p1$data.survtable
kmdata2 <- p2$data.survplot
risktable2 <- p2$data.survtable
# Naive 1 - KM curves
kmplot1 <- ggplot(data = kmdata1[kmdata1$time <= 18, ], aes(x = time, y = 100*(1-surv), color = treatment)) +
geom_line() +
labs(x = "Time (months)", y = "Cumulative Incidence (%)", title = "Naive 1 - KM curves for neuropathy by treatment") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
scale_y_continuous(limits = c(0, 100)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(axis.text.x = element_text(hjust = 1),
legend.position = 'bottom', legend.title = element_blank())
kmplot2 <- ggplot(data = kmdata2[kmdata2$time <= 18, ], aes(x = time, y = 100*(1-surv), color = treatment)) +
geom_line() +
labs(x = "Time (months)", y = "Cumulative Incidence (%)", title = "Naive 1 - KM curves for premature discontinuation by treatment") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
scale_y_continuous(limits = c(0, 100)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(axis.text.x = element_text(hjust = 1),
legend.position = 'bottom', legend.title = element_blank())
# Risk Tables
rt1 <- ggplot(data = risktable1[risktable1$time <= 18, ], aes(x = time, y = treatment, label = n.risk, color = treatment)) +
geom_text(size = 3) +
labs(x = NULL, y = "", colour = "") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
annotate("text", x = 1, y = 3.5, label = "Participants at risk:", size = 3) +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(legend.position = 'none', legend.title = element_blank())
rt2 <- ggplot(data = risktable2[risktable2$time <= 18, ], aes(x = time, y = treatment, label = n.risk, color = treatment)) +
geom_text(size = 3) +
labs(x = NULL, y = "", colour = "") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
annotate("text", x = 1, y = 3.5, label = "Participants at risk:", size = 3) +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(legend.position = 'none', legend.title = element_blank())
# Number of cases
cases1 <- ggplot(data = risktable1[risktable1$time <= 18, ], aes(x = time, y = treatment, label = cum.n.event, color = treatment)) +
geom_text(size = 3) +
labs(x = NULL, y = "", colour = "") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
annotate("text", x = 1, y = 3.5, label = "Number of cases:", size = 3) +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(legend.position = 'none', legend.title = element_blank())
cases2 <- ggplot(data = risktable2[risktable2$time <= 18, ], aes(x = time, y = treatment, label = cum.n.event, color = treatment)) +
geom_text(size = 3) +
labs(x = NULL, y = "", colour = "") +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
theme_classic() +
coord_cartesian(xlim = c(0, 18), clip = "off") +
annotate("text", x = 1, y = 3.5, label = "Number of cases:", size = 3) +
scale_color_manual(values = c("Experimental" = "#00AD9A", "Standard of care" = "#E16A86")) +
theme(legend.position = 'none', legend.title = element_blank())
plot_grid(kmplot1, rt1, cases1, ncol=1, align='v', rel_heights = c(1, 0.3, 0.3))
plot_grid(kmplot2, rt2, cases2, ncol=1, align='v', rel_heights = c(1, 0.3, 0.3))
ggplot(data = na.omit(data), aes(x = discontinuation_reason, fill = treatment)) +
geom_bar(stat = "count", position = "dodge", colour = "black") +
labs(x = "Reason for premature discontinuation",
y = "Number of participants",
fill = "Treatment",
title = "Reasons for permanent discontinuation by treatment") +
scale_fill_discrete_qualitative(palette = "Dark 3") +
theme_classic() +
theme(legend.position = "bottom", legend.title = element_blank())
# Aalen–Johansen cumulative incidence curves
cif <- cmprsk::cuminc(
ftime = data$followup_months,
fstatus = data$first_event_code,
group = data$treatment_n,
cencode = 0
)
plot <-
ggcompetingrisks(
fit = cif,
risk.table = TRUE,
break.time.by = 1,
multiple_panels = FALSE) +
labs(x = "Time (months)",
y = "Cumulative incidence",
title = "Cumulative incidence of neuropathy and premature discontinuation by treatment",
linetype = "Event",
color = "Treatment") +
scale_linetype_manual(values = c("1" = "solid", "2" = "dashed"),
labels = c("1" = "Neuropathy", "2" = "Premature discontinuation")) +
scale_color_manual(values = c("1" = "#00AD9A", "2" = "#E16A86"),
labels = c("1" = "Experimental", "2" = "Standard of care")) +
theme_classic() +
scale_x_continuous(breaks = seq(0, 18, by = 1)) +
scale_y_continuous(limits = c(0, 0.8), breaks = seq(0, 1, by = 0.1)) +
theme(legend.position = "right")
plot
# CIF vs 1-KM plots