5  Efficacy table

Following 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(tidyr) # Manipulate data
library(r2rtf) # Reporting in RTF format
library(emmeans) # LS mean estimation

In this chapter, we illustrate how to generate an efficacy table for a study. For efficacy analysis, only the change from baseline glucose data at week 24 is analyzed.

5.1 Analysis dataset

To prepare the analysis, both adsl and adlbc datasets are required.

adsl <- read_sas("data-adam/adsl.sas7bdat")
adlb <- read_sas("data-adam/adlbc.sas7bdat")

First, both the population and the data in scope are selected. The analysis is done on the efficacy population, identified by EFFFL == "Y", and all records post baseline (AVISITN >= 1) and on or before Week 24 (AVISITN <= 24). Here the variable AVISITN is the numerical analysis visit. For example, if the analysis visit is recorded as “Baseline” (i.e., AVISIT = Baseline), AVISITN = 0; if the analysis visit is recorded as “Week 24” (i.e., AVISIT = Week 24), AVISITN = 24; if the analysis visit is blank, AVISITN is also blank. We will discuss these missing values in Section 6.4.

gluc <- adlb %>%
  left_join(adsl %>% select(USUBJID, EFFFL), by = "USUBJID") %>%
  # PARAMCD is parameter code and here we focus on Glucose (mg/dL)
  filter(EFFFL == "Y" & PARAMCD == "GLUC") %>%
  arrange(TRTPN) %>%
  mutate(TRTP = factor(TRTP, levels = unique(TRTP)))

ana <- gluc %>%
  filter(AVISITN > 0 & AVISITN <= 24) %>%
  arrange(AVISITN) %>%
  mutate(AVISIT = factor(AVISIT, levels = unique(AVISIT)))

Below is the first few records of the analysis dataset.

  • AVAL: analysis value
  • BASE: baseline value
  • CHG: change from baseline
ana %>% select(USUBJID, TRTPN, AVISIT, AVAL, BASE, CHG)
#> # A tibble: 1,377 × 6
#>   USUBJID     TRTPN AVISIT              AVAL  BASE     CHG
#>   <chr>       <dbl> <fct>              <dbl> <dbl>   <dbl>
#> 1 01-701-1015     0 "          Week 2"  4.66  4.72 -0.0555
#> 2 01-701-1023     0 "          Week 2"  5.77  5.33  0.444 
#> 3 01-701-1047     0 "          Week 2"  5.55  5.55  0     
#> 4 01-701-1118     0 "          Week 2"  4.88  4.05  0.833 
#> # ℹ 1,373 more rows

5.2 Helper functions

To prepare the report, we create a few helper functions by using the fmt_num() function defined in Chapter 3.

  • Format estimators
fmt_num <- function(x, digits, width = digits + 4) {
  formatC(
    x,
    digits = digits,
    format = "f",
    width = width
  )
}
fmt_est <- function(.mean,
                    .sd,
                    digits = c(1, 2)) {
  .mean <- fmt_num(.mean, digits[1], width = digits[1] + 4)
  .sd <- fmt_num(.sd, digits[2], width = digits[2] + 3)
  paste0(.mean, " (", .sd, ")")
}
  • Format confidence interval
fmt_ci <- function(.est,
                   .lower,
                   .upper,
                   digits = 2,
                   width = digits + 3) {
  .est <- fmt_num(.est, digits, width)
  .lower <- fmt_num(.lower, digits, width)
  .upper <- fmt_num(.upper, digits, width)
  paste0(.est, " (", .lower, ",", .upper, ")")
}
  • Format p-value
fmt_pval <- function(.p, digits = 3) {
  scale <- 10^(-1 * digits)
  p_scale <- paste0("<", digits)
  if_else(.p < scale, p_scale, fmt_num(.p, digits = digits))
}

5.3 Summary of observed data

First the observed data at Baseline and Week 24 are summarized using code below:

t11 <- gluc %>%
  filter(AVISITN %in% c(0, 24)) %>%
  group_by(TRTPN, TRTP, AVISITN) %>%
  summarise(
    n = n(),
    mean_sd = fmt_est(mean(AVAL), sd(AVAL))
  ) %>%
  pivot_wider(
    id_cols = c(TRTP, TRTPN),
    names_from = AVISITN,
    values_from = c(n, mean_sd)
  )

t11
#> # A tibble: 3 × 6
#> # Groups:   TRTPN, TRTP [3]
#>   TRTP                 TRTPN   n_0  n_24 mean_sd_0       mean_sd_24     
#>   <fct>                <dbl> <int> <int> <chr>           <chr>          
#> 1 Placebo                  0    79    57 "  5.7 ( 2.23)" "  5.7 ( 1.83)"
#> 2 Xanomeline Low Dose     54    79    26 "  5.4 ( 0.95)" "  5.7 ( 1.26)"
#> 3 Xanomeline High Dose    81    74    30 "  5.4 ( 1.37)" "  6.0 ( 1.92)"

Also the observed change from baseline glucose at Week 24 is summarized using code below:

t12 <- gluc %>%
  filter(AVISITN %in% 24) %>%
  group_by(TRTPN, AVISITN) %>%
  summarise(
    n_chg = n(),
    mean_chg = fmt_est(
      mean(CHG, na.rm = TRUE),
      sd(CHG, na.rm = TRUE)
    )
  )

t12
#> # A tibble: 3 × 4
#> # Groups:   TRTPN [3]
#>   TRTPN AVISITN n_chg mean_chg       
#>   <dbl>   <dbl> <int> <chr>          
#> 1     0      24    57 " -0.1 ( 2.68)"
#> 2    54      24    26 "  0.2 ( 0.82)"
#> 3    81      24    30 "  0.5 ( 1.94)"

5.4 Missing data imputation

In clinical trials, missing data is inevitable. In this study, there are missing values in glucose data.

count(ana, AVISIT)
#> # A tibble: 8 × 2
#>   AVISIT                 n
#>   <fct>              <int>
#> 1 "          Week 2"   229
#> 2 "          Week 4"   211
#> 3 "          Week 6"   197
#> 4 "          Week 8"   187
#> # ℹ 4 more rows

For simplicity and illustration purpose, we use the last observation carried forward (LOCF) approach to handle missing data. LOCF approach is a single imputation approach that is not recommended in real application. Interested readers can find more discussion on missing data approaches in the book: The Prevention and Treatment of Missing Data in Clinical Trials.

ana_locf <- ana %>%
  group_by(USUBJID) %>%
  mutate(locf = AVISITN == max(AVISITN)) %>%
  filter(locf)

5.5 ANCOVA model

The imputed data is analyzed using the ANCOVA model with treatment and baseline glucose as covariates.

fit <- lm(CHG ~ BASE + TRTP, data = ana_locf)
summary(fit)
#> 
#> Call:
#> lm(formula = CHG ~ BASE + TRTP, data = ana_locf)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -6.9907 -0.7195 -0.2367  0.2422  7.0754 
#> 
#> Coefficients:
#>                          Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)               3.00836    0.39392   7.637 6.23e-13 ***
#> BASE                     -0.53483    0.06267  -8.535 2.06e-15 ***
#> TRTPXanomeline Low Dose  -0.17367    0.24421  -0.711    0.478    
#> TRTPXanomeline High Dose  0.32983    0.24846   1.327    0.186    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 1.527 on 226 degrees of freedom
#>   (2 observations deleted due to missingness)
#> Multiple R-squared:  0.2567, Adjusted R-squared:  0.2468 
#> F-statistic: 26.01 on 3 and 226 DF,  p-value: 1.714e-14

The emmeans R package is used to obtain within and between group least square (LS) mean

fit_within <- emmeans(fit, "TRTP")
fit_within
#>  TRTP                  emmean    SE  df lower.CL upper.CL
#>  Placebo               0.0676 0.172 226   -0.272    0.407
#>  Xanomeline Low Dose  -0.1060 0.173 226   -0.447    0.235
#>  Xanomeline High Dose  0.3975 0.179 226    0.045    0.750
#> 
#> Confidence level used: 0.95
t13 <- fit_within %>%
  as_tibble() %>%
  mutate(ls = fmt_ci(emmean, lower.CL, upper.CL)) %>%
  select(TRTP, ls)
t13
#> # A tibble: 3 × 2
#>   TRTP                 ls                   
#>   <fct>                <chr>                
#> 1 Placebo              " 0.07 (-0.27, 0.41)"
#> 2 Xanomeline Low Dose  "-0.11 (-0.45, 0.23)"
#> 3 Xanomeline High Dose " 0.40 ( 0.05, 0.75)"
fit_between <- pairs(fit_within, reverse = TRUE)
fit_between
#>  contrast                                   estimate    SE  df t.ratio p.value
#>  Xanomeline Low Dose - Placebo                -0.174 0.244 226  -0.711  0.7571
#>  Xanomeline High Dose - Placebo                0.330 0.248 226   1.327  0.3814
#>  Xanomeline High Dose - Xanomeline Low Dose    0.504 0.249 226   2.024  0.1087
#> 
#> P value adjustment: tukey method for comparing a family of 3 estimates
t2 <- fit_between %>%
  as_tibble() %>%
  mutate(
    ls = fmt_ci(
      estimate,
      estimate - 1.96 * SE,
      estimate + 1.96 * SE
    ),
    p = fmt_pval(p.value)
  ) %>%
  filter(stringr::str_detect(contrast, "- Placebo")) %>%
  select(contrast, ls, p)

t2
#> # A tibble: 2 × 3
#>   contrast                       ls                    p        
#>   <chr>                          <chr>                 <chr>    
#> 1 Xanomeline Low Dose - Placebo  "-0.17 (-0.65, 0.30)" "  0.757"
#> 2 Xanomeline High Dose - Placebo " 0.33 (-0.16, 0.82)" "  0.381"

5.6 Reporting

t11, t12 and t13 are combined to get the first part of the report table

t1 <- cbind(
  t11 %>% ungroup() %>% select(TRTP, ends_with("0"), ends_with("24")),
  t12 %>% ungroup() %>% select(ends_with("chg")),
  t13 %>% ungroup() %>% select(ls)
)
t1
#>                   TRTP n_0     mean_sd_0 n_24    mean_sd_24 n_chg      mean_chg
#> 1              Placebo  79   5.7 ( 2.23)   57   5.7 ( 1.83)    57  -0.1 ( 2.68)
#> 2  Xanomeline Low Dose  79   5.4 ( 0.95)   26   5.7 ( 1.26)    26   0.2 ( 0.82)
#> 3 Xanomeline High Dose  74   5.4 ( 1.37)   30   6.0 ( 1.92)    30   0.5 ( 1.94)
#>                    ls
#> 1  0.07 (-0.27, 0.41)
#> 2 -0.11 (-0.45, 0.23)
#> 3  0.40 ( 0.05, 0.75)

Then r2rtf is used to prepare the table format for t1. We also highlight how to handle special characters in this example.

Special characters ^ and _ are used to define superscript and subscript of text. And {} is to define the part that will be impacted. For example, {^a} provides a superscript a for footnote notation. r2rtf also supports most LaTeX characters. Examples can be found on the r2rtf get started page. The text_convert argument in r2rtf_*() functions controls whether to convert special characters.

t1_rtf <- t1 %>%
  data.frame() %>%
  rtf_title(c(
    "ANCOVA of Change from Baseline Glucose (mmol/L) at Week 24",
    "LOCF",
    "Efficacy Analysis Population"
  )) %>%
  rtf_colheader("| Baseline | Week 24 | Change from Baseline",
    col_rel_width = c(2.5, 2, 2, 4)
  ) %>%
  rtf_colheader(
    paste(
      "Treatment |",
      paste0(rep("N | Mean (SD) | ", 3), collapse = ""),
      "LS Mean (95% CI){^a}"
    ),
    col_rel_width = c(2.5, rep(c(0.5, 1.5), 3), 2)
  ) %>%
  rtf_body(
    text_justification = c("l", rep("c", 7)),
    col_rel_width = c(2.5, rep(c(0.5, 1.5), 3), 2)
  ) %>%
  rtf_footnote(c(
    "{^a}Based on an ANCOVA model after adjusting baseline value. LOCF approach is used to impute missing values.",
    "ANCOVA = Analysis of Covariance, LOCF = Last Observation Carried Forward",
    "CI = Confidence Interval, LS = Least Squares, SD = Standard Deviation"
  ))

t1_rtf %>%
  rtf_encode() %>%
  write_rtf("tlf/tlf_eff1.rtf")

We also use r2rtf to prepare the table format for t2

t2_rtf <- t2 %>%
  data.frame() %>%
  rtf_colheader("Pairwise Comparison | Difference in LS Mean (95% CI){^a} | p-Value",
    col_rel_width = c(4.5, 4, 2)
  ) %>%
  rtf_body(
    text_justification = c("l", "c", "c"),
    col_rel_width = c(4.5, 4, 2)
  )

t2_rtf %>%
  rtf_encode() %>%
  write_rtf("tlf/tlf_eff2.rtf")

Finally, we combine the two parts to get the final table using r2rtf. This is achieved by providing a list of t1_rtf and t2_rtf as input for rtf_encode.

list(t1_rtf, t2_rtf) %>%
  rtf_encode() %>%
  write_rtf("tlf/tlf_eff.rtf")

In conclusion, the procedure to generate the above efficacy results table is summarized as follows.

  • Step 1: Read the data (i.e., adsl and adlb) into R.
  • Step 2: Define the analysis dataset. In this example, we define two analysis datasets. The first dataset is the efficacy population (gluc). The second dataset is the collection of all records post baseline and on or before week 24 (ana).
  • Step 3: Impute the missing values. In this example, we name the ana dataset after imputation as ana_locf.
  • Step 4: Calculate the mean and standard derivation of efficacy endpoint (i.e., gluc), and then format it into an RTF table.
  • Step 5: Calculate the pairwise comparison by ANCOVA model, and then format it into an RTF table.
  • Step 6: Combine the outputs from steps 4 and 5 by rows.