Rmd setup

Instructions

Submission

Please knit your file as a HTML File and submit your assignment to bCourses.

Tips

  • The question in Exercise 3 is meant to complement Module: Creating Table 1 in R in Week 9.

  • Exercise 3 is going to use the glp1_data.csv dataset that we cleaned in Module: Creating Table 1 in R.

Read in Data

# Them, import the dataset
data <- read_csv(here(params$week, "data", "glp1_data.csv"))

Question

In Module: Creating Table 1 in R we walked through the separate pieces that go into creating a Table 1. Now it is your turn to put everything together and create your own Table 1! Hint - please use the pieces from 09_table-1.Rmd to put your table together :)

Please include the following pieces in your Table 1

theme_gtsummary_journal(journal = "jama")
## Setting theme "JAMA"
theme_gtsummary_compact()
## Setting theme "Compact"
tbl1 <-
  data %>%
 
  select(-c(patient_id, heart_disease, insulin, diabetes)) %>%
  tbl_summary(
    by = glp1,                
    missing = "always",        
    

    label = list(
      age            ~ "Age, years",
      age_category   ~ "Age category",
      race           ~ "Race/ethnicity",
      gender         ~ "Gender",
      medicare_plan  ~ "Medicare plan",
      smoking_status ~ "Smoking status",
      hypertension   ~ "Hypertension",
      hyperlipidemia ~ "Hyperlipidemia",
      hospitalization~ "Hospitalized in past 2 years",
      bmi            ~ "BMI (kg/m²)",
      bmi_category   ~ "BMI category",
      a1c            ~ "Hemoglobin A1c (%)",
      sweet_beverages~ "Sugary drinks per day",
      charlson_score ~ "Charlson comorbidity index",
      metformin      ~ "Using metformin"
    ),
    
      type = list(
      all_categorical() ~ "categorical",
      all_continuous()  ~ "continuous2",   
      age               ~ "continuous"     
    ),
    
    statistic = list(
      all_categorical() ~ "{n} ({p}%)",
      all_continuous2() ~ c("{mean} ({sd})",
                            "{median} [{p25}, {p75}]"),
      age               ~ "{mean} ({sd})"
    ),
    
    digits = list(
      
      all_categorical() ~ c(0, 1),
    
      all_continuous2() ~ c(1, 1, 1, 1, 1),
      age               ~ c(1, 1),
      bmi               ~ c(1, 1),
      a1c               ~ c(1, 1),
      sweet_beverages   ~ c(1, 1)
    )
  ) %>%

  add_overall(col_label = "Overall", last = TRUE) %>%
 
  add_p(
    test = list(
      all_categorical() ~ "chisq.test",
      all_continuous2() ~ "t.test",
      age               ~ "t.test"
    ),
    pvalue_fun = ~ style_pvalue(.x, digits = 3)
  ) %>%

  bold_p(t = 0.05) %>%
  add_stat_label() %>%          
  italicize_levels() %>%        
  bold_labels()                 
## The following warnings were returned during `bold_p()`:
## ! For variable `sweet_beverages` (`glp1`) and "statistic", "p.value", and
##   "parameter" statistics: Chi-squared approximation may be incorrect
## `add_stat_label()` has previously been applied. Returning gtsummary table
## unaltered.
tbl1
Characteristic No
N = 2,500
Yes
N = 2,500
Overall p-value1
Age, years, Mean (SD) 73.1 (5.4) 73.1 (5.5) 73.1 (5.5) 0.965
    Unknown 0 0 0
Age category, n (%)


0.699
    65-69 784 (31.4%) 821 (32.8%) 1,605 (32.1%)
    70-74 769 (30.8%) 731 (29.2%) 1,500 (30.0%)
    75-79 546 (21.8%) 555 (22.2%) 1,101 (22.0%)
    80-84 371 (14.8%) 360 (14.4%) 731 (14.6%)
    85-89 30 (1.2%) 33 (1.3%) 63 (1.3%)
    Unknown 0 0 0
Race/ethnicity, n (%)


0.294
    Asian 376 (15.0%) 396 (15.8%) 772 (15.4%)
    Black 151 (6.0%) 142 (5.7%) 293 (5.9%)
    Hispanic 1,019 (40.8%) 1,025 (41.0%) 2,044 (40.9%)
    Multiracial 74 (3.0%) 56 (2.2%) 130 (2.6%)
    Native American 10 (0.4%) 21 (0.8%) 31 (0.6%)
    Pacific Islander 11 (0.4%) 10 (0.4%) 21 (0.4%)
    White 859 (34.4%) 850 (34.0%) 1,709 (34.2%)
    Unknown 0 0 0
Gender, n (%)


0.838
    Female 1,256 (50.2%) 1,236 (49.4%) 2,492 (49.8%)
    Male 1,172 (46.9%) 1,193 (47.7%) 2,365 (47.3%)
    Non-Binary 72 (2.9%) 71 (2.8%) 143 (2.9%)
    Unknown 0 0 0
Medicare plan, n (%)


0.290
    Advantage 855 (34.2%) 876 (35.0%) 1,731 (34.6%)
    Original 1,262 (50.5%) 1,280 (51.2%) 2,542 (50.8%)
    Supplemental 383 (15.3%) 344 (13.8%) 727 (14.5%)
    Unknown 0 0 0
Smoking status, n (%)


0.343
    Current smoker 206 (8.2%) 192 (7.7%) 398 (8.0%)
    Former smoker 1,125 (45.0%) 1,175 (47.0%) 2,300 (46.0%)
    Never smoker 1,169 (46.8%) 1,133 (45.3%) 2,302 (46.0%)
    Unknown 0 0 0
Hypertension, n (%)


0.559
    No 1,550 (62.0%) 1,571 (62.8%) 3,121 (62.4%)
    Yes 950 (38.0%) 929 (37.2%) 1,879 (37.6%)
    Unknown 0 0 0
Hyperlipidemia, n (%)


0.013
    No 916 (36.6%) 1,002 (40.1%) 1,918 (38.4%)
    Yes 1,584 (63.4%) 1,498 (59.9%) 3,082 (61.6%)
    Unknown 0 0 0
Hospitalized in past 2 years, n (%)


0.130
    No 1,051 (42.0%) 1,105 (44.2%) 2,156 (43.1%)
    Yes 1,449 (58.0%) 1,395 (55.8%) 2,844 (56.9%)
    Unknown 0 0 0
BMI (kg/m²)


0.117
    Mean (SD) 31.1 (3.3) 30.9 (3.3) 31.0 (3.3)
    Median [Q1, Q3] 31.0 [28.9, 33.3] 30.9 [28.7, 33.2] 31.0 [28.8, 33.2]
    Unknown 0 0 0
BMI category, n (%)


0.262
    Normal weight 72 (2.9%) 88 (3.5%) 160 (3.2%)
    Obese 1,574 (63.0%) 1,530 (61.2%) 3,104 (62.1%)
    Overweight 854 (34.2%) 882 (35.3%) 1,736 (34.7%)
    Unknown 0 0 0
Hemoglobin A1c (%)


0.890
    Mean (SD) 7.7 (0.5) 7.7 (0.5) 7.7 (0.5)
    Median [Q1, Q3] 7.7 [7.3, 8.0] 7.7 [7.3, 8.1] 7.7 [7.3, 8.1]
    Unknown 0 0 0
Sugary drinks per day, n (%)


0.771
    0 200.0 (8.0%) 220.0 (8.8%) 420.0 (8.4%)
    1 1,216.0 (48.6%) 1,225.0 (49.0%) 2,441.0 (48.8%)
    2 844.0 (33.8%) 838.0 (33.5%) 1,682.0 (33.6%)
    3 208.0 (8.3%) 192.0 (7.7%) 400.0 (8.0%)
    4 29.0 (1.2%) 23.0 (0.9%) 52.0 (1.0%)
    5 3.0 (0.1%) 2.0 (0.1%) 5.0 (0.1%)
    Unknown 0 0 0
Charlson comorbidity index


<0.001
    Mean (SD) 3.6 (1.2) 3.4 (1.0) 3.5 (1.1)
    Median [Q1, Q3] 3.3 [2.6, 4.3] 3.2 [2.6, 4.0] 3.2 [2.6, 4.1]
    Unknown 0 0 0
Using metformin, n (%)


0.734
    No 1,212 (48.5%) 1,225 (49.0%) 2,437 (48.7%)
    Yes 1,288 (51.5%) 1,275 (51.0%) 2,563 (51.3%)
    Unknown 0 0 0
1 Welch Two Sample t-test; Pearson’s Chi-squared test