6  Efficacy figure

Following the ICH E3 guidance, primary and secondary efficacy endpoints need to be summarized in Section 11.4, Efficacy Results and Tabulations of Individual Participant.

library(haven) # Read SAS data
library(dplyr) # Manipulate data
library(r2rtf) # Reporting in RTF format
library(survival) # Fit survival model

In this chapter, we illustrate how to create a simplified Kaplan-Meier plot in a study. For the survival analysis in efficacy, time to dermatologic event (TTDE) will be analyzed.

Note

R packages such as visR and survminer can create more informative Kaplan-Meier plots. Interested readers can find examples on their websites.

6.1 Analysis dataset

To prepare the analysis, the adtte dataset is required.

adtte <- read_sas("data-adam/adtte.sas7bdat")

First, to prepare the analysis ready data, filter all records for the efficacy endpoint of time to event of interest (TTDE) using PARAMCD (or PARAM, PRAMN), then select the survival analysis related variables:

  • TRTP: treatment arm (using corresponding numeric code TRTAN to re-order the levels, “Placebo” will be the reference level)
  • AVAL: time-to-event analysis value
  • CNSR: event (censoring) status
adtte_ttde <- adtte %>%
  filter(PARAMCD == "TTDE") %>%
  select(TRTP, TRTAN, AVAL, CNSR) %>%
  mutate(
    TRTP = forcats::fct_reorder(TRTP, TRTAN), # Recorder levels
    AVAL_m = AVAL / 30.4367 # Convert Day to Month
  )

6.2 Create Kaplan-Meier curve

The survival package is used to obtain the K-M estimate.

# Fit survival model, convert the time value from Days to Month
fit <- survfit(Surv(AVAL_m, 1 - CNSR) ~ TRTP, data = adtte_ttde)

We save the simplified K-M plot into a .png file using code below.

# Save as a PNG file
png(
  file = "tlf/fig_km.png",
  width = 3000,
  height = 2000,
  res = 300
)

plot(
  fit,
  xlab = "Time in Months",
  ylab = "Survival probability",
  mark.time = TRUE,
  lwd = 2,
  col = c(2, 3, 4),
  lty = c(1, 2, 3)
)

dev.off()

Now, we can use the r2rtf package to create a formatted RTF figure. More details can be found on the r2rtf website.

# Create RTF figure
rtf_read_figure("tlf/fig_km.png") %>% # Read the PNG file from the file path
  rtf_title(
    "Kaplan-Meier Plot for Time to First Dermatologic Event by Treatment Group",
    "All Participants"
  ) %>% # Add title or subtitle
  rtf_footnote("footnote") %>% # Add footnote
  rtf_source("[datasource: adam-adtte]") %>% # Add data source
  rtf_figure(fig_width = 6, fig_height = 4) %>% # Set proportional figure size to the original PNG figure size
  rtf_encode(doc_type = "figure") %>% # Encode figure as rtf
  write_rtf(file = "tlf/tlf_km.rtf")

In conclusion, the steps to create a K-M plot are as follows.

  • Step 1: Read the data adtte into R.
  • Step 2: Define the analysis-ready dataset. In this example, we define the analysis dataset for the TTDE endpoint adtte_ttde.
  • Step 3: Save figures into png files based on required analysis specification.
  • Step 4: Create RTF output using the r2rtf package.