Efficacy

Following the ICH E3 guidance, we need to summarize primary and secondary efficacy endpoints, in Section 11.4, Efficacy Results and Tabulations of Individual Patient.

library(esubdemo)
## Warning in eval(ei, envir): The current R version is not the same with the
## current project in 4.1.0
library(haven) # Read SAS data
library(dplyr) # Manipulate data
library(tidyr) # Manipulate data
library(r2rtf) # Reporting in RTF format
library(emmeans) # LS means estimation
library(stringr) # String manipulation

For efficacy analysis, we only analyze change from baseline glucose data at Week 24.

Analysis Dataset

To prepare analysis dataset, we need both adsl and adlbc datasets for this analysis.

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

We first define the analysis dataset using efficacy population flag EFFFL 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, then AVISITN = 0; if the analysis visit is recorded as “Week 24”, i.e., AVISIT = Week 24, then AVISITN = 24; if the analysis visit is blank, then 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) %>%
  head(4)
## # A tibble: 4 × 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

Summary of Observed Data

We first summarize observed data at Baseline and Week 24

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)
  )
## `summarise()` has grouped output by 'TRTPN', 'TRTP'. You can override using the
## `.groups` argument.
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)"

We also summarize observed change from baseline glucose at Week 24.

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)
    )
  )
## `summarise()` has grouped output by 'TRTPN'. You can override using the
## `.groups` argument.
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)"

Missing Data Imputation

In clinical trials, missing data is inevitable. In this study, there are also 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
## 5 "         Week 12"   167
## 6 "         Week 16"   147
## 7 "         Week 20"   126
## 8 "         Week 24"   113

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 studies. 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)

ANCOVA model

We start to analyze the imputed data using 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

Then we use the emmeans R package to obtain within and between group least square mean (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(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"

Reporting

We combine t11, t12 and t13 to get the first part of the report data

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 we use r2rtf to prepare the table format for t1. We also highlight how to handle special character 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} provide a superscript a for footnote notation. r2rtf also support most LaTeX characters. Examples can be found in r2rtf Get Started Page. The text_convert argument in r2rtf_xxx functions control whether 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 into R, i.e., adsl and adlb.
  • 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 our example, we name the ana dataset after imputation as ana_locf.
  • Step 4: Summarize gluc, i.e., calculate the mean and standard derivation, and then format it into a rtf table.
  • Step 5: Summarize ana_locf, i.e., calculate the pairwise comparison by ANCOVA model, and then format it into a rtf table.
  • Step 6: Rowly bind the output in Step 4 and Step 5.