TLG Catalog - Stable
  • Stable
    • Dev
  1. Tables
  2. Efficacy
  3. MMRMT01
  • Introduction

  • Tables
    • ADA
      • ADAT01
      • ADAT02
      • ADAT03
      • ADAT04A
      • ADAT04B
    • Adverse Events
      • AET01
      • AET01_AESI
      • AET02
      • AET02_SMQ
      • AET03
      • AET04
      • AET04_PI
      • AET05
      • AET05_ALL
      • AET06
      • AET06_SMQ
      • AET07
      • AET09
      • AET09_SMQ
      • AET10
    • Concomitant Medications
      • CMT01
      • CMT01A
      • CMT01B
      • CMT02_PT
    • Deaths
      • DTHT01
    • Demography
      • DMT01
    • Disclosures
      • DISCLOSUREST01
      • EUDRAT01
      • EUDRAT02
    • Disposition
      • DST01
      • PDT01
      • PDT02
    • ECG
      • EGT01
      • EGT02
      • EGT03
      • EGT04
      • EGT05_QTCAT
    • Efficacy
      • AOVT01
      • AOVT02
      • AOVT03
      • CFBT01
      • CMHT01
      • COXT01
      • COXT02
      • DORT01
      • LGRT02
      • MMRMT01
      • ONCT05
      • RATET01
      • RBMIT01
      • RSPT01
      • TTET01
    • Exposure
      • EXT01
    • Lab Results
      • LBT01
      • LBT02
      • LBT03
      • LBT04
      • LBT05
      • LBT06
      • LBT07
      • LBT08
      • LBT09
      • LBT10
      • LBT10_BL
      • LBT11
      • LBT11_BL
      • LBT12
      • LBT12_BL
      • LBT13
      • LBT14
      • LBT15
    • Medical History
      • MHT01
    • Pharmacokinetic
      • PKCT01
      • PKPT02
      • PKPT03
      • PKPT04
      • PKPT05
      • PKPT06
      • PKPT07
      • PKPT08
      • PKPT11
    • Risk Management Plan
      • RMPT01
      • RMPT03
      • RMPT04
      • RMPT05
      • RMPT06
    • Safety
      • ENTXX
    • Vital Signs
      • VST01
      • VST02
  • Listings
    • ADA
      • ADAL02
    • Adverse Events
      • AEL01
      • AEL01_NOLLT
      • AEL02
      • AEL02_ED
      • AEL03
      • AEL04
    • Concomitant Medications
      • CML01
      • CML02A_GL
      • CML02B_GL
    • Development Safety Update Report
      • DSUR4
    • Disposition
      • DSL01
      • DSL02
    • ECG
      • EGL01
    • Efficacy
      • ONCL01
    • Exposure
      • EXL01
    • Lab Results
      • LBL01
      • LBL01_RLS
      • LBL02A
      • LBL02A_RLS
      • LBL02B
    • Medical History
      • MHL01
    • Pharmacokinetic
      • ADAL01
      • PKCL01
      • PKCL02
      • PKPL01
      • PKPL02
      • PKPL04
    • Vital Signs
      • VSL01
  • Graphs
    • Efficacy
      • FSTG01
      • FSTG02
      • KMG01
      • MMRMG01
      • MMRMG02
    • Other
      • BRG01
      • BWG01
      • CIG01
      • IPPG01
      • LTG01
      • MNG01
    • Pharmacokinetic
      • PKCG01
      • PKCG02
      • PKCG03
      • PKPG01
      • PKPG02
      • PKPG03
      • PKPG04
      • PKPG06

  • Appendix
    • Reproducibility

  • Index

On this page

  • teal App
  • Reproducibility
    • Timestamp
    • Session Info
    • .lock file
  • Edit this page
  • Report an issue
  1. Tables
  2. Efficacy
  3. MMRMT01

MMRMT01

Tables for Mixed-Effect Model Repeated Measures Analysis


  • Least Squares Means
  • Fixed Effects
  • Covariance Matrix
  • Model Diagnostics
  • Data Setup

Considering the treatment variable in the model

Code
mmrm_results <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BASE", "STRATA1", "BMRKR2"),
    id = "USUBJID",
    arm = "ARMCD",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal"
)

df <- tidy(mmrm_results)
attr(df$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df, alt_counts_df = adsl_sub)

result
Visit                                      ARM B              ARM A              ARM C      
  Statistics                              (N=134)            (N=134)            (N=132)     
————————————————————————————————————————————————————————————————————————————————————————————
WEEK 1 DAY 8                                                                                
  n                                         134                134                132       
  Adjusted Mean (SE)                   3.488 (0.687)      4.246 (0.687)      3.163 (0.692)  
    95% CI                             (2.136, 4.839)     (2.895, 5.598)     (1.803, 4.523) 
  Difference in Adjusted Means (SE)                       0.759 (0.973)      -0.325 (0.976) 
    95% CI                                               (-1.155, 2.672)    (-2.243, 1.593) 
    Relative Increase (%)                                     21.8%              -9.3%      
    p-value (MMRM)                                            0.4362             0.7393     
WEEK 2 DAY 15                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   9.135 (0.768)      9.018 (0.767)      8.509 (0.773)  
    95% CI                            (7.626, 10.644)    (7.510, 10.527)    (6.991, 10.028) 
  Difference in Adjusted Means (SE)                       -0.117 (1.087)     -0.626 (1.090) 
    95% CI                                               (-2.253, 2.020)    (-2.768, 1.517) 
    Relative Increase (%)                                     -1.3%              -6.8%      
    p-value (MMRM)                                            0.9147             0.5662     
WEEK 3 DAY 22                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   13.547 (0.871)     16.014 (0.871)     15.789 (0.877) 
    95% CI                            (11.835, 15.259)   (14.303, 17.726)   (14.066, 17.513)
  Difference in Adjusted Means (SE)                       2.467 (1.232)      2.242 (1.236)  
    95% CI                                                (0.044, 4.890)    (-0.187, 4.672) 
    Relative Increase (%)                                     18.2%              16.6%      
    p-value (MMRM)                                            0.0460             0.0704     
WEEK 4 DAY 29                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   18.102 (0.995)     19.479 (0.995)     19.511 (1.002) 
    95% CI                            (16.146, 20.059)   (17.523, 21.435)   (17.541, 21.481)
  Difference in Adjusted Means (SE)                       1.377 (1.408)      1.409 (1.413)  
    95% CI                                               (-1.392, 4.145)    (-1.368, 4.186) 
    Relative Increase (%)                                      7.6%               7.8%      
    p-value (MMRM)                                            0.3288             0.3192     
WEEK 5 DAY 36                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   23.503 (1.058)     24.931 (1.058)     23.704 (1.065) 
    95% CI                            (21.423, 25.583)   (22.851, 27.011)   (21.610, 25.798)
  Difference in Adjusted Means (SE)                       1.428 (1.497)      0.201 (1.502)  
    95% CI                                               (-1.515, 4.371)    (-2.752, 3.153) 
    Relative Increase (%)                                      6.1%               0.9%      
    p-value (MMRM)                                            0.3408             0.8937     

Not considering the treatment variable in the model

Code
mmrm_results_no_arm <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BMRKR2", "STRATA1"),
    id = "USUBJID",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal",
  parallel = TRUE
)

df_no_arm <- tidy(mmrm_results_no_arm)
attr(df_no_arm$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  add_overall_col("All Patients") %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df_no_arm$AVISIT)) %>%
  summarize_lsmeans(arms = FALSE) %>%
  append_topleft("  Statistics") %>%
  build_table(df_no_arm, alt_counts_df = adsl_sub)

result
Visit                    All Patients  
  Statistics               (N=400)     
———————————————————————————————————————
WEEK 1 DAY 8                           
  n                          400       
  Adjusted Mean (SE)    3.615 (0.620)  
    95% CI              (2.396, 4.834) 
WEEK 2 DAY 15                          
  n                          400       
  Adjusted Mean (SE)    8.870 (0.602)  
    95% CI             (7.687, 10.053) 
WEEK 3 DAY 22                          
  n                          400       
  Adjusted Mean (SE)    15.094 (0.683) 
    95% CI             (13.751, 16.437)
WEEK 4 DAY 29                          
  n                          400       
  Adjusted Mean (SE)    19.009 (0.717) 
    95% CI             (17.599, 20.418)
WEEK 5 DAY 36                          
  n                          400       
  Adjusted Mean (SE)    24.028 (0.747) 
    95% CI             (22.560, 25.496)

Adding baseline rows

It may be of interest to summarize some different statistics at the baseline visit or summarize a different variable in the data set not used in the MMRM. For example, the model may use the variable CHG but the baseline visit row may summarize the AVAL variable, thus we would need to create two tables and then combine them to accomplish this.

Code
# First have the least-square means table.
a <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df, alt_counts_df = adsl_sub)

# Second prepare the baseline values summary table.
baseline_dat <- adqs %>%
  filter(AVISIT == "BASELINE") %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  droplevels()

b <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD") %>%
  split_rows_by("AVISIT") %>%
  analyze_vars("AVAL") %>%
  append_topleft("  Statistics") %>%
  build_table(baseline_dat, alt_counts_df = adsl_sub)

# Now we can combine them as follows.
col_info(b) <- EmptyColInfo
rbind(b, a)
Modifying subtable (or row) names to ensure uniqueness among direct siblings
[AVISIT  -> { AVISIT, AVISIT[2] }]
  To control table names use split_rows_by*(, parent_name =.) or  analyze(., table_names = .) when analyzing a single variable, or analyze(., parent_name = .) when analyzing multiple variables in a single call.FALSE
Visit                                      ARM B              ARM A              ARM C      
  Statistics                              (N=134)            (N=134)            (N=132)     
————————————————————————————————————————————————————————————————————————————————————————————
BASELINE                                                                                    
  n                                         134                134                132       
  Mean (SD)                              49.9 (7.4)         49.7 (8.3)         50.3 (9.1)   
  Median                                    48.7               49.3               49.7      
  Min - Max                             33.7 - 65.9        25.8 - 71.5        26.0 - 70.0   
WEEK 1 DAY 8                                                                                
  n                                         134                134                132       
  Adjusted Mean (SE)                   3.488 (0.687)      4.246 (0.687)      3.163 (0.692)  
    95% CI                             (2.136, 4.839)     (2.895, 5.598)     (1.803, 4.523) 
  Difference in Adjusted Means (SE)                       0.759 (0.973)      -0.325 (0.976) 
    95% CI                                               (-1.155, 2.672)    (-2.243, 1.593) 
    Relative Increase (%)                                     21.8%              -9.3%      
    p-value (MMRM)                                            0.4362             0.7393     
WEEK 2 DAY 15                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   9.135 (0.768)      9.018 (0.767)      8.509 (0.773)  
    95% CI                            (7.626, 10.644)    (7.510, 10.527)    (6.991, 10.028) 
  Difference in Adjusted Means (SE)                       -0.117 (1.087)     -0.626 (1.090) 
    95% CI                                               (-2.253, 2.020)    (-2.768, 1.517) 
    Relative Increase (%)                                     -1.3%              -6.8%      
    p-value (MMRM)                                            0.9147             0.5662     
WEEK 3 DAY 22                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   13.547 (0.871)     16.014 (0.871)     15.789 (0.877) 
    95% CI                            (11.835, 15.259)   (14.303, 17.726)   (14.066, 17.513)
  Difference in Adjusted Means (SE)                       2.467 (1.232)      2.242 (1.236)  
    95% CI                                                (0.044, 4.890)    (-0.187, 4.672) 
    Relative Increase (%)                                     18.2%              16.6%      
    p-value (MMRM)                                            0.0460             0.0704     
WEEK 4 DAY 29                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   18.102 (0.995)     19.479 (0.995)     19.511 (1.002) 
    95% CI                            (16.146, 20.059)   (17.523, 21.435)   (17.541, 21.481)
  Difference in Adjusted Means (SE)                       1.377 (1.408)      1.409 (1.413)  
    95% CI                                               (-1.392, 4.145)    (-1.368, 4.186) 
    Relative Increase (%)                                      7.6%               7.8%      
    p-value (MMRM)                                            0.3288             0.3192     
WEEK 5 DAY 36                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   23.503 (1.058)     24.931 (1.058)     23.704 (1.065) 
    95% CI                            (21.423, 25.583)   (22.851, 27.011)   (21.610, 25.798)
  Difference in Adjusted Means (SE)                       1.428 (1.497)      0.201 (1.502)  
    95% CI                                               (-1.515, 4.371)    (-2.752, 3.153) 
    Relative Increase (%)                                      6.1%               0.9%      
    p-value (MMRM)                                            0.3408             0.8937     

Considering visit averages

It may also be of interest to summarize several different statistics for an averaged combination of various visits in the MMRM. For example, you may want to see the statistics for the average of the first 2 visits, or the average statistics of all visits combined. This can be accomplished by specifying the averages_emmeans argument when fitting the MMRM model.

Code
mmrm_results_avg_visits <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BASE", "STRATA1", "BMRKR2"),
    id = "USUBJID",
    arm = "ARMCD",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal",
  averages_emmeans = list(
    "WEEKS 1-2" = c("WEEK 1 DAY 8", "WEEK 2 DAY 15"),
    "WEEKS 3-5" = c("WEEK 3 DAY 22", "WEEK 4 DAY 29", "WEEK 5 DAY 36"),
    "ALL VISITS" = c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22", "WEEK 4 DAY 29", "WEEK 5 DAY 36")
  )
)

df_avgs <- tidy(mmrm_results_avg_visits)
attr(df_avgs$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results_avg_visits$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df_avgs$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df_avgs, alt_counts_df = adsl_sub)

result
Visit                                      ARM B              ARM A              ARM C      
  Statistics                              (N=134)            (N=134)            (N=132)     
————————————————————————————————————————————————————————————————————————————————————————————
WEEK 1 DAY 8                                                                                
  n                                         134                134                132       
  Adjusted Mean (SE)                   3.488 (0.687)      4.246 (0.687)      3.163 (0.692)  
    95% CI                             (2.136, 4.839)     (2.895, 5.598)     (1.803, 4.523) 
  Difference in Adjusted Means (SE)                       0.759 (0.973)      -0.325 (0.976) 
    95% CI                                               (-1.155, 2.672)    (-2.243, 1.593) 
    Relative Increase (%)                                     21.8%              -9.3%      
    p-value (MMRM)                                            0.4362             0.7393     
WEEK 2 DAY 15                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   9.135 (0.768)      9.018 (0.767)      8.509 (0.773)  
    95% CI                            (7.626, 10.644)    (7.510, 10.527)    (6.991, 10.028) 
  Difference in Adjusted Means (SE)                       -0.117 (1.087)     -0.626 (1.090) 
    95% CI                                               (-2.253, 2.020)    (-2.768, 1.517) 
    Relative Increase (%)                                     -1.3%              -6.8%      
    p-value (MMRM)                                            0.9147             0.5662     
WEEK 3 DAY 22                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   13.547 (0.871)     16.014 (0.871)     15.789 (0.877) 
    95% CI                            (11.835, 15.259)   (14.303, 17.726)   (14.066, 17.513)
  Difference in Adjusted Means (SE)                       2.467 (1.232)      2.242 (1.236)  
    95% CI                                                (0.044, 4.890)    (-0.187, 4.672) 
    Relative Increase (%)                                     18.2%              16.6%      
    p-value (MMRM)                                            0.0460             0.0704     
WEEK 4 DAY 29                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   18.102 (0.995)     19.479 (0.995)     19.511 (1.002) 
    95% CI                            (16.146, 20.059)   (17.523, 21.435)   (17.541, 21.481)
  Difference in Adjusted Means (SE)                       1.377 (1.408)      1.409 (1.413)  
    95% CI                                               (-1.392, 4.145)    (-1.368, 4.186) 
    Relative Increase (%)                                      7.6%               7.8%      
    p-value (MMRM)                                            0.3288             0.3192     
WEEK 5 DAY 36                                                                               
  n                                         134                134                132       
  Adjusted Mean (SE)                   23.503 (1.058)     24.931 (1.058)     23.704 (1.065) 
    95% CI                            (21.423, 25.583)   (22.851, 27.011)   (21.610, 25.798)
  Difference in Adjusted Means (SE)                       1.428 (1.497)      0.201 (1.502)  
    95% CI                                               (-1.515, 4.371)    (-2.752, 3.153) 
    Relative Increase (%)                                      6.1%               0.9%      
    p-value (MMRM)                                            0.3408             0.8937     
WEEKS 1-2                                                                                   
  n                                         134                134                132       
  Adjusted Mean (SE)                   6.311 (0.514)      6.632 (0.514)      5.836 (0.516)  
    95% CI                             (5.301, 7.322)     (5.623, 7.642)     (4.821, 6.852) 
  Difference in Adjusted Means (SE)                       0.321 (0.728)      -0.475 (0.729) 
    95% CI                                               (-1.111, 1.753)    (-1.909, 0.959) 
    Relative Increase (%)                                      5.1%              -7.5%      
    p-value (MMRM)                                            0.6596             0.5151     
WEEKS 3-5                                                                                   
  n                                         134                134                132       
  Adjusted Mean (SE)                   18.384 (0.560)     20.141 (0.560)     19.668 (0.563) 
    95% CI                            (17.284, 19.485)   (19.041, 21.241)   (18.562, 20.775)
  Difference in Adjusted Means (SE)                       1.757 (0.793)      1.284 (0.794)  
    95% CI                                                (0.198, 3.316)    (-0.278, 2.846) 
    Relative Increase (%)                                      9.6%               7.0%      
    p-value (MMRM)                                            0.0273             0.1068     
ALL VISITS                                                                                  
  n                                         134                134                132       
  Adjusted Mean (SE)                   13.555 (0.388)     14.738 (0.388)     14.135 (0.389) 
    95% CI                            (12.792, 14.318)   (13.976, 15.500)   (13.370, 14.900)
  Difference in Adjusted Means (SE)                       1.183 (0.551)      0.580 (0.551)  
    95% CI                                                (0.100, 2.266)    (-0.502, 1.663) 
    Relative Increase (%)                                      8.7%               4.3%      
    p-value (MMRM)                                            0.0324             0.2924     

Considering the treatment variable in the model

Code
as.rtable(mmrm_results, type = "fixed")
                                 Estimate   Std. Error   t value    df    Pr(>|t|)
——————————————————————————————————————————————————————————————————————————————————
(Intercept)                      55.7483      1.5244     36.5713    510   <0.0001 
BASE                             -1.0196      0.0246     -41.4362   392   <0.0001 
STRATA1B                         -0.0369      0.5345     -0.0691    392    0.9450 
STRATA1C                          0.0205      0.5238      0.0392    392    0.9688 
BMRKR2MEDIUM                     -0.3840      0.5198     -0.7386    392    0.4606 
BMRKR2HIGH                       -1.0056      0.5259     -1.9123    392    0.0566 
ARMCDARM A                        0.7587      0.9733      0.7795    396    0.4362 
ARMCDARM C                       -0.3248      0.9756     -0.3329    394    0.7393 
AVISITWEEK 2 DAY 15               5.6472      1.0331      5.4665    397   <0.0001 
AVISITWEEK 3 DAY 22              10.0591      1.0897      9.2311    397   <0.0001 
AVISITWEEK 4 DAY 29              14.6145      1.2176     12.0027    397   <0.0001 
AVISITWEEK 5 DAY 36              20.0154      1.2584     15.9057    397   <0.0001 
ARMCDARM A:AVISITWEEK 2 DAY 15   -0.8752      1.4610     -0.5990    397    0.5495 
ARMCDARM C:AVISITWEEK 2 DAY 15   -0.3007      1.4665     -0.2050    397    0.8376 
ARMCDARM A:AVISITWEEK 3 DAY 22    1.7085      1.5411      1.1087    397    0.2682 
ARMCDARM C:AVISITWEEK 3 DAY 22    2.5673      1.5469      1.6597    397    0.0978 
ARMCDARM A:AVISITWEEK 4 DAY 29    0.6181      1.7220      0.3589    397    0.7198 
ARMCDARM C:AVISITWEEK 4 DAY 29    1.7337      1.7285      1.0030    397    0.3165 
ARMCDARM A:AVISITWEEK 5 DAY 36    0.6690      1.7796      0.3759    397    0.7072 
ARMCDARM C:AVISITWEEK 5 DAY 36    0.5257      1.7863      0.2943    397    0.7687 

Not considering the treatment variable in the model

Code
as.rtable(mmrm_results_no_arm, type = "fixed")
                      Estimate   Std. Error   t value   df    Pr(>|t|)
——————————————————————————————————————————————————————————————————————
(Intercept)            1.5624      1.1751     1.3296    466    0.1843 
BMRKR2MEDIUM           1.0924      1.1878     0.9196    395    0.3583 
BMRKR2HIGH             1.4619      1.1971     1.2212    395    0.2227 
STRATA1B               2.6321      1.2180     2.1610    395    0.0313 
STRATA1C               0.9717      1.2008     0.8092    395    0.4189 
AVISITWEEK 2 DAY 15    5.2548      0.5967     8.8061    399   <0.0001 
AVISITWEEK 3 DAY 22   11.4787      0.6314     18.1802   399   <0.0001 
AVISITWEEK 4 DAY 29   15.3937      0.7039     21.8696   399   <0.0001 
AVISITWEEK 5 DAY 36   20.4130      0.7266     28.0921   399   <0.0001 
Code
as.rtable(mmrm_results, type = "cov")
                WEEK 1 DAY 8   WEEK 2 DAY 15   WEEK 3 DAY 22   WEEK 4 DAY 29   WEEK 5 DAY 36
————————————————————————————————————————————————————————————————————————————————————————————
WEEK 1 DAY 8      63.0140         -0.6664         2.5965          -1.6231         0.2589    
WEEK 2 DAY 15     -0.6664         78.6592         1.7004         -11.8677         -0.4261   
WEEK 3 DAY 22      2.5965         1.7004         101.2949         -5.8424         7.1145    
WEEK 4 DAY 29     -1.6231        -11.8677         -5.8424        132.4034         -5.3739   
WEEK 5 DAY 36      0.2589         -0.4261         7.1145          -5.3739        149.6937   

Model diagnostics are currently available to evaluate choice of covariates for the fixed and random effects. Statistics to evaluate choice of covariance structure are being investigated and will be included in a future release.

Code
as.rtable(mmrm_results, type = "diagnostic")
                 Diagnostic statistic value
———————————————————————————————————————————
REML criterion           14835.9968        
AIC                      14865.9968        
AICc                     14866.2412        
BIC                      14925.8688        
Code
library(dplyr)
library(tern.mmrm)
library(broom)

adsl <- random.cdisc.data::cadsl
adqs <- random.cdisc.data::cadqs

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adqs <- df_explicit_na(adqs)

adqs_f <- adqs %>%
  dplyr::filter(PARAMCD == "FKSI-FWB" & !AVISIT %in% c("BASELINE", "SCREENING")) %>%
  droplevels() %>%
  dplyr::mutate(ARMCD = factor(ARMCD, levels = c("ARM B", "ARM A", "ARM C"))) %>%
  dplyr::mutate(
    AVISITN = rank(AVISITN) %>%
      as.factor() %>%
      as.numeric() %>%
      as.factor()
  )
adsl_sub <- adqs_f %>%
  dplyr::filter(!is.na(CHG)) %>%
  distinct(USUBJID) %>%
  left_join(adsl, by = "USUBJID")
var_labels(adqs_f) <- var_labels(adqs)

teal App

Code
library(teal.modules.clinical)

## Data reproducible code
data <- teal_data()
data <- within(data, {
  library(dplyr)

  ADSL <- random.cdisc.data::cadsl
  ADQS <- random.cdisc.data::cadqs %>%
    filter(ABLFL != "Y" & ABLFL2 != "Y") %>%
    filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22")) %>%
    mutate(
      AVISIT = as.factor(AVISIT),
      AVISITN = rank(AVISITN) %>%
        as.factor() %>%
        as.numeric() %>%
        as.factor() # making consecutive numeric factor
    )
})
datanames <- c("ADSL", "ADQS")
datanames(data) <- datanames
Warning: `datanames<-()` was deprecated in teal.data 0.7.0.
ℹ invalid to use `datanames()<-` or `names()<-` on an object of class
  `teal_data`. See ?names.teal_data
Code
join_keys(data) <- default_cdisc_join_keys[datanames]

## Reusable Configuration For Modules
ADQS <- data[["ADQS"]]
arm_ref_comp <- list(
  ARMCD = list(
    ref = "ARM A",
    comp = c("ARM B", "ARM C")
  )
)

## Setup App
app <- init(
  data = data,
  modules = modules(
    tm_a_mmrm(
      label = "MMRM",
      dataname = "ADQS",
      aval_var = choices_selected(c("AVAL", "CHG"), "CHG"),
      id_var = choices_selected(c("USUBJID", "SUBJID"), "USUBJID"),
      arm_var = choices_selected(c("ARM", "ARMCD"), "ARMCD"),
      visit_var = choices_selected(c("AVISIT", "AVISITN"), "AVISIT"),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        choices = value_choices(ADQS, "PARAMCD", "PARAM"),
        selected = "FKSI-FWB"
      ),
      cov_var = choices_selected(c("BASE", "AGE", "SEX", "BASE:AVISIT"), NULL),
      conf_level = choices_selected(c(0.95, 0.9, 0.8), 0.95)
    )
  )
)

shinyApp(app$ui, app$server)

Reproducibility

Timestamp

[1] "2025-07-09 17:43:41 UTC"

Session Info

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.0 (2025-04-11)
 os       Ubuntu 24.04.2 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Etc/UTC
 date     2025-07-09
 pandoc   3.7.0.2 @ /usr/bin/ (via rmarkdown)
 quarto   1.7.32 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package               * version  date (UTC) lib source
 backports               1.5.0    2024-05-23 [1] RSPM
 brio                    1.1.5    2024-04-24 [1] RSPM
 broom                 * 1.0.8    2025-03-28 [1] RSPM
 bslib                   0.9.0    2025-01-30 [1] RSPM
 cachem                  1.1.0    2024-05-16 [1] RSPM
 callr                   3.7.6    2024-03-25 [1] RSPM
 checkmate               2.3.2    2024-07-29 [1] RSPM
 chromote                0.5.1    2025-04-24 [1] RSPM
 cli                     3.6.5    2025-04-23 [1] RSPM
 coda                    0.19-4.1 2024-01-31 [1] CRAN (R 4.5.0)
 codetools               0.2-20   2024-03-31 [2] CRAN (R 4.5.0)
 cowplot                 1.2.0    2025-07-07 [1] RSPM
 curl                    6.4.0    2025-06-22 [1] RSPM
 dichromat               2.0-0.1  2022-05-02 [1] CRAN (R 4.5.0)
 digest                  0.6.37   2024-08-19 [1] RSPM
 dplyr                 * 1.1.4    2023-11-17 [1] RSPM
 emmeans                 1.11.1   2025-05-04 [1] RSPM
 estimability            1.5.1    2024-05-12 [1] RSPM
 evaluate                1.0.4    2025-06-18 [1] RSPM
 farver                  2.1.2    2024-05-13 [1] RSPM
 fastmap                 1.2.0    2024-05-15 [1] RSPM
 fontawesome             0.5.3    2024-11-16 [1] RSPM
 forcats                 1.0.0    2023-01-29 [1] RSPM
 formatR                 1.14     2023-01-17 [1] CRAN (R 4.5.0)
 formatters            * 0.5.11   2025-04-09 [1] RSPM
 geepack                 1.3.12   2024-09-23 [1] RSPM
 generics                0.1.4    2025-05-09 [1] RSPM
 ggplot2                 3.5.2    2025-04-09 [1] RSPM
 glue                    1.8.0    2024-09-30 [1] RSPM
 gtable                  0.3.6    2024-10-25 [1] RSPM
 htmltools               0.5.8.1  2024-04-04 [1] RSPM
 htmlwidgets             1.6.4    2023-12-06 [1] RSPM
 httpuv                  1.6.16   2025-04-16 [1] RSPM
 jquerylib               0.1.4    2021-04-26 [1] RSPM
 jsonlite                2.0.0    2025-03-27 [1] RSPM
 knitr                   1.50     2025-03-16 [1] RSPM
 later                   1.4.2    2025-04-08 [1] RSPM
 lattice                 0.22-7   2025-04-02 [2] CRAN (R 4.5.0)
 lifecycle               1.0.4    2023-11-07 [1] RSPM
 logger                  0.4.0    2024-10-22 [1] RSPM
 magrittr              * 2.0.3    2022-03-30 [1] RSPM
 MASS                    7.3-65   2025-02-28 [2] CRAN (R 4.5.0)
 Matrix                  1.7-3    2025-03-11 [1] CRAN (R 4.5.0)
 memoise                 2.0.1    2021-11-26 [1] RSPM
 mime                    0.13     2025-03-17 [1] RSPM
 mmrm                    0.3.15   2025-06-10 [1] RSPM
 multcomp                1.4-28   2025-01-29 [1] RSPM
 mvtnorm                 1.3-3    2025-01-10 [1] RSPM
 nestcolor               0.1.3    2025-01-21 [1] RSPM
 nlme                    3.1-168  2025-03-31 [2] CRAN (R 4.5.0)
 parallelly              1.45.0   2025-06-02 [1] RSPM
 pillar                  1.11.0   2025-07-04 [1] RSPM
 pkgcache                2.2.4    2025-05-26 [1] RSPM
 pkgconfig               2.0.3    2019-09-22 [1] RSPM
 processx                3.8.6    2025-02-21 [1] RSPM
 promises                1.3.3    2025-05-29 [1] RSPM
 ps                      1.9.1    2025-04-12 [1] RSPM
 purrr                   1.0.4    2025-02-05 [1] RSPM
 R6                      2.6.1    2025-02-15 [1] RSPM
 random.cdisc.data       0.3.16   2024-10-10 [1] RSPM
 rbibutils               2.3      2024-10-04 [1] RSPM
 RColorBrewer            1.1-3    2022-04-03 [1] RSPM
 Rcpp                    1.1.0    2025-07-02 [1] RSPM
 Rdpack                  2.6.4    2025-04-09 [1] RSPM
 rlang                   1.1.6    2025-04-11 [1] RSPM
 rmarkdown               2.29     2024-11-04 [1] RSPM
 rtables               * 0.6.13   2025-06-19 [1] RSPM
 sandwich                3.1-1    2024-09-15 [1] RSPM
 sass                    0.4.10   2025-04-11 [1] RSPM
 scales                  1.4.0    2025-04-24 [1] RSPM
 sessioninfo             1.2.3    2025-02-05 [1] any (@1.2.3)
 shiny                 * 1.11.1   2025-07-03 [1] RSPM
 shinycssloaders         1.1.0    2024-07-30 [1] RSPM
 shinyjs                 2.1.0    2021-12-23 [1] RSPM
 shinyvalidate           0.1.3    2023-10-04 [1] RSPM
 shinyWidgets            0.9.0    2025-02-21 [1] RSPM
 stringi                 1.8.7    2025-03-27 [1] RSPM
 stringr                 1.5.1    2023-11-14 [1] RSPM
 survival                3.8-3    2024-12-17 [2] CRAN (R 4.5.0)
 teal                  * 0.16.0   2025-02-23 [1] RSPM
 teal.code             * 0.6.1    2025-02-14 [1] RSPM
 teal.data             * 0.7.0    2025-01-28 [1] RSPM
 teal.logger             0.4.0    2025-07-08 [1] RSPM
 teal.modules.clinical * 0.10.0   2025-02-28 [1] RSPM
 teal.reporter           0.4.0    2025-01-24 [1] RSPM
 teal.slice            * 0.6.0    2025-02-03 [1] RSPM
 teal.transform        * 0.6.0    2025-02-12 [1] RSPM
 teal.widgets            0.4.3    2025-01-31 [1] RSPM
 tern                  * 0.9.9    2025-06-20 [1] RSPM
 tern.gee                0.1.5    2024-08-23 [1] RSPM
 tern.mmrm             * 0.3.3    2025-07-04 [1] RSPM
 testthat                3.2.3    2025-01-13 [1] RSPM
 TH.data                 1.1-3    2025-01-17 [1] RSPM
 tibble                  3.3.0    2025-06-08 [1] RSPM
 tidyr                   1.3.1    2024-01-24 [1] RSPM
 tidyselect              1.2.1    2024-03-11 [1] RSPM
 TMB                     1.9.17   2025-03-10 [1] RSPM
 vctrs                   0.6.5    2023-12-01 [1] RSPM
 webshot                 0.5.5    2023-06-26 [1] CRAN (R 4.5.0)
 webshot2                0.1.2    2025-04-23 [1] RSPM
 websocket               1.4.4    2025-04-10 [1] RSPM
 withr                   3.0.2    2024-10-28 [1] RSPM
 xfun                    0.52     2025-04-02 [1] RSPM
 xtable                  1.8-4    2019-04-21 [1] RSPM
 yaml                    2.3.10   2024-07-26 [1] RSPM
 zoo                     1.8-14   2025-04-10 [1] RSPM

 [1] /usr/local/lib/R/site-library
 [2] /usr/local/lib/R/library
 [3] /github/home/R/x86_64-pc-linux-gnu-library/4.5
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────

.lock file

Download the .lock file and use renv::restore() on it to recreate environment used to generate this website.

Download

LGRT02
ONCT05
Source Code
---
title: MMRMT01
subtitle: Tables for Mixed-Effect Model Repeated Measures Analysis
---

------------------------------------------------------------------------

{{< include ../../_utils/envir_hook.qmd >}}

```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern.mmrm)
library(broom)

adsl <- random.cdisc.data::cadsl
adqs <- random.cdisc.data::cadqs

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adqs <- df_explicit_na(adqs)

adqs_f <- adqs %>%
  dplyr::filter(PARAMCD == "FKSI-FWB" & !AVISIT %in% c("BASELINE", "SCREENING")) %>%
  droplevels() %>%
  dplyr::mutate(ARMCD = factor(ARMCD, levels = c("ARM B", "ARM A", "ARM C"))) %>%
  dplyr::mutate(
    AVISITN = rank(AVISITN) %>%
      as.factor() %>%
      as.numeric() %>%
      as.factor()
  )
adsl_sub <- adqs_f %>%
  dplyr::filter(!is.na(CHG)) %>%
  distinct(USUBJID) %>%
  left_join(adsl, by = "USUBJID")
var_labels(adqs_f) <- var_labels(adqs)
```

::: panel-tabset
## Least Squares Means

#### Considering the treatment variable in the model

```{r variant1, test = list(result_v1 = "result"), message = FALSE}
mmrm_results <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BASE", "STRATA1", "BMRKR2"),
    id = "USUBJID",
    arm = "ARMCD",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal"
)

df <- tidy(mmrm_results)
attr(df$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df, alt_counts_df = adsl_sub)

result
```

#### Not considering the treatment variable in the model

```{r variant2, test = list(result_v2 = "result")}
mmrm_results_no_arm <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BMRKR2", "STRATA1"),
    id = "USUBJID",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal",
  parallel = TRUE
)

df_no_arm <- tidy(mmrm_results_no_arm)
attr(df_no_arm$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  add_overall_col("All Patients") %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df_no_arm$AVISIT)) %>%
  summarize_lsmeans(arms = FALSE) %>%
  append_topleft("  Statistics") %>%
  build_table(df_no_arm, alt_counts_df = adsl_sub)

result
```

#### Adding baseline rows

It may be of interest to summarize some different statistics at the baseline visit or summarize a different variable in the data set not used in the MMRM. For example, the model may use the variable `CHG` but the baseline visit row may summarize the `AVAL` variable, thus we would need to create two tables and then combine them to accomplish this.

```{r variant_baseline, test = list(result_baseline = "result")}
# First have the least-square means table.
a <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df, alt_counts_df = adsl_sub)

# Second prepare the baseline values summary table.
baseline_dat <- adqs %>%
  filter(AVISIT == "BASELINE") %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  droplevels()

b <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD") %>%
  split_rows_by("AVISIT") %>%
  analyze_vars("AVAL") %>%
  append_topleft("  Statistics") %>%
  build_table(baseline_dat, alt_counts_df = adsl_sub)

# Now we can combine them as follows.
col_info(b) <- EmptyColInfo
rbind(b, a)
```

#### Considering visit averages

It may also be of interest to summarize several different statistics for an averaged combination of various visits in the MMRM. For example, you may want to see the statistics for the average of the first 2 visits, or the average statistics of all visits combined. This can be accomplished by specifying the `averages_emmeans` argument when fitting the MMRM model.

```{r variant3, test = list(result_v3 = "result")}
mmrm_results_avg_visits <- fit_mmrm(
  vars = list(
    response = "CHG",
    covariates = c("BASE", "STRATA1", "BMRKR2"),
    id = "USUBJID",
    arm = "ARMCD",
    visit = "AVISIT"
  ),
  data = adqs_f,
  weights_emmeans = "equal",
  averages_emmeans = list(
    "WEEKS 1-2" = c("WEEK 1 DAY 8", "WEEK 2 DAY 15"),
    "WEEKS 3-5" = c("WEEK 3 DAY 22", "WEEK 4 DAY 29", "WEEK 5 DAY 36"),
    "ALL VISITS" = c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22", "WEEK 4 DAY 29", "WEEK 5 DAY 36")
  )
)

df_avgs <- tidy(mmrm_results_avg_visits)
attr(df_avgs$AVISIT, "label") <- "Visit"

# Define the split function
split_fun <- drop_split_levels

result <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARMCD", ref_group = mmrm_results_avg_visits$ref_level) %>%
  split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(df_avgs$AVISIT)) %>%
  summarize_lsmeans(show_relative = "increase") %>%
  append_topleft("  Statistics") %>%
  build_table(df_avgs, alt_counts_df = adsl_sub)

result
```

## Fixed Effects

#### Considering the treatment variable in the model

```{r}
as.rtable(mmrm_results, type = "fixed")
```

#### Not considering the treatment variable in the model

```{r}
as.rtable(mmrm_results_no_arm, type = "fixed")
```

## Covariance Matrix

```{r}
as.rtable(mmrm_results, type = "cov")
```

## Model Diagnostics

Model diagnostics are currently available to evaluate choice of covariates for the fixed and random effects. Statistics to evaluate choice of covariance structure are being investigated and will be included in a future release.

```{r}
as.rtable(mmrm_results, type = "diagnostic")
```

## Data Setup

```{r setup}
#| code-fold: show
```
:::

{{< include ../../_utils/save_results.qmd >}}

## `teal` App

```{r teal, opts.label = c("skip_if_testing", "app")}
library(teal.modules.clinical)

## Data reproducible code
data <- teal_data()
data <- within(data, {
  library(dplyr)

  ADSL <- random.cdisc.data::cadsl
  ADQS <- random.cdisc.data::cadqs %>%
    filter(ABLFL != "Y" & ABLFL2 != "Y") %>%
    filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22")) %>%
    mutate(
      AVISIT = as.factor(AVISIT),
      AVISITN = rank(AVISITN) %>%
        as.factor() %>%
        as.numeric() %>%
        as.factor() # making consecutive numeric factor
    )
})
datanames <- c("ADSL", "ADQS")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]

## Reusable Configuration For Modules
ADQS <- data[["ADQS"]]
arm_ref_comp <- list(
  ARMCD = list(
    ref = "ARM A",
    comp = c("ARM B", "ARM C")
  )
)

## Setup App
app <- init(
  data = data,
  modules = modules(
    tm_a_mmrm(
      label = "MMRM",
      dataname = "ADQS",
      aval_var = choices_selected(c("AVAL", "CHG"), "CHG"),
      id_var = choices_selected(c("USUBJID", "SUBJID"), "USUBJID"),
      arm_var = choices_selected(c("ARM", "ARMCD"), "ARMCD"),
      visit_var = choices_selected(c("AVISIT", "AVISITN"), "AVISIT"),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        choices = value_choices(ADQS, "PARAMCD", "PARAM"),
        selected = "FKSI-FWB"
      ),
      cov_var = choices_selected(c("BASE", "AGE", "SEX", "BASE:AVISIT"), NULL),
      conf_level = choices_selected(c(0.95, 0.9, 0.8), 0.95)
    )
  )
)

shinyApp(app$ui, app$server)
```

{{< include ../../repro.qmd >}}

Made with ❤️ by the NEST Team

  • Edit this page
  • Report an issue
Cookie Preferences