Main Paper Analysis

Author

Dr Samuel Blay Nguah

Published

July 4, 2025

Setting and loading packages

Data preparation

Show the code
df_pings2_bp <- 
    dget("pings_2_data_with_bps_ready") %>%
    mutate(
        female = a_gender == "Female", 
        nihss_levcon = str_extract(z_levcon, "^\\d+") %>% as.numeric(),
        nihss_loc_quest = str_extract(z_loc_quest, "^\\d+") %>% as.numeric(), 
        nihss_loc_comm = str_extract(z_loc_comm, "^\\d+") %>% as.numeric(),
        nihss_bestgaze = str_extract(z_bestgaze, "^\\d+") %>% as.numeric(),
        nihss_vfield = str_extract(z_vfield, "^\\d+") %>% as.numeric(),
        nihss_facparesis = str_extract(z_facparesis, "^\\d+") %>% as.numeric(),
        nihss_motor_armr = str_extract(z_motor_armr, "^\\d+") %>% as.numeric(),
        nihss_motor_arml = str_extract(z_motor_arml, "^\\d+") %>% as.numeric(),
        nihss_motor_legr = str_extract(z_motor_legr, "^\\d+") %>% as.numeric(),
        nihss_motor_legl = str_extract(z_motor_legl, "^\\d+") %>% as.numeric(),
        nihss_limbataxia = str_extract(z_limbataxia, "^\\d+") %>% as.numeric(),
        nihss_pinprick = str_extract(z_pinprick, "^\\d+") %>% as.numeric(),
        nihss_bestlang = str_extract(z_bestlang, "^\\d+") %>% as.numeric(),
        nihss_dysarthria = str_extract(z_dysarthria, "^\\d+") %>% as.numeric(),
        nihss_extinction = str_extract(z_extinction, "^\\d+") %>% as.numeric(),
        nihss_scale = nihss_levcon + nihss_loc_quest + nihss_loc_comm + 
            nihss_bestgaze + nihss_vfield + nihss_facparesis + nihss_motor_armr + 
            nihss_motor_arml + nihss_motor_legr + nihss_motor_legl + 
            nihss_limbataxia + nihss_pinprick + nihss_bestlang + 
            nihss_dysarthria + nihss_extinction, 
        ranking = str_extract(x_ranking, "\\d+") %>% as.numeric(), 
        dm = case_when(
            ff_hba1c_0 > 6.5 ~ "Yes",  
            c_dm == "Yes" ~ "Yes",
            h_antidm == "Yes" ~ "Yes", 
            ff_fbs_0 > 7 ~ "Yes",
            eventname == "Baseline" ~ "No"),
        hpt = case_when(
            sbp >= 140 ~ "Yes", 
            dbp >= 90 ~ "Yes",
            sbp <  140 ~ "No",
            dbp <  90 ~ "No") %>%  factor(),
        hyperlipidemia = case_when(
            c_hyperlip == "Yes" ~ "Yes", 
            h_antilipid == "Yes" ~ "Yes",
            ff_totchol_0 > 5.17 ~ "Yes", 
            eventname == "Baseline" ~ "No"),
        tobacco_use = case_when(g_tobacco %in% c(
            "Formerly used tobacco products", 
            "Stopped after the stroke occurred", 
            "Currently uses tobacco products") ~ "Yes",
            g_tobacco == "Never used tobacco products" ~ "No"),
        obese_overwgt = case_when(
            ee_bmi_0 >= 25 ~ "Yes", 
            ee_bmi_0 < 25 ~ "No"),
        alcohol_curr = case_when(
            g_alcohol == "Currently uses alcohol" ~ "Yes",
            g_alcohol %in% c(
                "Never used alcohol", 
                "Past 12 months", 
                "Past 30 days", 
                "Formerly used alcohol", 
                "Stopped after the stroke occured") ~ "No"),
        acei = i_acei_v2 == "Checked",
        arb = i_arb_v2 == "Checked",
        bb = i_bb_v2 == "Checked",
        ccb = i_ccb_v2 == "Checked",
        h_alpha_md = i_alpha_md_v2 == "Checked",
        h_alpha_ab = i_alpha_ab_v2 == "Checked",
        diuretics = i_diuretics_v2 == "Checked",
        h_antiplt = i_antiplt_v2 == "Yes",
        h_statins = i_statins_v2 == "Yes",
        income2 = case_when(
            a_income %in% c("0-100", "101-250", "251-500") ~ "<500 GHc",
            a_income %in% c("501-1500", "1501-3000", "> 3000") ~ ">= 500 GHc"),
        educ2 = case_when(
            a_formeduc %in% c("None", "Primary") ~ "None/Primary",
            a_formeduc %in% c("Secondary", "Tertiary", "Postgraduate") ~ 
                "Secondary or higher"),
        agecat = case_when(a_agebase  < 60 ~ "<60", a_agebase >= 60 ~ ">=60"),
        hosp_cat = case_when(
            datagrp %in% c("CCTH SITE", "KATH SITE", "KORLE-BU SITE") ~ "Tertiary",
            datagrp %in% c(
                "KUMASI SOUTH HOSPITAL", "AGOGO SITE", "KNUST SITE") ~ "Secondary",
            datagrp %in% c(
                "ANKAASE SITE", "MANHYIA GOVT HOSPITAL", "KWADASO SITE", "TAFO SITE") ~ 
              "Primary"), 
        arm = case_when(
            arm == "Arm 1- Intervention Arm" ~ "Intervention", 
            arm == "Arm 2- Routine Care" ~ "Routine"),
        morisky_4_item = (unclass(k_forget) + unclass(k_miss) + 
            unclass(k_fine) + unclass(k_doctor)), 
        across(
            c(l_forget, l_decide, l_salty, l_shake, l_fasfood, l_appoint, 
            l_missched, l_prescrip, l_runout, l_skipmed, l_feelbet,
            l_feelsick, l_someone, l_careless), 
            .fns = ~factor(.x),
            .names = "{.col}_unclassed"),
        across(
            c(l_forget_unclassed, l_decide_unclassed, l_salty_unclassed, 
              l_shake_unclassed, l_fasfood_unclassed, l_appoint_unclassed, 
            l_missched_unclassed, l_prescrip_unclassed, l_runout_unclassed, 
            l_skipmed_unclassed, l_feelbet_unclassed, l_feelsick_unclassed, 
            l_someone_unclassed, l_careless_unclassed), 
            .fns = ~unclass(.x)),
        hillbone = (
            l_forget_unclassed + l_decide_unclassed + l_salty_unclassed + 
            l_shake_unclassed + l_fasfood_unclassed + l_appoint_unclassed + 
            l_missched_unclassed + l_prescrip_unclassed + 
            l_runout_unclassed + l_skipmed_unclassed + l_feelbet_unclassed + 
            l_feelsick_unclassed + l_someone_unclassed + l_careless_unclassed) %>%  
            as.numeric(),
        aa_bp_115_75_corrrect = ifelse(
            aa_bp_115_75 == "Normal", "Yes", "No"),
        aa_bp160_100_correct = ifelse(
            aa_bp160_100 == "High", "Yes", "No"),
        aa_hptlasts_correct = ifelse(
            aa_hptlasts == "The Rest of their Life", "Yes", "No"),
        aa_hptmeds_correct = ifelse(aa_hptmeds == "Everyday", "Yes", "No"),
        aa_losewght_correct = ifelse(aa_losewght == "Go Down", "Yes", "No"),
        aa_eatsalt_correct = ifelse(aa_eatsalt == "Go Down", "Yes", "No"),
        aa_hrtattack_correct = ifelse(aa_hrtattack == "Yes", "Yes", "No"),
        aa_cancer_correct = ifelse(aa_cancer == "No", "Yes", "No"),
        aa_stroke_correct = ifelse(aa_stroke == "Yes", "Yes", "No"),
        aa_kidneyp_correct = ifelse(aa_kidneyp == "Yes", "Yes", "No"),
        aa_highrisk_correct = ifelse(aa_highrisk == "Yes", "Yes", "No"),
        aa_headache_correct = ifelse(aa_headache == "No", "Yes", "No"),
        aa_feelgood_correct = ifelse(aa_feelgood == "Never", "Yes", "No"),
        aa_strokeris_correct = ifelse(
            aa_strokeris == "The Rest of Their Life", "Yes", "No"),
        aa_hkq = (aa_bp_115_75_corrrect == "Yes") + 
            (aa_bp160_100_correct == "Yes") +
            (aa_hptlasts_correct =="Yes") + 
            (aa_hptmeds_correct == "Yes") + 
            (aa_losewght_correct == "Yes") + 
            (aa_eatsalt_correct == "Yes") + 
            (aa_hrtattack_correct == "Yes") + 
            (aa_cancer_correct == "Yes") + 
            (aa_stroke_correct == "Yes") + 
            (aa_kidneyp_correct == "Yes") + 
            (aa_highrisk_correct == "Yes") + 
            (aa_headache_correct =="Yes") + 
            (aa_feelgood_correct =="Yes") + 
            (aa_strokeris_correct == "Yes"),
        mobility = case_when(
            str_detect(
                p_mobility , "I have no problems in walking about") ~ "1",
            str_detect(
                p_mobility , "I have some problems in walking about") ~ "2",
            str_detect(
                p_mobility , "I am confined to bed") ~ "3")%>% 
            as.numeric(),
        selfcare = case_when(
            str_detect(
                p_selfcare , "I have no problems with self-care") ~ "1",
            str_detect(
                p_selfcare , "I have some problems with washing or") ~ "2",
            str_detect(
                p_selfcare , "I am unable to wash or dress myself") ~ "3")%>%
            as.numeric(),
        usual_act = case_when(
            str_detect(
                p_usual_act , "I have no problems with performing my") ~ "1",
            str_detect(
                p_usual_act , "I have some problems with performing") ~ "2",
            str_detect(
                p_usual_act , "I am unable to perform my usual activitie") ~
                "3")%>% 
            as.numeric(),
        pain_disc = case_when(
            str_detect(p_pain_disc , "I have no pain or discomfort") ~ "1",
            str_detect(
                p_pain_disc , "I have moderate pain or discomfort") ~ "2",
            str_detect(
                p_pain_disc , "I have extreme pain or discomfort") ~ "3") %>%
            as.numeric(),
        anxiety = case_when(
            str_detect(p_anxiety, "I am not anxious or depressed") ~ "1",
            str_detect(
                p_anxiety, "I am moderately anxious or depressed") ~ "2",
            str_detect(
                p_anxiety, "I am extremely anxious or depressed") ~ "3")%>% 
            as.numeric(),
        eq_5d = mobility + selfcare + usual_act + pain_disc + anxiety,
         p_health = ifelse(p_health <= 1, p_health*100, p_health), 
        across(
            c(bb_physical, bb_nutfacts, bb_repsalt, bb_limsalt, bb_tabsalt, 
              bb_eatsfood, 
            bb_broilst, bb_rsfoods, bb_rephfat, bb_totcal, bb_eatveges, 
            bb_alcohol, 
            bb_smoking, bb_bpathome, bb_fbpmeds, bb_takemeds, bb_wgtdown, 
            bb_monitst, 
            bb_streslow, bb_doctor, bb_physical2, bb_nutfacts2, bb_repsalt2, 
            bb_limsalt2, 
            bb_tabsalt2, bb_eatsfood2, bb_broilst2, bb_rsfoods2, bb_rephfat2, 
            bb_totcal2, 
            bb_eatveges2, bb_alcohol2, bb_smoking2, bb_bpathome2, bb_fbpmeds2,
            bb_takemeds2, 
            bb_wgtdown2, bb_monitst2, bb_streslow2, bb_doctor2, bb_physical3,
            bb_nutfacts3,
            bb_repsalt3, bb_limsalt3, bb_tabsalt3, bb_eatsfood3, bb_broilst3,
            bb_rsfoods3, 
            bb_rephfat3, bb_totcal3, bb_eatveges3, bb_alcohol3, bb_smoking3,
            bb_bpathome3, 
            bb_fbpmeds3, bb_takemeds3, bb_wgtdown3, bb_monitst3, bb_streslow3,
            bb_doctor3), 
            .fns = ~factor(.x),
            .names = "{.col}_unclassed"),
        across(
            c(bb_physical_unclassed, bb_nutfacts_unclassed, bb_repsalt_unclassed, 
              bb_limsalt_unclassed, bb_tabsalt_unclassed, bb_eatsfood_unclassed, 
            bb_broilst_unclassed, bb_rsfoods_unclassed, bb_rephfat_unclassed, 
            bb_totcal_unclassed, bb_eatveges_unclassed, bb_alcohol_unclassed, 
            bb_smoking_unclassed, bb_bpathome_unclassed, bb_fbpmeds_unclassed, 
            bb_takemeds_unclassed, bb_wgtdown_unclassed, bb_monitst_unclassed, 
            bb_streslow_unclassed, bb_doctor_unclassed, bb_physical2_unclassed, 
            bb_nutfacts2_unclassed, bb_repsalt2_unclassed, bb_limsalt2_unclassed, 
            bb_tabsalt2_unclassed, bb_eatsfood2_unclassed, bb_broilst2_unclassed, 
            bb_rsfoods2_unclassed, bb_rephfat2_unclassed, bb_totcal2_unclassed, 
            bb_eatveges2_unclassed, bb_alcohol2_unclassed, bb_smoking2_unclassed, 
            bb_bpathome2_unclassed, bb_fbpmeds2_unclassed, bb_takemeds2_unclassed, 
            bb_wgtdown2_unclassed, bb_monitst2_unclassed, bb_streslow2_unclassed, 
            bb_doctor2_unclassed, bb_physical3_unclassed, bb_nutfacts3_unclassed,
            bb_repsalt3_unclassed, bb_limsalt3_unclassed, bb_tabsalt3_unclassed, 
            bb_eatsfood3_unclassed, bb_broilst3_unclassed, bb_rsfoods3_unclassed, 
            bb_rephfat3_unclassed, bb_totcal3_unclassed, bb_eatveges3_unclassed, 
            bb_alcohol3_unclassed, bb_smoking3_unclassed, bb_bpathome3_unclassed, 
            bb_fbpmeds3_unclassed, bb_takemeds3_unclassed, bb_wgtdown3_unclassed, 
            bb_monitst3_unclassed, bb_streslow3_unclassed, bb_doctor3_unclassed), 
            .fns = ~unclass(.x)),
        across(
          c(bb_fbpmeds_unclassed, bb_takemeds_unclassed,
            bb_fbpmeds2_unclassed, bb_takemeds2_unclassed,
            bb_fbpmeds3_unclassed, bb_takemeds3_unclassed), 
          .fns = ~ 0 - .x + 5),
        hpt_self_care = bb_physical_unclassed + bb_nutfacts_unclassed + 
          bb_repsalt_unclassed + 
            bb_limsalt_unclassed + bb_tabsalt_unclassed + bb_eatsfood_unclassed + 
            bb_broilst_unclassed + bb_rsfoods_unclassed + bb_rephfat_unclassed + 
            bb_totcal_unclassed + bb_eatveges_unclassed + bb_alcohol_unclassed + 
            bb_smoking_unclassed + bb_bpathome_unclassed + bb_fbpmeds_unclassed + 
            bb_takemeds_unclassed + bb_wgtdown_unclassed + bb_monitst_unclassed + 
            bb_streslow_unclassed + bb_doctor_unclassed + bb_physical2_unclassed + 
            bb_nutfacts2_unclassed + bb_repsalt2_unclassed + bb_limsalt2_unclassed + 
            bb_tabsalt2_unclassed + bb_eatsfood2_unclassed + bb_broilst2_unclassed + 
            bb_rsfoods2_unclassed + bb_rephfat2_unclassed + bb_totcal2_unclassed + 
            bb_eatveges2_unclassed + bb_alcohol2_unclassed + bb_smoking2_unclassed + 
            bb_bpathome2_unclassed + bb_fbpmeds2_unclassed + bb_takemeds2_unclassed + 
            bb_wgtdown2_unclassed + bb_monitst2_unclassed + bb_streslow2_unclassed + 
            bb_doctor2_unclassed + bb_physical3_unclassed + bb_nutfacts3_unclassed +
            bb_repsalt3_unclassed + bb_limsalt3_unclassed + bb_tabsalt3_unclassed + 
            bb_eatsfood3_unclassed + bb_broilst3_unclassed + bb_rsfoods3_unclassed + 
            bb_rephfat3_unclassed + bb_totcal3_unclassed + bb_eatveges3_unclassed + 
            bb_alcohol3_unclassed + bb_smoking3_unclassed + bb_bpathome3_unclassed + 
            bb_fbpmeds3_unclassed + bb_takemeds3_unclassed + bb_wgtdown3_unclassed + 
            bb_monitst3_unclassed + bb_streslow3_unclassed + bb_doctor3_unclassed, 
        sbp_2 = sbp, 
        dbp_2 = dbp, 
        sbp_baseline = case_when(eventname == "Baseline" ~ sbp),
        dbp_baseline = case_when(eventname == "Baseline" ~ dbp),
        stroke_type = case_when(
          d_st_type == "Ischemic Stroke" ~ "Ischemic",
          d_st_type == "Intracerebral Hemorrhagic Stroke" ~ "Hemorrhagic") %>% 
          factor(),
        hosp_cat2 = case_when(
          hosp_cat %in% c("Primary","Secondary") ~ "Primary/Secondary",
          hosp_cat == "Tertiary" ~ "Tertiary"),
        egfr0 = parse_number(ff_egfr_0),
        egfr0 = ifelse(egfr0 < 1, egfr0*100, egfr0),
        egfr_cat = case_when(egfr0 < 60 ~ "<60", egfr0 >= 60 ~ ">=60"),
        across(
            c(m12_pratio_1, m12_pratio_2, m12_pratio_3, m12_pratio_4, 
            m12_pratio_5, m12_pratio_6, m12_pratio_7, m12_pratio_8), 
              ~parse_number(.)),
        emerg_visit = case_when(
          gg_emerg_0 == "seizure" ~ "Yes",
          gg_emerg_1 == "Stage III HPT" ~ "Yes", 
          gg_emerg_3 %in% c("Seizure","Yes") ~ "Yes", 
          gg_emerg_6 %in%  c("seizure (recurrent stroke)", "YES") ~ "Yes",
          eventname == "Baseline" ~ "No"),
        emerg_visit = emerg_visit == "Yes",
        mpr12 = rowMeans(
          across(
            c(m12_pratio_1, m12_pratio_2, m12_pratio_3, m12_pratio_4, 
              m12_pratio_5, m12_pratio_6, m12_pratio_7, m12_pratio_8)), 
            na.rm=T),
        mpr12 = ifelse(mpr12 < 10, mpr12*10, mpr12),
        mpr12 = ifelse(mpr12 > 200, mpr12/10, mpr12),
        mpr12 = ifelse(mpr12 > 100, 100, mpr12),
        sbp_base_cat = case_when(
          sbp < 160 & eventname == "Baseline" ~ "<160mmHg",
          sbp >= 160 & eventname == "Baseline" ~ ">=160mmHg")) %>% 
      arrange(pid, eventname) %>% 
      group_by(pid) %>% 
      fill(
        sbp_2, dbp_2, arm, sbp_baseline, dbp_baseline, emerg_visit, dm, 
        d_st_type, arm) %>% 
      ungroup() %>% 
      mutate(
          sbp_less_140_itt = sbp_2 < 140, 
          sbp_less_140_pp = sbp < 140, 
          bp_less_140_90_itt = (sbp_2 < 140 & dbp_2 < 90),
          bp_less_140_90_pp = (sbp < 140 & dbp < 90),
          sbp_diff = sbp_baseline - sbp,
          dbp_diff = dbp_baseline - dbp,
          review_no = case_when(
            eventname == "Baseline" & !is.na(sbp) ~ 0,
            eventname == "Month 1"  & !is.na(sbp) ~ 1,
            eventname == "Month 3" & !is.na(sbp) ~ 3,
            eventname == "Month 6"  & !is.na(sbp) ~ 6,
            eventname == "Month 9" & !is.na(sbp) ~ 9,
            eventname == "Month12" & !is.na(sbp) ~ 12)) %>% 
      arrange(pid, eventname) %>% 
      group_by(pid) %>% 
      mutate(
        max_review = max(review_no, na.rm = T),
        completed_study = case_when(
          max_review == 12 ~ "Yes", TRUE ~ "No") %>% factor()) %>% 
      ungroup()
Warning: There were 8 warnings in `mutate()`.
The first warning was:
ℹ In argument: `egfr0 = parse_number(ff_egfr_0)`.
Caused by warning:
! 2 parsing failures.
 row col expected actual
1276  -- a number    N/A
1336  -- a number    N/A
ℹ Run `dplyr::last_dplyr_warnings()` to see the 7 remaining warnings.
Show the code
df_pings2_bp <- 
    df_pings2_bp %>% 
    labelled::set_variable_labels(
            female = "Gender, female",
            d_st_type = "Type of Stroke",
            nihss_scale ="Stroke Severity (NIHSS)",
            ranking = "Modified Ranking Score",
            dm = "Diabetes Mellitus",
            sbp = "Systolic Blood Pressure",
            dbp = "Diastolic Blood Pressure",
            hpt = "Hypertesion",
            hyperlipidemia = "Hyperlipidemia", 
            tobacco_use = "Cigarette smoking", 
            obese_overwgt  = "Overweight & obesity",
            alcohol_curr = "Alcohol use, current", 
            acei = "ACE-Inhibitors",
            arb = "ARB",
            bb = "B-blockers",
            ccb = "Calcium channel blocker",
            diuretics = "Diuretics", 
            female = "Gender, female",
            income2 = "Income level", 
            educ2 = "Educational Level",
            agecat = "Age in years",
            h_alpha_md = "Alpha Methyl Dopa",
            h_alpha_ab = "Alpha Adrenergic Blockers",
            h_antiplt = "Antiplatelets",
            h_statins = "Statins",
            morisky_4_item = "Morisky (4 Items)",
            hillbone = "Total Hillbone Score",
            aa_hkq = "Health Literacy in HPT/stroke",
            eq_5d = "Health Related QoL",
            p_health = "Health Related QoL", 
            hpt_self_care = "Hypertension Self Care", 
            sbp_less_140_itt = "SBP < 140 mmHg at month 12 (ITT)",
            sbp_less_140_pp = "SBP < 140 mmHg at month 12 (PP)", 
            bp_less_140_90_itt = "BP < 140/90 mmHg at month 12 (ITT)", 
            bp_less_140_90_pp = "BP < 140/90 mmHg at month 12 (PP)",
            sbp_diff = "Change in SBP(month 12 from baseline)",
            dbp_diff = "Change in DBP(month 12 from baseline)",
            max_review = "Follow-up period",
            review_no = "Review number",
            completed_study = "Completed Study")

Table 1. Baseline Characteristics of Participants by Study Arm

Show the code
table_1 <- 
    df_pings2_bp %>% 
    filter(eventname == "Baseline") %>% 
    select(
        a_agebase, female,  a_formeduc, a_maristat, a_income, 
        a_religion, d_st_type, nihss_scale, ranking, hpt, dm, 
        hyperlipidemia, tobacco_use, obese_overwgt, alcohol_curr, 
        ff_hba1c_0, sbp, dbp, acei, arb, bb, ccb, diuretics,
        h_alpha_md, h_alpha_ab, h_antiplt, h_statins, morisky_4_item, 
        hillbone, aa_hkq, p_health, completed_study, max_review, arm) %>% 
    gtsummary::tbl_summary(
        by = arm,
        type = list(
          ranking ~ "continuous",
          morisky_4_item ~ "continuous",
          max_review ~ "continuous"),
        statistic = list(
          gtsummary::all_categorical() ~ "{n} ({p})",
          c(a_agebase, sbp, dbp, max_review) ~ "{mean} ({sd})"), 
        missing = "no",
        digits = list(
          c(nihss_scale, ranking, hillbone) ~ 0, 
          ff_hba1c_0 ~ 0,
          gtsummary::all_categorical() ~ c(0,1))
        ) %>% 
    gtsummary::modify_spanning_header(
        gtsummary::all_stat_cols()~"**Study Arm**") %>%
    gtsummary::add_overall(last = TRUE) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3)) %>% 
    gtsummary::bold_labels() %>% 
    gtsummary::bold_p()

table_1
Characteristic
Study Arm
Overall
N = 5001
p-value2
Intervention
N = 2441
Routine
N = 2561
Age in years 58 (11) 58 (12) 58 (11) 0.600
Gender, female 103 (42.2) 116 (45.3) 219 (43.8) 0.485
Level of Formal education


0.177
    None 17 (7.0) 32 (12.5) 49 (9.8)
    Primary 95 (38.9) 108 (42.2) 203 (40.6)
    Secondary 89 (36.5) 76 (29.7) 165 (33.0)
    Tertiary 37 (15.2) 35 (13.7) 72 (14.4)
    Postgraduate 6 (2.5) 5 (2.0) 11 (2.2)
Marital Status


0.510
    Never Married 11 (4.5) 12 (4.7) 23 (4.6)
    Currently Married 164 (67.2) 161 (62.9) 325 (65.0)
    Separated 22 (9.0) 16 (6.3) 38 (7.6)
    Widow/Widower 35 (14.3) 49 (19.1) 84 (16.8)
    Cohabitating 3 (1.2) 5 (2.0) 8 (1.6)
    Divorced 9 (3.7) 13 (5.1) 22 (4.4)
Income Bracket


0.989
    0-100 81 (33.5) 93 (36.5) 174 (35.0)
    101-250 75 (31.0) 75 (29.4) 150 (30.2)
    251-500 54 (22.3) 55 (21.6) 109 (21.9)
    501-1500 22 (9.1) 21 (8.2) 43 (8.7)
    1501-3000 7 (2.9) 8 (3.1) 15 (3.0)
    > 3000 3 (1.2) 3 (1.2) 6 (1.2)
Religion


0.739
    Christianity 221 (90.6) 227 (88.7) 448 (89.6)
    Islam 22 (9.0) 27 (10.5) 49 (9.8)
    Other 1 (0.4) 2 (0.8) 3 (0.6)
Type of Stroke


0.014
    Ischemic Stroke 168 (76.0) 164 (71.6) 332 (73.8)
    Intracerebral Hemorrhagic Stroke 45 (20.4) 58 (25.3) 103 (22.9)
    Ischemic With Hemorrhagic Transformation 8 (3.6) 2 (0.9) 10 (2.2)
    Untyped Stroke (no CT scan available) 0 (0.0) 5 (2.2) 5 (1.1)
Stroke Severity (NIHSS) 3 (0, 7) 3 (0, 8) 3 (0, 8) 0.858
Modified Ranking Score 2 (1, 3) 2 (1, 3) 2 (1, 3) 0.873
Hypertesion 227 (93.0) 242 (94.5) 469 (93.8) 0.487
Diabetes Mellitus 98 (40.2) 71 (27.7) 169 (33.8) 0.003
Hyperlipidemia 82 (33.6) 78 (30.5) 160 (32.0) 0.452
Cigarette smoking 22 (9.3) 23 (9.2) 45 (9.3) 0.963
Overweight & obesity 128 (61.0) 130 (58.8) 258 (59.9) 0.652
Alcohol use, current 28 (11.5) 24 (9.4) 52 (10.4) 0.441
HBA1C (Baseline) 6 (5, 7) 6 (5, 7) 6 (5, 7) 0.075
Systolic Blood Pressure 157 (18) 158 (20) 158 (19) 0.727
Diastolic Blood Pressure 94 (13) 96 (15) 95 (14) 0.117
ACE-Inhibitors 51 (20.9) 65 (25.4) 116 (23.2) 0.235
ARB 115 (47.1) 115 (44.9) 230 (46.0) 0.620
B-blockers 34 (13.9) 29 (11.3) 63 (12.6) 0.380
Calcium channel blocker 200 (82.0) 198 (77.3) 398 (79.6) 0.200
Diuretics 56 (23.0) 48 (18.8) 104 (20.8) 0.247
Alpha Methyl Dopa 21 (8.6) 19 (7.4) 40 (8.0) 0.625
Alpha Adrenergic Blockers 7 (2.9) 7 (2.7) 14 (2.8) 0.927
Antiplatelets 148 (65.2) 151 (63.7) 299 (64.4) 0.738
Statins 176 (76.2) 186 (79.5) 362 (77.8) 0.392
Morisky (4 Items) 8 (7, 8) 8 (7, 8) 8 (7, 8) 0.214
Total Hillbone Score 52 (50, 53) 52 (50, 53) 52 (50, 53) 0.259
Health Literacy in HPT/stroke 9 (7, 10) 8 (5, 10) 8 (6, 10) 0.039
Health Related QoL 70 (50, 83) 70 (50, 80) 70 (50, 80) 0.410
Completed Study 200 (82.0) 210 (82.0) 410 (82.0) 0.985
Follow-up period 10.7 (3.2) 10.3 (3.9) 10.5 (3.6) 0.772
1 Mean (SD); n (%); Median (Q1, Q3)
2 Wilcoxon rank sum test; Pearson’s Chi-squared test; Fisher’s exact test
Show the code
file.remove("table_1.docx")
[1] TRUE
Show the code
table_1 %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_1.docx")

Table 2A: Crude Clinical Outcome Measures

Show the code
table_2A <- 
  df_pings2_bp %>% 
    filter(eventname == "Month12") %>% 
    select(
        arm, sbp_less_140_itt, sbp_less_140_pp, 
        bp_less_140_90_itt, bp_less_140_90_pp,
        sbp, dbp, sbp_diff,  dbp_diff, ) %>% 
    gtsummary::tbl_summary(
        by = arm, 
        label = list(
            sbp ~ "Systolic BP at month 12", 
            dbp ~ "Diastolic BP at month 12"),
        statistic = list(
            gtsummary::all_continuous() ~ "{mean}({sd})",
            gtsummary::all_categorical() ~ "{n} ({p})"),
        missing = "no") %>% 
    gtsummary::bold_labels() %>% 
    gtsummary::add_difference(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3)
    ) %>% 
    gtsummary::bold_p()
    

table_2A
Characteristic Intervention
N = 244
1
Routine
N = 256
1
Difference2 95% CI2 p-value2
SBP < 140 mmHg at month 12 (ITT) 163 (67) 109 (43) 24% 15%, 33% <0.001
SBP < 140 mmHg at month 12 (PP) 141 (71) 94 (45) 26% 16%, 35% <0.001
BP < 140/90 mmHg at month 12 (ITT) 136 (56) 97 (38) 18% 8.8%, 27% <0.001
BP < 140/90 mmHg at month 12 (PP) 119 (60) 86 (41) 19% 8.5%, 29% <0.001
Systolic BP at month 12 138(20) 143(22) -5.5 -9.6, -1.4 0.008
Diastolic BP at month 12 85(13) 87(13) -1.4 -4.0, 1.1 0.271
Change in SBP(month 12 from baseline) 20(24) 14(26) 5.9 1.1, 11 0.016
Change in DBP(month 12 from baseline) 9(16) 9(18) -0.08 -3.3, 3.2 0.959
Abbreviation: CI = Confidence Interval
1 n (%); Mean(SD)
2 2-sample test for equality of proportions with continuity correction; Welch Two Sample t-test
Show the code
file.remove("table_2A.docx")
[1] TRUE
Show the code
table_2A %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_2A.docx")

Table 2A: Adjusted Clinical Outcome Measures

Show the code
table_2A_adj <- 
  df_pings2_bp %>% 
    filter(eventname == "Month12") %>% 
    select(
        arm, sbp_less_140_itt, sbp_less_140_pp, 
        bp_less_140_90_itt, bp_less_140_90_pp,
        sbp, dbp, sbp_diff,  dbp_diff, dm, d_st_type) %>% 
    gtsummary::tbl_summary(
        by = arm, 
        label = list(
            sbp ~ "Systolic BP at month 12", 
            dbp ~ "Diastolic BP at month 12"),
        statistic = list(
            gtsummary::all_continuous() ~ "{mean}({sd})",
            gtsummary::all_categorical() ~ "{n} ({p})"),
        include = c(
          sbp_less_140_itt, sbp_less_140_pp, 
          bp_less_140_90_itt, bp_less_140_90_pp,
          sbp, dbp, sbp_diff,  dbp_diff),
        missing = "no") %>% 
    gtsummary::bold_labels() %>% 
    gtsummary::add_difference(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3), 
        adj.vars = c(dm, d_st_type), 
        test = list(
          gtsummary::all_continuous() ~ "ancova", 
          gtsummary::all_dichotomous() ~ "ancova", 
          gtsummary::all_categorical(FALSE) ~ "ancova")
        ) %>% 
    gtsummary::bold_p()
    

table_2A_adj
Characteristic Intervention
N = 244
1
Routine
N = 256
1
Adjusted Difference2 95% CI2 p-value2
SBP < 140 mmHg at month 12 (ITT) 163 (67) 109 (43) 23% 14%, 32% <0.001
SBP < 140 mmHg at month 12 (PP) 141 (71) 94 (45) 23% 13%, 33% <0.001
BP < 140/90 mmHg at month 12 (ITT) 136 (56) 97 (38) 17% 7.3%, 26% <0.001
BP < 140/90 mmHg at month 12 (PP) 119 (60) 86 (41) 16% 5.8%, 26% 0.002
Systolic BP at month 12 138(20) 143(22) -4.9 -9.2, -0.60 0.026
Diastolic BP at month 12 85(13) 87(13) -1.3 -3.9, 1.4 0.358
Change in SBP(month 12 from baseline) 20(24) 14(26) 5.2 0.10, 10 0.046
Change in DBP(month 12 from baseline) 9(16) 9(18) -0.22 -3.6, 3.1 0.900
Abbreviation: CI = Confidence Interval
1 n (%); Mean(SD)
2 ANCOVA
Show the code
file.remove("table_2A_adj.docx")
[1] TRUE
Show the code
table_2A_adj %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_2A_adj.docx")

Table 2B: Crude Secondary outcomes

Show the code
table_2B <- 
    df_pings2_bp %>% 
    select(
      arm, pid, eventname, hpt_self_care, hillbone, mpr, aa_hkq, 
      emerg_visit, p_health, ranking) %>% 
    filter(eventname == "Month12") %>%  
    full_join(readxl::read_xlsx("temp_info.xlsx")) %>% 
    mutate(
      across(rec_stroke:mace, .fns = ~ifelse(is.na(.x), 0, .x)),
      across(rec_stroke:mace, .fns = ~ifelse(.x == 1, TRUE, FALSE))) %>% 
    gtsummary::tbl_summary(
      include = -c(pid, eventname),
      by = arm,
      type = list(ranking ~ "continuous"),
      digits = list(c(ranking, hillbone) ~ 1),
      statistic = list(gtsummary::all_continuous() ~ "{mean} ({sd})"),
      label = list(
        mpr ~ "Medication Possession Ratio",
        emerg_visit ~ "Cardiovascular ED encounters and rehospitalizations",
        rec_stroke ~ "Recurrent stroke",
        mi ~ "Myocardial infacrtion",
        vasc_death ~ "Vascular deaths",
        all_cause ~ "All-cause mortality",
        mace ~ "MACE")) %>% 
  gtsummary::bold_labels() %>% 
  gtsummary::add_difference()

table_2B
Characteristic Intervention
N = 244
1
Routine
N = 256
1
Difference2 95% CI2 p-value2
Hypertension Self Care 100 (22) 103 (24) -3.5 -8.3, 1.2 0.14
    Unknown 65 68


Total Hillbone Score 51.5 (2.9) 51.2 (3.7) 0.30 -0.34, 0.93 0.4
    Unknown 40 42


Medication Possession Ratio 83 (22) 85 (21) -1.9 -6.4, 2.6 0.4
    Unknown 66 76


Health Literacy in HPT/stroke 10 (2) 9 (2) 0.34 -0.11, 0.78 0.14
    Unknown 44 50


Cardiovascular ED encounters and rehospitalizations 1 (0.4%) 2 (0.8%) -0.37% -2.1%, 1.3% >0.9
Health Related QoL 76 (24) 76 (24) 0.30 -4.4, 5.0 >0.9
    Unknown 39 39


Modified Ranking Score 1.5 (1.3) 1.6 (1.3) -0.07 -0.32, 0.19 0.6
    Unknown 32 34


Recurrent stroke 6 (2.5%) 3 (1.2%) 1.3% -1.5%, 4.0% 0.5
Myocardial infacrtion 0 (0%) 0 (0%) 0.00% 0.00%, 0.00%
Vascular deaths 10 (4.1%) 9 (3.5%) 0.58% -3.2%, 4.3% >0.9
All-cause mortality 14 (5.7%) 14 (5.5%) 0.27% -4.0%, 4.6% >0.9
MACE 16 (6.6%) 12 (4.7%) 1.9% -2.6%, 6.3% 0.5
Abbreviation: CI = Confidence Interval
1 Mean (SD); n (%)
2 Welch Two Sample t-test; 2-sample test for equality of proportions with continuity correction; 2-sample test for equality of proportions without continuity correction
Show the code
file.remove("table_2B.docx")
[1] TRUE
Show the code
table_2B %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_2B.docx")

Table 2B: Adjusted Secondary outcomes

Show the code
table_2B_adj <- 
    df_pings2_bp %>% 
    select(
      arm, pid, eventname, hpt_self_care, hillbone, mpr, aa_hkq, 
      emerg_visit, p_health, ranking, dm, d_st_type) %>% 
    filter(eventname == "Month12") %>%  
    full_join(readxl::read_xlsx("temp_info.xlsx")) %>% 
    mutate(
      across(rec_stroke:mace, .fns = ~ifelse(is.na(.x), 0, .x)),
      across(rec_stroke:mace, .fns = ~ifelse(.x == 1, TRUE, FALSE))) %>% 
    gtsummary::tbl_summary(
      include = -c(pid, eventname),
      by = arm,
      type = list(ranking ~ "continuous"),
      digits = list(c(ranking, hillbone) ~ 1),
      statistic = list(gtsummary::all_continuous() ~ "{mean} ({sd})"),
      label = list(
        mpr ~ "Medication Possession Ratio",
        emerg_visit ~ "Cardiovascular ED encounters and rehospitalizations",
        rec_stroke ~ "Recurrent stroke",
        mi ~ "Myocardial infacrtion",
        vasc_death ~ "Vascular deaths",
        all_cause ~ "All-cause mortality",
        mace ~ "MACE")) %>% 
  gtsummary::bold_labels() %>% 
  gtsummary::add_difference(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3), 
        adj.vars = c(dm, d_st_type), 
        test = list(
          gtsummary::all_continuous() ~ "ancova", 
          gtsummary::all_dichotomous() ~ "ancova", 
          gtsummary::all_categorical(FALSE) ~ "ancova"),
        ) %>% 
    gtsummary::bold_p()

table_2B_adj
Characteristic Intervention
N = 244
1
Routine
N = 256
1
Adjusted Difference2 95% CI2 p-value2
Hypertension Self Care 100 (22) 103 (24) -2.1 -7.1, 2.9 0.411
    Unknown 65 68


Total Hillbone Score 51.5 (2.9) 51.2 (3.7) 0.37 -0.31, 1.0 0.291
    Unknown 40 42


Medication Possession Ratio 83 (22) 85 (21) -2.0 -7.0, 3.0 0.429
    Unknown 66 76


Health Literacy in HPT/stroke 10 (2) 9 (2) 0.33 -0.14, 0.81 0.171
    Unknown 44 50


Cardiovascular ED encounters and rehospitalizations 1 (0.4%) 2 (0.8%) -0.77% -2.3%, 0.75% 0.318
Health Related QoL 76 (24) 76 (24) 1.2 -3.6, 6.1 0.614
    Unknown 39 39


Modified Ranking Score 1.5 (1.3) 1.6 (1.3) -0.12 -0.39, 0.14 0.369
    Unknown 32 34


Diabetes Mellitus 98 (40%) 71 (28%)


Type of Stroke

-0.04

    Ischemic Stroke 168 (76%) 164 (72%)


    Intracerebral Hemorrhagic Stroke 45 (20%) 58 (25%)


    Ischemic With Hemorrhagic Transformation 8 (3.6%) 2 (0.9%)


    Untyped Stroke (no CT scan available) 0 (0%) 5 (2.2%)


    Unknown 23 27


Recurrent stroke 6 (2.5%) 3 (1.2%) 1.9% -0.62%, 4.4% 0.141
Myocardial infacrtion 0 (0%) 0 (0%) 0.00% 0.00%, 0.00%
Vascular deaths 10 (4.1%) 9 (3.5%) 2.0% -1.5%, 5.5% 0.266
All-cause mortality 14 (5.7%) 14 (5.5%) 1.6% -2.5%, 5.8% 0.438
MACE 16 (6.6%) 12 (4.7%) 3.6% -0.61%, 7.7% 0.094
Abbreviation: CI = Confidence Interval
1 Mean (SD); n (%)
2 ANCOVA
Show the code
file.remove("table_2B_adj.docx")
[1] TRUE
Show the code
table_2B_adj %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_2B_adj.docx")

BP visualizations

Show the code
figure_one <- 
    df_pings2_bp %>% 
    select(eventname, arm, sbp_diff, dbp_diff) %>% 
    filter(eventname != "Baseline") %>%
    pivot_longer(cols = c(sbp_diff, dbp_diff)) %>% 
    group_by(eventname, name, arm) %>% 
    reframe(across(value, ~epiDisplay::ci.numeric(.x))) %>% 
    unnest(value) %>% 
    mutate(
        name = case_when(name == "sbp_diff" ~ "SBP", name == "dbp_diff" ~ "DBP")) %>% 
    ggplot(
        aes(
            x = eventname, y = mean, color = arm, fill = arm,
            ymin = lower95ci, ymax = upper95ci)) + 
    geom_errorbar(color = "black",  width = 0.15, position = position_dodge(0.9))+
        geom_col(position = position_dodge(.9)) +
    labs(
        y = "BP Change (mmHg) from Baseline", 
        x = NULL,
        color = NULL,
        fill = NULL)+
    theme_bw()+
#    scale_y_continuous(br = seq(0, 1, 0.2), labels = seq(0, 100, 20))+
    scale_fill_manual(values = c("#70161E","#A4B6AC"))+
    scale_color_manual(values = c("#70161E","#A4B6AC"))+
    theme(
       axis.text.x = element_text(
           angle = 90, hjust = 1, vjust = 0.05, 
           face = "italic"))+
    theme(legend.position = "top")+
    facet_wrap(vars(name), nrow = 1)

figure_one

Show the code
ggsave(width = 7, height = 4, filename = "figure1.jpg",)
ggsave(width = 7, height = 4, filename = "figure1.pdf")
Show the code
figure_two <- 
    df_pings2_bp %>% 
    group_by(eventname, arm) %>% 
    reframe(across(sbp_less_140_pp, ~epiDisplay::ci(.x))) %>% 
    unnest(sbp_less_140_pp) %>% 
    ggplot(
        aes(
            x = eventname, 
            y = probability, 
            ymin = exact.lower95ci, 
            ymax = exact.upper95ci,
            color = arm)) +
    geom_errorbar(
        position = position_dodge2(width = 0.4),
        width = 0.2) +    
    geom_point(
        position = position_dodge2(width = 0.2),
        size = 3)+
        labs(
        x = NULL, 
        y = "Probability (95%CI) of BP < 140mmHg",
        color = NULL
        )+
    theme_bw()+
    scale_color_manual(
        breaks = c("Intervention", "Routine"),
        values = c("#C952B9","dodgerblue")
        )+
    theme(
        legend.position = "inside",
        legend.position.inside = c(0.1, 0.9),
        legend.background = element_rect(color = "black"),
#        axis.text.y = element_markdown(),
        axis.text = element_text(color = "black"),
        panel.grid = element_blank(),
        legend.spacing = unit(0, "pt"), 
        axis.text.x = element_text(size = 11),
        legend.margin = margin(t = 1, b = 2,r = 3, l = 3),
        legend.key.spacing = unit(0, "pt")
        )

figure_two

Show the code
ggsave(width = 7, height = 4, filename = "figure2.jpg",)
ggsave(width = 7, height = 4, filename = "figure2.pdf")

Table 3A: Blood Pressure control (<140/90) at Month 12 by Pre-defined baseline measures (per-protocol)

Show the code
# Create function for risk ratio
riskA <- function(data, bps, grp){
    tblx <- table(data[[bps]], data[[grp]])
    a <- tblx[1,1]
    b <- tblx[2,1]
    c <- tblx[1,2]
    d <- tblx[2,2]
    x <- 
      epiR::epi.2by2(
        c(b, a, d, c), 
        method = "cohort.count", 
        conf.level = 0.95)
    t1 = x$tab[2,4]
    t2 = x$tab[1,4]
    t3 = x$massoc.summary[1,]
    data.frame(
        "Inc_Risk_Intervention" = t1, 
        "Inc_Risk_Routine" = t2, 
        "Risk_Ratio" = t3)
    }

# Create function for interaction p-value
interA <- function(data, bps, grp, var){
    glm.1 <- 
        glm(
        data[[bps]] ~ data[[grp]]*data[[var]], 
        family = binomial(link = "log"))
    t4 <- summary(glm.1)$coefficients[4,4]
    t4 <- data.frame(inteR = t4)
    t4
    }


df_for_table_three <-  
    df_pings2_bp %>% 
    select(
        pid, eventname, a_gender, arm, bp_less_140_90_pp, 
        income2, educ2, agecat, d_st_type, hosp_cat, dm, 
        obese_overwgt, stroke_type, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    arrange(pid, eventname) %>%
    group_by(pid) %>% 
    fill(
        a_gender, arm, income2, educ2, agecat, stroke_type, hosp_cat, 
        dm, obese_overwgt, d_st_type, hosp_cat, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    ungroup() %>% 
    filter(eventname=="Month12") %>% 
    select(-c(pid, eventname)) 


df_first <- 
  bind_rows(
    df_for_table_three %>% 
    select(bp_less_140_90_pp, arm, a_gender, arm) %>% 
    nest(data = - a_gender) %>% 
    mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
    unnest(cols = c(mns)) %>% 
    rename(x = a_gender),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, educ2) %>% 
      nest(data = - educ2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = educ2), 
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, income2) %>% 
      drop_na(income2) %>% 
      nest(data = - income2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = income2),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, dm) %>% 
      drop_na(dm) %>% 
      nest(data = - dm) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = dm),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, obese_overwgt) %>% 
      drop_na(obese_overwgt) %>% 
      nest(data = - obese_overwgt) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = obese_overwgt), 
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, agecat) %>% 
      drop_na(agecat) %>% 
      nest(data = - agecat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = agecat),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, stroke_type) %>% 
      drop_na(stroke_type) %>% 
      nest(data = - stroke_type) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = stroke_type),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, hosp_cat2) %>% 
      drop_na(hosp_cat2) %>% 
      nest(data = - hosp_cat2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = hosp_cat2),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, egfr_cat) %>% 
      drop_na(egfr_cat) %>% 
      nest(data = - egfr_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = egfr_cat),
    
    df_for_table_three %>% 
      select(bp_less_140_90_pp, arm, sbp_base_cat) %>% 
      drop_na(sbp_base_cat) %>% 
      nest(data = - sbp_base_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = sbp_base_cat)
      ) %>% 
  mutate(
    y = c(y = rev(c(4:5,7:8, 10:11, 13:14, 16:17, 19:20, 22:23, 25:26, 28:29, 31:32))),
    rr = paste(
     sprintf("%.2f", Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", Risk_Ratio.upper), 
      ")", sep = ""))
  
df_second <- 
  bind_rows(
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "a_gender"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "educ2"), 
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "income2"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "dm"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "obese_overwgt"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "agecat"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "stroke_type"), 
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "hosp_cat2"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "egfr_cat"),
    interA(df_for_table_three, "bp_less_140_90_pp", "arm", "sbp_base_cat")) %>% 
  mutate(
    y = rev(seq(6,33,3)), 
    x = 4,
    z = 0.00001,
    inteR = sprintf("%.3f", inteR),
    var = c(
      "Sex", "Education Status", "Income", "Diabetes Mellitus",
      "Obese/Over weight", "Age (yrs)", "Stroke Type", "Health Facility",
      "eGFR", "SBP at Baseline"))


df_all_p <- riskA(df_for_table_three, "bp_less_140_90_pp", "arm") 
all_part <- 
  c(df_all_p$Inc_Risk_Intervention, df_all_p$Inc_Risk_Routine, 
    paste(
      sprintf("%.2f", df_all_p$Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", df_all_p$Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", df_all_p$Risk_Ratio.upper), 
      ")", sep = ""))

col1 <- 10^(-5)
col2 <- 10^(-4)
col3 <- 10^(-2.9)
col4 <- 10^(-1.7)
col5 <- 4
row1 <- 36
 
polygon_cords <- 
  riskA(df_for_table_three, "bp_less_140_90_pp", "arm")

p1 <- polygon_cords %>% pull(Risk_Ratio.est)
p2 <- polygon_cords %>% pull(Risk_Ratio.lower)
p3 <- polygon_cords %>% pull(Risk_Ratio.upper)

df_polygon <- 
  data.frame(
    x = c(p1, p2, p1, p3), 
    y = c(2.7, 3.0, 3.3, 3.0))

top_data <- c(
  "Subgroup", "Routine", "Intervention", 
  "Risk (95%CI)", "Risk (95%CI)", 
  "Risk Ratio (95%CI)", 
  "Pre-defined", "P for Interaction")
Show the code
df_first %>% 
  ggplot(aes(x = Risk_Ratio.est, y = y)) + 
  geom_point(size = 2, shape = 15, color = "black")+
  geom_errorbar(
    aes(
      xmin = Risk_Ratio.lower, 
      xmax = Risk_Ratio.upper),
      width=0, linewidth = 0.4,
    color = "black")+
  geom_hline(yintercept = seq(2.5, 33.5, 01), alpha = 0.1, linewidth = 0.3)+
  geom_text(x = -5, hjust = 0, size = 2.5, aes(label = x)) +
  geom_text(x = -4, hjust = 0, size = 2.5, aes(label = Inc_Risk_Intervention)) +
  geom_text(x = -2.9, hjust = 0, size = 2.5, aes(label = Inc_Risk_Routine)) +
  geom_text(x = -1.7, hjust = 0, size = 2.5, aes(label = rr)) +
  geom_segment(
    aes(x = exp(log(1)), xend = exp(log(1)), y = 32.5, yend = 2), 
    inherit.aes = FALSE, 
    linewidth = 0.3)+
  geom_segment(
    aes(x = 0.5, xend = 2, y = 2, yend = 2), 
    inherit.aes = FALSE, linewidth = 0.3)+
  labs(x = NULL, y = NULL)+
  annotate(
    geom = "text", 
    x = c(0.5, 1, 2), y = rep(1.6,3), 
    label = c("0.5","1.0", "2.0"), 
    size = 2.5, fontface = "plain", hjust = 0.5, vjust = 1)+
  annotate(
    "segment",
    x = c(0.5, 1, 2), xend = c(0.5, 1, 2), y = rep(2, 3), 
    yend = rep(1.75, 3),  
    colour = "black", linewidth = 0.3)+
  annotate(
    "segment",
    x = 0.9, xend = 0.4, y = 0.8, yend = 0.8,  
    colour = "black", linewidth = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    "segment",
    x = 1.1, xend = 2.3, y = 0.8, yend = 0.8,  
    colour = "black", size = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    geom = "text", 
    x = 0.9, y = 0.5, 
    label = c("Favours Intervention"), 
    size = 2.5, fontface = "plain", hjust = 1, vjust = 1)+
  annotate(
    geom = "text", 
    x = 1.1, y = 0.5, 
    label = c("Favours Routine"), 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 1)+
  annotate(
    geom = "text", 
    x = c(10^(-4), 10^(-2.9), 10^(-1.7)), 
    y = rep(3,3), 
    label = all_part, 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = 10^(-5), y = 3, label = "All Participants", 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = c(col1,col2, col3, col2, col3,col4, col1, col5), 
    y = c(row1-1, row1, row1, row1-1, row1-1, row1-1, row1-2, row1-1), 
    label = top_data, 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = x, y = y, label = inteR),
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = z, y = y, label = var),
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    "segment",
    x = 1.45, xend = 1.45, y = 32.5, yend = 2.5,  
    colour = "gray45", linewidth = 0.3, linetype = 2)+
  annotate(
    "segment",
    x = c(col2, col3, col1), 
    xend = c(0.0008, 0.01, 0.15), 
    y = c(row1-0.5, row1-0.5, row1-1.5), 
    yend = c(row1-0.5, row1-0.5, row1-1.5),  
    colour = "black", linewidth = 0.4, linetype = 1)+
  geom_polygon(
    data = df_polygon,
    aes(x = x, y = y),
    fill = "red", color = "red")+
  theme_minimal()+
  scale_x_log10(
    expand = c(0.02,0.02), 
    limits = c(0.00001, 15), 
    breaks = c(0.5, 1, 2))+
  scale_y_continuous(
    limits = c(0, 37),
    expand = c(0,0))+
  theme(
    panel.grid = element_blank(),
    axis.text = element_blank(),
    axis.line = element_blank(),
    text = element_text(family ='serif'))

Show the code
ggsave(width = 7, height = 5.5, filename = "table3A.jpg",)
ggsave(width = 7, height = 5.5, filename = "table3A.pdf")

Table 3B: Blood Pressure control (sbp < 140) at Month 12 by Pre-defined baseline measures (per-Protocol)

Show the code
# Create function for risk ratio
riskA <- function(data, bps, grp){
    tblx <- table(data[[bps]], data[[grp]])
    a <- tblx[1,1]
    b <- tblx[2,1]
    c <- tblx[1,2]
    d <- tblx[2,2]
    x <- 
      epiR::epi.2by2(
        c(b, a, d, c), 
        method = "cohort.count", 
        conf.level = 0.95)
    t1 = x$tab[2,4]
    t2 = x$tab[1,4]
    t3 = x$massoc.summary[1,]
    data.frame(
        "Inc_Risk_Intervention" = t1, 
        "Inc_Risk_Routine" = t2, 
        "Risk_Ratio" = t3)
    }

# Create function for interaction p-value
interA <- function(data, bps, grp, var){
    glm.1 <- 
        glm(
        data[[bps]] ~ data[[grp]]*data[[var]], 
        family = binomial(link = "log"))
    t4 <- summary(glm.1)$coefficients[4,4]
    t4 <- data.frame(inteR = t4)
    t4
}

#-----------------------------------------------

df_for_table_three <-  
    df_pings2_bp %>% 
    select(
        pid, eventname, a_gender, arm, sbp_less_140_pp, 
        income2, educ2, agecat, d_st_type, hosp_cat, dm, 
        obese_overwgt, stroke_type, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    arrange(pid, eventname) %>%
    group_by(pid) %>% 
    fill(
        a_gender, arm, income2, educ2, agecat, stroke_type, hosp_cat, 
        dm, obese_overwgt, d_st_type, hosp_cat, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    ungroup() %>% 
    filter(eventname=="Month12") %>% 
    select(-c(pid, eventname)) 

df_first <- 
  bind_rows(
    df_for_table_three %>% 
    select(sbp_less_140_pp, arm, a_gender, arm) %>% 
    nest(data = - a_gender) %>% 
    mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
    unnest(cols = c(mns)) %>% 
    rename(x = a_gender),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, educ2) %>% 
      nest(data = - educ2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = educ2), 
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, income2) %>% 
      drop_na(income2) %>% 
      nest(data = - income2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = income2),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, dm) %>% 
      drop_na(dm) %>% 
      nest(data = - dm) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = dm),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, obese_overwgt) %>% 
      drop_na(obese_overwgt) %>% 
      nest(data = - obese_overwgt) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = obese_overwgt), 
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, agecat) %>% 
      drop_na(agecat) %>% 
      nest(data = - agecat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = agecat),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, stroke_type) %>% 
      drop_na(stroke_type) %>% 
      nest(data = - stroke_type) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = stroke_type),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, hosp_cat2) %>% 
      drop_na(hosp_cat2) %>% 
      nest(data = - hosp_cat2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = hosp_cat2),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, egfr_cat) %>% 
      drop_na(egfr_cat) %>% 
      nest(data = - egfr_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = egfr_cat),
    
    df_for_table_three %>% 
      select(sbp_less_140_pp, arm, sbp_base_cat) %>% 
      drop_na(sbp_base_cat) %>% 
      nest(data = - sbp_base_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_pp", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = sbp_base_cat)
      ) %>% 
  mutate(
    y = c(y = rev(c(4:5,7:8, 10:11, 13:14, 16:17, 19:20, 22:23, 25:26, 28:29, 31:32))),
    rr = paste(
     sprintf("%.2f", Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", Risk_Ratio.upper), 
      ")", sep = ""))
  
df_second <- 
  bind_rows(
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "a_gender"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "educ2"), 
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "income2"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "dm"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "obese_overwgt"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "agecat"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "stroke_type"), 
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "hosp_cat2"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "egfr_cat"),
    interA(df_for_table_three, "sbp_less_140_pp", "arm", "sbp_base_cat")) %>% 
  mutate(
    y = rev(seq(6,33,3)), 
    x = 4,
    z = 0.00001,
    inteR = sprintf("%.3f", inteR),
    var = c(
      "Sex", "Education Status", "Income", "Diabetes Mellitus",
      "Obese/Over weight", "Age (yrs)", "Stroke Type", "Health Facility",
      "eGFR", "SBP at Baseline"))


df_all_p <- riskA(df_for_table_three, "sbp_less_140_pp", "arm") 
all_part <- 
  c(df_all_p$Inc_Risk_Intervention, df_all_p$Inc_Risk_Routine, 
    paste(
      sprintf("%.2f", df_all_p$Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", df_all_p$Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", df_all_p$Risk_Ratio.upper), 
      ")", sep = ""))

col1 <- 10^(-5)
col2 <- 10^(-4)
col3 <- 10^(-2.9)
col4 <- 10^(-1.7)
col5 <- 4
row1 <- 36
 
polygon_cords <- 
  riskA(df_for_table_three, "sbp_less_140_pp", "arm")

p1 <- polygon_cords %>% pull(Risk_Ratio.est)
p2 <- polygon_cords %>% pull(Risk_Ratio.lower)
p3 <- polygon_cords %>% pull(Risk_Ratio.upper)

df_polygon <- 
  data.frame(
    x = c(p1, p2, p1, p3), 
    y = c(2.7, 3.0, 3.3, 3.0))

top_data <- c(
  "Subgroup", "Routine", "Intervention", 
  "Risk (95%CI)", "Risk (95%CI)", 
  "Risk Ratio (95%CI)", 
  "Pre-defined", "P for Interaction")

#----------------------------------------------------------

df_first %>% 
  ggplot(aes(x = Risk_Ratio.est, y = y)) + 
  geom_point(size = 2, shape = 15, color = "black")+
  geom_errorbar(
    aes(
      xmin = Risk_Ratio.lower, 
      xmax = Risk_Ratio.upper),
      width=0, linewidth = 0.4,
    color = "black")+
  geom_hline(yintercept = seq(2.5, 33.5, 01), alpha = 0.1, linewidth = 0.3)+
  geom_text(x = -5, hjust = 0, size = 2.5, aes(label = x)) +
  geom_text(x = -4, hjust = 0, size = 2.5, aes(label = Inc_Risk_Intervention)) +
  geom_text(x = -2.9, hjust = 0, size = 2.5, aes(label = Inc_Risk_Routine)) +
  geom_text(x = -1.7, hjust = 0, size = 2.5, aes(label = rr)) +
  geom_segment(
    aes(x = exp(log(1)), xend = exp(log(1)), y = 32.5, yend = 2), 
    inherit.aes = FALSE, 
    linewidth = 0.3)+
  geom_segment(
    aes(x = 0.5, xend = 2, y = 2, yend = 2), 
    inherit.aes = FALSE, linewidth = 0.3)+
  labs(x = NULL, y = NULL)+
  annotate(
    geom = "text", 
    x = c(0.5, 1, 2), y = rep(1.6,3), 
    label = c("0.5","1.0", "2.0"), 
    size = 2.5, fontface = "plain", hjust = 0.5, vjust = 1)+
  annotate(
    "segment",
    x = c(0.5, 1, 2), xend = c(0.5, 1, 2), y = rep(2, 3), 
    yend = rep(1.75, 3),  
    colour = "black", linewidth = 0.3)+
  annotate(
    "segment",
    x = 0.9, xend = 0.4, y = 0.8, yend = 0.8,  
    colour = "black", linewidth = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    "segment",
    x = 1.1, xend = 2.3, y = 0.8, yend = 0.8,  
    colour = "black", size = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    geom = "text", 
    x = 0.9, y = 0.5, 
    label = c("Favours Intervention"), 
    size = 2.5, fontface = "plain", hjust = 1, vjust = 1)+
  annotate(
    geom = "text", 
    x = 1.1, y = 0.5, 
    label = c("Favours Routine"), 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 1)+
  annotate(
    geom = "text", 
    x = c(10^(-4), 10^(-2.9), 10^(-1.7)), 
    y = rep(3,3), 
    label = all_part, 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = 10^(-5), y = 3, label = "All Participants", 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = c(col1,col2, col3, col2, col3,col4, col1, col5), 
    y = c(row1-1, row1, row1, row1-1, row1-1, row1-1, row1-2, row1-1), 
    label = top_data, 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = x, y = y, label = inteR),
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = z, y = y, label = var),
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    "segment",
    x = p1, xend = p1, y = 32.5, yend = 2.5,  
    colour = "gray45", linewidth = 0.3, linetype = 2)+
  annotate(
    "segment",
    x = c(col2, col3, col1), 
    xend = c(0.0008, 0.01, 0.15), 
    y = c(row1-0.5, row1-0.5, row1-1.5), 
    yend = c(row1-0.5, row1-0.5, row1-1.5),  
    colour = "black", linewidth = 0.4, linetype = 1)+
  geom_polygon(
    data = df_polygon,
    aes(x = x, y = y),
    fill = "red", color = "red")+
  theme_minimal()+
  scale_x_log10(
    expand = c(0.02,0.02), 
    limits = c(0.00001, 15), 
    breaks = c(0.5, 1, 2))+
  scale_y_continuous(
    limits = c(0, 37),
    expand = c(0,0))+
  theme(
    panel.grid = element_blank(),
    axis.text = element_blank(),
    axis.line = element_blank(),
    text = element_text(family ='serif'))

Show the code
ggsave(width = 7, height = 5.5, filename = "table3B.jpg",)
ggsave(width = 7, height = 5.5, filename = "table3B.pdf")

Table 3C: Blood Pressure control (sbp < 140/90) at Month 12 by Pre-defined baseline measures (Intention to treat)

Show the code
riskA <- function(data, bps, grp){
    tblx <- table(data[[bps]], data[[grp]])
    a <- tblx[1,1]
    b <- tblx[2,1]
    c <- tblx[1,2]
    d <- tblx[2,2]
    x <- 
      epiR::epi.2by2(
        c(b, a, d, c), 
        method = "cohort.count", 
        conf.level = 0.95)
    t1 = x$tab[2,4]
    t2 = x$tab[1,4]
    t3 = x$massoc.summary[1,]
    data.frame(
        "Inc_Risk_Intervention" = t1, 
        "Inc_Risk_Routine" = t2, 
        "Risk_Ratio" = t3)
    }

# Create function for interaction p-value
interA <- function(data, bps, grp, var){
    glm.1 <- 
        glm(
        data[[bps]] ~ data[[grp]]*data[[var]], 
        family = binomial(link = "log"))
    t4 <- summary(glm.1)$coefficients[4,4]
    t4 <- data.frame(inteR = t4)
    t4
    }


df_for_table_three <-  
    df_pings2_bp %>% 
    select(
        pid, eventname, a_gender, arm, bp_less_140_90_itt, 
        income2, educ2, agecat, d_st_type, hosp_cat, dm, 
        obese_overwgt, stroke_type, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    arrange(pid, eventname) %>%
    group_by(pid) %>% 
    fill(
        a_gender, arm, income2, educ2, agecat, stroke_type, hosp_cat, 
        dm, obese_overwgt, d_st_type, hosp_cat, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    ungroup() %>% 
    filter(eventname=="Month12") %>% 
    select(-c(pid, eventname)) 


df_first <- 
  bind_rows(
    df_for_table_three %>% 
    select(bp_less_140_90_itt, arm, a_gender, arm) %>% 
    nest(data = - a_gender) %>% 
    mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
    unnest(cols = c(mns)) %>% 
    rename(x = a_gender),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, educ2) %>% 
      nest(data = - educ2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = educ2), 
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, income2) %>% 
      drop_na(income2) %>% 
      nest(data = - income2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = income2),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, dm) %>% 
      drop_na(dm) %>% 
      nest(data = - dm) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = dm),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, obese_overwgt) %>% 
      drop_na(obese_overwgt) %>% 
      nest(data = - obese_overwgt) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = obese_overwgt), 
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, agecat) %>% 
      drop_na(agecat) %>% 
      nest(data = - agecat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = agecat),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, stroke_type) %>% 
      drop_na(stroke_type) %>% 
      nest(data = - stroke_type) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = stroke_type),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, hosp_cat2) %>% 
      drop_na(hosp_cat2) %>% 
      nest(data = - hosp_cat2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = hosp_cat2),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, egfr_cat) %>% 
      drop_na(egfr_cat) %>% 
      nest(data = - egfr_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = egfr_cat),
    
    df_for_table_three %>% 
      select(bp_less_140_90_itt, arm, sbp_base_cat) %>% 
      drop_na(sbp_base_cat) %>% 
      nest(data = - sbp_base_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "bp_less_140_90_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = sbp_base_cat)
      ) %>% 
  mutate(
    y = c(y = rev(c(4:5,7:8, 10:11, 13:14, 16:17, 19:20, 22:23, 25:26, 28:29, 31:32))),
    rr = paste(
     sprintf("%.2f", Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", Risk_Ratio.upper), 
      ")", sep = ""))
  
df_second <- 
  bind_rows(
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "a_gender"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "educ2"), 
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "income2"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "dm"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "obese_overwgt"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "agecat"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "stroke_type"), 
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "hosp_cat2"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "egfr_cat"),
    interA(df_for_table_three, "bp_less_140_90_itt", "arm", "sbp_base_cat")) %>% 
  mutate(
    y = rev(seq(6,33,3)), 
    x = 4,
    z = 0.00001,
    inteR = sprintf("%.3f", inteR),
    var = c(
      "Sex", "Education Status", "Income", "Diabetes Mellitus",
      "Obese/Over weight", "Age (yrs)", "Stroke Type", "Health Facility",
      "eGFR", "SBP at Baseline"))


df_all_p <- riskA(df_for_table_three, "bp_less_140_90_itt", "arm") 
all_part <- 
  c(df_all_p$Inc_Risk_Intervention, df_all_p$Inc_Risk_Routine, 
    paste(
      sprintf("%.2f", df_all_p$Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", df_all_p$Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", df_all_p$Risk_Ratio.upper), 
      ")", sep = ""))

col1 <- 10^(-5)
col2 <- 10^(-4)
col3 <- 10^(-2.9)
col4 <- 10^(-1.7)
col5 <- 4
row1 <- 36
 
polygon_cords <- 
  riskA(df_for_table_three, "bp_less_140_90_itt", "arm")

p1 <- polygon_cords %>% pull(Risk_Ratio.est)
p2 <- polygon_cords %>% pull(Risk_Ratio.lower)
p3 <- polygon_cords %>% pull(Risk_Ratio.upper)

df_polygon <- 
  data.frame(
    x = c(p1, p2, p1, p3), 
    y = c(2.7, 3.0, 3.3, 3.0))

top_data <- c(
  "Subgroup", "Routine", "Intervention", 
  "Risk (95%CI)", "Risk (95%CI)", 
  "Risk Ratio (95%CI)", 
  "Pre-defined", "P for Interaction")

#----------------------------------------------------------

df_first %>% 
  ggplot(aes(x = Risk_Ratio.est, y = y)) + 
  geom_point(size = 2, shape = 15, color = "black")+
  geom_errorbar(
    aes(
      xmin = Risk_Ratio.lower, 
      xmax = Risk_Ratio.upper),
      width=0, linewidth = 0.4,
    color = "black")+
  geom_hline(yintercept = seq(2.5, 33.5, 01), alpha = 0.1, linewidth = 0.3)+
  geom_text(x = -5, hjust = 0, size = 2.5, aes(label = x)) +
  geom_text(x = -4, hjust = 0, size = 2.5, aes(label = Inc_Risk_Intervention)) +
  geom_text(x = -2.9, hjust = 0, size = 2.5, aes(label = Inc_Risk_Routine)) +
  geom_text(x = -1.7, hjust = 0, size = 2.5, aes(label = rr)) +
  geom_segment(
    aes(x = exp(log(1)), xend = exp(log(1)), y = 32.5, yend = 2), 
    inherit.aes = FALSE, 
    linewidth = 0.3)+
  geom_segment(
    aes(x = 0.5, xend = 2, y = 2, yend = 2), 
    inherit.aes = FALSE, linewidth = 0.3)+
  labs(x = NULL, y = NULL)+
  annotate(
    geom = "text", 
    x = c(0.5, 1, 2), y = rep(1.6,3), 
    label = c("0.5","1.0", "2.0"), 
    size = 2.5, fontface = "plain", hjust = 0.5, vjust = 1)+
  annotate(
    "segment",
    x = c(0.5, 1, 2), xend = c(0.5, 1, 2), y = rep(2, 3), 
    yend = rep(1.75, 3),  
    colour = "black", linewidth = 0.3)+
  annotate(
    "segment",
    x = 0.9, xend = 0.4, y = 0.8, yend = 0.8,  
    colour = "black", linewidth = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    "segment",
    x = 1.1, xend = 2.3, y = 0.8, yend = 0.8,  
    colour = "black", size = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    geom = "text", 
    x = 0.9, y = 0.5, 
    label = c("Favours Intervention"), 
    size = 2.5, fontface = "plain", hjust = 1, vjust = 1)+
  annotate(
    geom = "text", 
    x = 1.1, y = 0.5, 
    label = c("Favours Routine"), 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 1)+
  annotate(
    geom = "text", 
    x = c(10^(-4), 10^(-2.9), 10^(-1.7)), 
    y = rep(3,3), 
    label = all_part, 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = 10^(-5), y = 3, label = "All Participants", 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = c(col1,col2, col3, col2, col3,col4, col1, col5), 
    y = c(row1-1, row1, row1, row1-1, row1-1, row1-1, row1-2, row1-1), 
    label = top_data, 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = x, y = y, label = inteR),
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = z, y = y, label = var),
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    "segment",
    x = p1, xend = p1, y = 32.5, yend = 2.5,  
    colour = "gray45", linewidth = 0.3, linetype = 2)+
  annotate(
    "segment",
    x = c(col2, col3, col1), 
    xend = c(0.0008, 0.01, 0.15), 
    y = c(row1-0.5, row1-0.5, row1-1.5), 
    yend = c(row1-0.5, row1-0.5, row1-1.5),  
    colour = "black", linewidth = 0.4, linetype = 1)+
  geom_polygon(
    data = df_polygon,
    aes(x = x, y = y),
    fill = "red", color = "red")+
  theme_minimal()+
  scale_x_log10(
    expand = c(0.02,0.02), 
    limits = c(0.00001, 15), 
    breaks = c(0.5, 1, 2))+
  scale_y_continuous(
    limits = c(0, 37),
    expand = c(0,0))+
  theme(
    panel.grid = element_blank(),
    axis.text = element_blank(),
    axis.line = element_blank(),
    text = element_text(family ='serif'))

Show the code
ggsave(width = 7, height = 5.5, filename = "table3C.jpg",)
ggsave(width = 7, height = 5.5, filename = "table3C.pdf")

Table 3D: Blood Pressure control (sbp < 140) at Month 12 by Pre-defined baseline measures (Intention to treat)

Show the code
riskA <- function(data, bps, grp){
    tblx <- table(data[[bps]], data[[grp]])
    a <- tblx[1,1]
    b <- tblx[2,1]
    c <- tblx[1,2]
    d <- tblx[2,2]
    x <- 
      epiR::epi.2by2(
        c(b, a, d, c), 
        method = "cohort.count", 
        conf.level = 0.95)
    t1 = x$tab[2,4]
    t2 = x$tab[1,4]
    t3 = x$massoc.summary[1,]
    data.frame(
        "Inc_Risk_Intervention" = t1, 
        "Inc_Risk_Routine" = t2, 
        "Risk_Ratio" = t3)
    }

# Create function for interaction p-value
interA <- function(data, bps, grp, var){
    glm.1 <- 
        glm(
        data[[bps]] ~ data[[grp]]*data[[var]], 
        family = binomial(link = "log"))
    t4 <- summary(glm.1)$coefficients[4,4]
    t4 <- data.frame(inteR = t4)
    t4
}

#-----------------------------------------------

df_for_table_three <-  
    df_pings2_bp %>% 
    select(
        pid, eventname, a_gender, arm, sbp_less_140_itt, 
        income2, educ2, agecat, d_st_type, hosp_cat, dm, 
        obese_overwgt, stroke_type, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    arrange(pid, eventname) %>%
    group_by(pid) %>% 
    fill(
        a_gender, arm, income2, educ2, agecat, stroke_type, hosp_cat, 
        dm, obese_overwgt, d_st_type, hosp_cat, hosp_cat2, egfr0, 
        egfr_cat, sbp_base_cat) %>% 
    ungroup() %>% 
    filter(eventname=="Month12") %>% 
    select(-c(pid, eventname)) 

df_first <- 
  bind_rows(
    df_for_table_three %>% 
    select(sbp_less_140_itt, arm, a_gender, arm) %>% 
    nest(data = - a_gender) %>% 
    mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
    unnest(cols = c(mns)) %>% 
    rename(x = a_gender),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, educ2) %>% 
      nest(data = - educ2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = educ2), 
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, income2) %>% 
      drop_na(income2) %>% 
      nest(data = - income2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = income2),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, dm) %>% 
      drop_na(dm) %>% 
      nest(data = - dm) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = dm),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, obese_overwgt) %>% 
      drop_na(obese_overwgt) %>% 
      nest(data = - obese_overwgt) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = obese_overwgt), 
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, agecat) %>% 
      drop_na(agecat) %>% 
      nest(data = - agecat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = agecat),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, stroke_type) %>% 
      drop_na(stroke_type) %>% 
      nest(data = - stroke_type) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = stroke_type),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, hosp_cat2) %>% 
      drop_na(hosp_cat2) %>% 
      nest(data = - hosp_cat2) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = hosp_cat2),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, egfr_cat) %>% 
      drop_na(egfr_cat) %>% 
      nest(data = - egfr_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = egfr_cat),
    
    df_for_table_three %>% 
      select(sbp_less_140_itt, arm, sbp_base_cat) %>% 
      drop_na(sbp_base_cat) %>% 
      nest(data = - sbp_base_cat) %>% 
      mutate(mns = map(.x = data, ~riskA(.x, "sbp_less_140_itt", "arm"))) %>% 
      unnest(cols = c(mns)) %>% 
      rename(x = sbp_base_cat)
      ) %>% 
  mutate(
    y = c(y = rev(c(4:5,7:8, 10:11, 13:14, 16:17, 19:20, 22:23, 25:26, 28:29, 31:32))),
    rr = paste(
     sprintf("%.2f", Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", Risk_Ratio.upper), 
      ")", sep = ""))
  
df_second <- 
  bind_rows(
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "a_gender"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "educ2"), 
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "income2"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "dm"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "obese_overwgt"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "agecat"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "stroke_type"), 
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "hosp_cat2"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "egfr_cat"),
    interA(df_for_table_three, "sbp_less_140_itt", "arm", "sbp_base_cat")) %>% 
  mutate(
    y = rev(seq(6,33,3)), 
    x = 4,
    z = 0.00001,
    inteR = sprintf("%.3f", inteR),
    var = c(
      "Sex", "Education Status", "Income", "Diabetes Mellitus",
      "Obese/Over weight", "Age (yrs)", "Stroke Type", "Health Facility",
      "eGFR", "SBP at Baseline"))


df_all_p <- riskA(df_for_table_three, "sbp_less_140_itt", "arm") 
all_part <- 
  c(df_all_p$Inc_Risk_Intervention, df_all_p$Inc_Risk_Routine, 
    paste(
      sprintf("%.2f", df_all_p$Risk_Ratio.est), 
      " (", 
      sprintf("%.2f", df_all_p$Risk_Ratio.lower), 
      " to ",
      sprintf("%.2f", df_all_p$Risk_Ratio.upper), 
      ")", sep = ""))

col1 <- 10^(-5)
col2 <- 10^(-4)
col3 <- 10^(-2.9)
col4 <- 10^(-1.7)
col5 <- 4
row1 <- 36
 
polygon_cords <- 
  riskA(df_for_table_three, "sbp_less_140_itt", "arm")

p1 <- polygon_cords %>% pull(Risk_Ratio.est)
p2 <- polygon_cords %>% pull(Risk_Ratio.lower)
p3 <- polygon_cords %>% pull(Risk_Ratio.upper)

df_polygon <- 
  data.frame(
    x = c(p1, p2, p1, p3), 
    y = c(2.7, 3.0, 3.3, 3.0))

top_data <- c(
  "Subgroup", "Routine", "Intervention", 
  "Risk (95%CI)", "Risk (95%CI)", 
  "Risk Ratio (95%CI)", 
  "Pre-defined", "P for Interaction")
#----------------------------------------------------------

df_first %>% 
  ggplot(aes(x = Risk_Ratio.est, y = y)) + 
  geom_point(size = 2, shape = 15, color = "black")+
  geom_errorbar(
    aes(
      xmin = Risk_Ratio.lower, 
      xmax = Risk_Ratio.upper),
      width=0, linewidth = 0.4,
    color = "black")+
  geom_hline(yintercept = seq(2.5, 33.5, 01), alpha = 0.1, linewidth = 0.3)+
  geom_text(x = -5, hjust = 0, size = 2.5, aes(label = x)) +
  geom_text(x = -4, hjust = 0, size = 2.5, aes(label = Inc_Risk_Intervention)) +
  geom_text(x = -2.9, hjust = 0, size = 2.5, aes(label = Inc_Risk_Routine)) +
  geom_text(x = -1.7, hjust = 0, size = 2.5, aes(label = rr)) +
  geom_segment(
    aes(x = exp(log(1)), xend = exp(log(1)), y = 32.5, yend = 2), 
    inherit.aes = FALSE, 
    linewidth = 0.3)+
  geom_segment(
    aes(x = 0.5, xend = 2, y = 2, yend = 2), 
    inherit.aes = FALSE, linewidth = 0.3)+
  labs(x = NULL, y = NULL)+
  annotate(
    geom = "text", 
    x = c(0.5, 1, 2), y = rep(1.6,3), 
    label = c("0.5","1.0", "2.0"), 
    size = 2.5, fontface = "plain", hjust = 0.5, vjust = 1)+
  annotate(
    "segment",
    x = c(0.5, 1, 2), xend = c(0.5, 1, 2), y = rep(2, 3), 
    yend = rep(1.75, 3),  
    colour = "black", linewidth = 0.3)+
  annotate(
    "segment",
    x = 0.9, xend = 0.4, y = 0.8, yend = 0.8,  
    colour = "black", linewidth = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    "segment",
    x = 1.1, xend = 2.3, y = 0.8, yend = 0.8,  
    colour = "black", size = 0.5,
    arrow = arrow(length = unit(0.15, "cm"), type = "closed"))+
  annotate(
    geom = "text", 
    x = 0.9, y = 0.5, 
    label = c("Favours Intervention"), 
    size = 2.5, fontface = "plain", hjust = 1, vjust = 1)+
  annotate(
    geom = "text", 
    x = 1.1, y = 0.5, 
    label = c("Favours Routine"), 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 1)+
  annotate(
    geom = "text", 
    x = c(10^(-4), 10^(-2.9), 10^(-1.7)), 
    y = rep(3,3), 
    label = all_part, 
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = 10^(-5), y = 3, label = "All Participants", 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    geom = "text", 
    x = c(col1,col2, col3, col2, col3,col4, col1, col5), 
    y = c(row1-1, row1, row1, row1-1, row1-1, row1-1, row1-2, row1-1), 
    label = top_data, 
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = x, y = y, label = inteR),
    size = 2.5, fontface = "plain", hjust = 0, vjust = 0.5)+
  geom_text(
    data = df_second,
    aes(x = z, y = y, label = var),
    size = 2.5, fontface = "bold", hjust = 0, vjust = 0.5)+
  annotate(
    "segment",
    x = p1, xend = p1, y = 32.5, yend = 2.5,  
    colour = "gray45", linewidth = 0.3, linetype = 2)+
  annotate(
    "segment",
    x = c(col2, col3, col1), 
    xend = c(0.0008, 0.01, 0.15), 
    y = c(row1-0.5, row1-0.5, row1-1.5), 
    yend = c(row1-0.5, row1-0.5, row1-1.5),  
    colour = "black", linewidth = 0.4, linetype = 1)+
  geom_polygon(
    data = df_polygon,
    aes(x = x, y = y),
    fill = "red", color = "red")+
  theme_minimal()+
  scale_x_log10(
    expand = c(0.02,0.02), 
    limits = c(0.00001, 15), 
    breaks = c(0.5, 1, 2))+
  scale_y_continuous(
    limits = c(0, 37),
    expand = c(0,0))+
  theme(
    panel.grid = element_blank(),
    axis.text = element_blank(),
    axis.line = element_blank(),
    text = element_text(family ='serif'))

Show the code
ggsave(width = 7, height = 5.5, filename = "table3D.jpg",)
ggsave(width = 7, height = 5.5, filename = "table3D.pdf")

Table 4: Implementation Outcome Measures on Blood Pressure Control Among Participants on PINGS Intervention ITT

Show the code
df_for_table_four <-
    dget("pings_2_data_ltfu") %>% 
    filter(redcap_event_name == "MONTH 9 (Arm 1: PINGSTER)") %>% 
  mutate(
    pid1 = case_when(TRUE~ str_extract(pid, "\\d{3}$")),
    pid2 = case_when(TRUE~ str_extract(pid, "\\d{2}$")),
    pid3 = case_when(TRUE~ str_extract(pid, "\\d{1}$")),
    pid4 = pid1,
    pid4 = ifelse(is.na(pid4), pid2, pid4),
    pid4 = ifelse(is.na(pid4), pid3, pid4),
    pid4 = as.numeric(pid4),
    pid4 = ifelse(pid4 == 933, 33, pid4),
    pid4 = ifelse(pid4 == 305, 5, pid4)) %>% 
    mutate(
      pid_temp = case_when(
        redcap_data_access_group == "AGOGO" ~ "15061",
        redcap_data_access_group == "ANKAASE METHODIST HOSPITAL" ~ "14224",
        redcap_data_access_group == "CCTH" ~ "12878",
        redcap_data_access_group == "KATH" ~ "12875",
        redcap_data_access_group == "KNUST" ~ "12876",
        redcap_data_access_group == "KORLE-BU" ~ "12879",
        redcap_data_access_group == "KUMASI SOUTH HOSPITAL" ~ "13711",
        redcap_data_access_group == "KWADASO" ~ "12880",
        redcap_data_access_group == "Manhyia" ~ "13794",
        redcap_data_access_group == "TAFO" ~ "12877"), 
      pid_final = paste(pid_temp, "-", pid4, sep = ""), 
      pid_final = ifelse(is.na(pid4), NA, pid_final)) %>% 
  datawizard::data_unique(select = pid_final) %>% 
  filter(!is.na(pid_final)) %>% 
  select(
        pid_final, diff, appropriate, acceptability, compliance,
        responsiveness, fidelity, called, frequency,
        redcap_event_name, i_blood_pressure_1systolic) %>%
  rename(pid = pid_final) 
(31 duplicates removed, with method 'best')
Show the code
x <-
  df_pings2_bp %>%
  filter(eventname == "Month12") %>%
  select(sbp_less_140_itt, pid)

df_for_table_four_complete <- 
  full_join(df_for_table_four, x)
Joining with `by = join_by(pid)`
Show the code
table_4 <- 
  df_for_table_four_complete %>% 
  select(-c(pid, redcap_event_name, i_blood_pressure_1systolic)) %>% 
    gtsummary::tbl_summary(
      by = sbp_less_140_itt,
      label = list(
        fidelity ~ "Fidelity measure score",
        appropriate ~ "Appropriateness measure",
        acceptability = "Acceptability measure ",
        compliance = "Compliance measure score",
        responsiveness = "Responsiveness measure",
        diff = "Difficulty to pay",
        frequency ~ "Frequencyof BP checks",
        called = "Called Nurse"), 
      type = list(
        c(appropriate, acceptability, compliance, responsiveness) ~ "continuous"),
      missing = "no") %>% 
  gtsummary::modify_spanning_header(
    gtsummary::all_stat_cols() ~ "**SBP Less than 140mmHg**") %>% 
  gtsummary::add_overall(last = TRUE) %>% 
  gtsummary::add_p() %>% 
  gtsummary::bold_labels() %>% 
  gtsummary::bold_p()
35 missing rows in the "sbp_less_140_itt" column have been removed.
Show the code
table_4
Characteristic
SBP Less than 140mmHg
Overall
N = 5001
p-value2
FALSE
N = 2281
TRUE
N = 2721
Difficulty to pay


0.7
    Very difficult 3 (5.8%) 10 (9.1%) 13 (8.0%)
    Difficult 24 (46%) 57 (52%) 81 (50%)
    Normal 21 (40%) 38 (35%) 59 (36%)
    Easy 4 (7.7%) 5 (4.5%) 9 (5.6%)
    Very easy 0 (0%) 0 (0%) 0 (0%)
Appropriateness measure 17 (16, 20) 17 (16, 20) 17 (16, 20) 0.4
Acceptability measure 17 (16, 20) 17 (16, 20) 17 (16, 20) 0.2
Compliance measure score 19 (17, 20) 20 (17, 20) 19 (17, 20) 0.4
Responsiveness measure 11 (9, 12) 12 (10, 12) 12 (10, 12) 0.14
Fidelity measure score 43.0 (41.0, 50.0) 43.0 (43.0, 48.0) 43.0 (42.0, 48.5) 0.4
Called Nurse 35 (71%) 70 (64%) 105 (66%) 0.4
Frequencyof BP checks


0.10
    Poor 0 (0%) 1 (0.9%) 1 (0.6%)
    Below average 2 (4.3%) 0 (0%) 2 (1.3%)
    Average 2 (4.3%) 9 (8.3%) 11 (7.1%)
    Good 27 (57%) 73 (68%) 100 (65%)
    Excellent 16 (34%) 25 (23%) 41 (26%)
1 n (%); Median (Q1, Q3)
2 Fisher’s exact test; Wilcoxon rank sum test; Pearson’s Chi-squared test
Show the code
file.remove("table_4.docx")
[1] TRUE
Show the code
table_4 %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_4.docx")

Table 4: Implementation Outcome Measures on Blood Pressure Control Among Participants on PINGS Intervention PP

Show the code
df_for_table_four <-
    dget("pings_2_data_ltfu") %>% 
    filter(redcap_event_name == "MONTH 9 (Arm 1: PINGSTER)") %>% 
  mutate(
    pid1 = case_when(TRUE~ str_extract(pid, "\\d{3}$")),
    pid2 = case_when(TRUE~ str_extract(pid, "\\d{2}$")),
    pid3 = case_when(TRUE~ str_extract(pid, "\\d{1}$")),
    pid4 = pid1,
    pid4 = ifelse(is.na(pid4), pid2, pid4),
    pid4 = ifelse(is.na(pid4), pid3, pid4),
    pid4 = as.numeric(pid4),
    pid4 = ifelse(pid4 == 933, 33, pid4),
    pid4 = ifelse(pid4 == 305, 5, pid4)) %>% 
    mutate(
      pid_temp = case_when(
        redcap_data_access_group == "AGOGO" ~ "15061",
        redcap_data_access_group == "ANKAASE METHODIST HOSPITAL" ~ "14224",
        redcap_data_access_group == "CCTH" ~ "12878",
        redcap_data_access_group == "KATH" ~ "12875",
        redcap_data_access_group == "KNUST" ~ "12876",
        redcap_data_access_group == "KORLE-BU" ~ "12879",
        redcap_data_access_group == "KUMASI SOUTH HOSPITAL" ~ "13711",
        redcap_data_access_group == "KWADASO" ~ "12880",
        redcap_data_access_group == "Manhyia" ~ "13794",
        redcap_data_access_group == "TAFO" ~ "12877"), 
      pid_final = paste(pid_temp, "-", pid4, sep = ""), 
      pid_final = ifelse(is.na(pid4), NA, pid_final)) %>% 
  datawizard::data_unique(select = pid_final) %>% 
  filter(!is.na(pid_final)) %>% 
  select(
        pid_final, diff, appropriate, acceptability, compliance,
        responsiveness, fidelity, called, frequency,
        redcap_event_name, i_blood_pressure_1systolic) %>%
  rename(pid = pid_final) 
(31 duplicates removed, with method 'best')
Show the code
x <-
  df_pings2_bp %>%
  filter(eventname == "Month12") %>%
  select(sbp_less_140_pp, pid)

df_for_table_four_complete <- 
  full_join(df_for_table_four, x)
Joining with `by = join_by(pid)`
Show the code
table_4 <- 
  df_for_table_four_complete %>% 
  select(-c(pid, redcap_event_name, i_blood_pressure_1systolic)) %>% 
    gtsummary::tbl_summary(
      by = sbp_less_140_pp,
      label = list(
        fidelity ~ "Fidelity measure score",
        appropriate ~ "Appropriateness measure",
        acceptability = "Acceptability measure ",
        compliance = "Compliance measure score",
        responsiveness = "Responsiveness measure",
        diff = "Difficulty to pay",
        frequency ~ "Frequencyof BP checks",
        called = "Called Nurse"), 
      type = list(c(appropriate, acceptability, compliance, responsiveness) ~ "continuous"),
      missing = "no") %>% 
  gtsummary::modify_spanning_header(
    gtsummary::all_stat_cols() ~ "**SBP Less than 140mmHg**") %>% 
  gtsummary::add_overall(last = TRUE) %>% 
  gtsummary::add_p() %>% 
  gtsummary::bold_labels() %>% 
  gtsummary::bold_p()
125 missing rows in the "sbp_less_140_pp" column have been removed.
Show the code
table_4
Characteristic
SBP Less than 140mmHg
Overall
N = 4101
p-value2
FALSE
N = 1751
TRUE
N = 2351
Difficulty to pay


0.6
    Very difficult 3 (7.3%) 9 (8.7%) 12 (8.3%)
    Difficult 17 (41%) 53 (51%) 70 (49%)
    Normal 18 (44%) 36 (35%) 54 (38%)
    Easy 3 (7.3%) 5 (4.9%) 8 (5.6%)
    Very easy 0 (0%) 0 (0%) 0 (0%)
Appropriateness measure 17 (16, 20) 17 (16, 20) 17 (16, 20) 0.5
Acceptability measure 18 (16, 20) 17 (16, 20) 17 (16, 20) 0.11
Compliance measure score 19 (17, 20) 20 (17, 20) 19 (17, 20) 0.5
Responsiveness measure 11 (9, 12) 12 (10, 12) 12 (10, 12) 0.039
Fidelity measure score 43.5 (41.0, 50.0) 43.0 (42.0, 48.0) 43.0 (42.0, 48.0) 0.6
Called Nurse 27 (69%) 65 (64%) 92 (65%) 0.5
Frequencyof BP checks


0.047
    Poor 0 (0%) 1 (1.0%) 1 (0.7%)
    Below average 2 (5.3%) 0 (0%) 2 (1.4%)
    Average 2 (5.3%) 9 (8.9%) 11 (7.9%)
    Good 20 (53%) 69 (68%) 89 (64%)
    Excellent 14 (37%) 22 (22%) 36 (26%)
1 n (%); Median (Q1, Q3)
2 Fisher’s exact test; Wilcoxon rank sum test; Pearson’s Chi-squared test
Show the code
file.remove("table_4.docx")
[1] TRUE
Show the code
table_4 %>% 
    gtsummary::as_gt() %>% 
    gt::gtsave(filename = "table_4.docx")

Table 5

Show the code
df_for_table_five <- 
    df_pings2_bp  %>%
    select(
    arm, pid, eventname, contains("_med_")) %>% 
    select(-starts_with("j")) %>% 
    arrange(pid, eventname) %>% 
    group_by(pid) %>% 
    fill(arm) %>% 
    ungroup() %>% 
#    mutate(studyid = row_number()) %>% 
    pivot_longer(cols = contains("_med_")) %>% 
    rename(drug = value) %>% 
    mutate(
        drug = toupper(drug),
        hpt_drug_class = case_when(
        drug == " BISOPROLOL" ~ "BB  ",
        drug == " HYDRALAZINE" ~ "VASODILATOR  ",
        drug == " NIFEDIPINE" ~ "CCB  ",
        drug == " NIFEDIPINE " ~ "CCB  ",
        drug == " RAMIPRIL" ~ "ACEI  ",
        drug == "`NIFEDIPINE" ~ "CCB  ",
        drug == "ACETAZOLAMIDE" ~ "DIURETIC  ",
        drug == "ALCDACTONE" ~ "DIURETIC  ",
        drug == "ALDACTONE" ~ "DIURETIC  ",
        drug == "ALDOMET" ~ "DIURETIC  ",
        drug == "AM,ODIPINE" ~ "CCB  ",
        drug == "AMILODIPINE " ~ "CCB  ",
        drug == "AMLODIPINE" ~ "CCB  ",
        drug == "AMLODIPINE " ~ "CCB  ",
        drug == "AMLODIPINE - CALCIUM BLOCKER" ~ "CCB  ",
        drug == "AMLODIPINE - CALCIUM BLOCKER " ~ "CCB  ",
        drug == "AMLODIPINE - CALCIUM BLOCKERS" ~ "CCB  ",
        drug == "AMLODIPINE + VALARSATAN+HTCZ" ~ "CCB ARB DIURETIC",
        drug == "AMLODIPINE EXFORGE" ~ "CCB ARB ",
        drug == "AMLODIPINE/VALSARTAN" ~ "CCB ARB ",
        drug == "AMLODIPINE+ VALSARTAN +HCTZ" ~ "CCB ARB DIURETIC",
        drug == "AMLODIPINE+VALARSATAN+HCTZ" ~ "CCB ARB DIURETIC",
        drug == "AMLODIPINE+VALSATAN +HTCZ" ~ "CCB ARB DIURETIC",
        drug == "AMLODPINE" ~ "CCB  ",
        drug == "AMLOPDIPINE" ~ "CCB  ",
        drug == "AMLOPIDIPINE" ~ "CCB  ",
        drug == "AMLOPIDOGREL" ~ "CCB  ",
        drug == "AMLOPINE" ~ "CCB  ",
        drug == "AMOLODIPINE" ~ "CCB  ",
        drug == "ATACAND" ~ "ARB  ",
        drug == "ATACAND PLUS" ~ "ARB  ",
        drug == "ATACAND PLUS -  ARBS" ~ "ARB  ",
        drug == "ATENELOL" ~ "BB  ",
        drug == "ATENOLO" ~ "BB  ",
        drug == "ATENOLOL" ~ "BB  ",
        drug == "ATENOLOL TABLET" ~ "BB  ",
        drug == "ATORVASTATIN/BENDROFLUMETHIAZIDE" ~ "DIURETIC ARB ",
        drug == "BDFZ" ~ "DIURETIC  ",
        drug == "BDZ" ~ "DIURETIC  ",
        drug == "BEMNDROFLUMETHIAZIDE" ~ "DIURETIC  ",
        drug == "BENDRO" ~ "DIURETIC  ",
        drug == "BENDRO " ~ "DIURETIC  ",
        drug == "BENDROFLOMETAZINE" ~ "DIURETIC  ",
        drug == "BENDROFLUATHAIZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUATHIAZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUAZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHAIZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHAIZIDE " ~ "DIURETIC  ",
        drug == "BENDROFLUMETHAZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIAZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIAZIDE " ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIAZIDE/ASPIRIN" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIAZIE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIOZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUMETHIZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUTHAZIDE" ~ "DIURETIC  ",
        drug == "BENDROFLUZAMETHIAZIDE " ~ "DIURETIC  ",
        drug == "BENDROLUAZIDE" ~ "DIURETIC  ",
        drug == "BFZ" ~ "DIURETIC  ",
        drug == "BISIPROLOL" ~ "BB  ",
        drug == "BISOPROLOL" ~ "BB  ",
        drug == "BISOPROLOL FUMARATE" ~ "BB  ",
        drug == "BISOPROLOL FUMARATE " ~ "BB  ",
        drug == "BISOPRPLOL" ~ "BB  ",
        drug == "BISPROLOL" ~ "BB  ",
        drug == "CARVADILOL" ~ "BB  ",
        drug == "CARVEDILOL" ~ "BB  ",
        drug == "CARVEDILOL " ~ "BB  ",
        drug == "CARVEDILOL  - ANTIHYPERTENSIVE" ~ "BB  ",
        drug == "CARVEDILOL - ANTI HYPERTENSIVE" ~ "BB  ",
        drug == "CARVEDILOL - ANTIHYPERTENSIVE" ~ "BB  ",
        drug == "CARVEDILOL - ANTIHYPERTENSIVE " ~ "BB  ",
        drug == "CARVEDILOL25MG" ~ "BB  ",
        drug == "CARVEDOLOL" ~ "BB  ",
        drug == "FRUSEMIDE" ~ "DIURETIC  ",
        drug == "FURESEMIDE" ~ "DIURETIC  ",
        drug == "FURESEMIND" ~ "DIURETIC  ",
        drug == "FUROSEMIDE" ~ "DIURETIC  ",
        drug == "FUROSEMIDE " ~ "DIURETIC  ",
        drug == "FUROSEMINE" ~ "DIURETIC  ",
        drug == "HYDARLAZINE" ~ "VASODILATOR  ",
        drug == "HYDRALAZINE" ~ "VASODILATOR  ",
        drug == "HYDRALAZINE " ~ "VASODILATOR  ",
        drug == "HYDROCHLOROTHIAZIDE" ~ "DIURETIC  ",
        drug == "HYDROCHLOROTHIAZIDE/ LISINOPRIL" ~ "DIURETIC ACEI ",
        drug == "HYDROCHLORTHIANONE" ~ "DIURETIC  ",
        drug == "HYGRALAZINE" ~ "VASODILATOR  ",
        drug == "HYROCLOTHIAZOLE" ~ "DIURETIC  ",
        drug == "IBESARTAN" ~ "ARB  ",
        drug == "IBESATAN" ~ "ARB  ",
        drug == "INDAPAMIDE" ~ "DIURETIC  ",
        drug == "INDAPAMIDE " ~ "DIURETIC  ",
        drug == "INDAPAMIDE  " ~ "DIURETIC  ",
        drug == "L0SARTAN" ~ "ARB  ",
        drug == "LABETALOL" ~ "BB  ",
        drug == "LASARTAN" ~ "ARB  ",
        drug == "LASIX" ~ "DIURETIC  ",
        drug == "LBETALOL" ~ "BB  ",
        drug == "LIISINOPRIL" ~ "ACEI  ",
        drug == "LISIN0PRIL/HCTZ" ~ "ACEI DIURETIC ",
        drug == "LISINOPREL/HCTZ" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL" ~ "ACEI  ",
        drug == "LISINOPRIL  " ~ "ACEI  ",
        drug == "LISINOPRIL   " ~ "ACEI  ",
        drug == "LISINOPRIL     " ~ "ACEI  ",
        drug == "LISINOPRIL       " ~ "ACEI  ",
        drug == "LISINOPRIL        " ~ "ACEI  ",
        drug == "LISINOPRIL - ANGIOTENSIN" ~ "ACEI  ",
        drug == "LISINOPRIL - ANTIHYPERTENSIVE" ~ "ACEI  ",
        drug == "LISINOPRIL - ANTIHYPERTENSIVE " ~ "ACEI  ",
        drug == "LISINOPRIL + HCTZ" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL + HYDROCHLOROTHIAZIDE" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL HCTZ" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL/HCT" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL/HCTZ" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL/HYDROCHLOROTHIAZIDE" ~ "ACEI DIURETIC ",
        drug == "LISINOPRIL+HYDROCHLOROTHIAZIDE" ~ "ACEI DIURETIC ",
        drug == "LISINOPROL" ~ "ACEI  ",
        drug == "LISINOPROLOL" ~ "ACEI  ",
        drug == "LISISNOPRIL" ~ "ACEI  ",
        drug == "LISNOPRIL" ~ "ACEI  ",
        drug == "LISNOPRILJ" ~ "ACEI  ",
        drug == "LOASRTAN" ~ "ARB  ",
        drug == "LORSATAN" ~ "ARB  ",
        drug == "LOSARTAN" ~ "ARB  ",
        drug == "LOSARTAN " ~ "ARB  ",
        drug == "LOSARTAN  " ~ "ARB  ",
        drug == "LOSARTAN + HYDROCHLOROTHIAZIDE" ~ "ARB DIURETIC ",
        drug == "LOSARTAN + HYDROCHOLORTHIAZIDE" ~ "ARB DIURETIC ",
        drug == "LOSARTAN TABLETS   " ~ "ARB  ",
        drug == "LOSARTAN/HCT" ~ "ARB DIURETIC ",
        drug == "LOSARTEN" ~ "ARB  ",
        drug == "LOSARTSAN" ~ "ARB  ",
        drug == "LOSATAN" ~ "ARB  ",
        drug == "METHLYDOPA" ~ "Methyldopa  ",
        drug == "METHYLDOPA" ~ "Methyldopa  ",
        drug == "METHYLDOPA " ~ "Methyldopa  ",
        drug == "METHYLDOPA   " ~ "Methyldopa  ",
        drug == "METHYLDOPA     " ~ "Methyldopa  ",
        drug == "METHYLDOPA       " ~ "Methyldopa  ",
        drug == "METHYLDOPA        " ~ "Methyldopa  ",
        drug == "METHYLDOPA - ANTI HYPERTENSIVE " ~ "Methyldopa  ",
        drug == "METHYLDOPA - ANTIHYPERTENSIVE" ~ "Methyldopa  ",
        drug == "METHYLDOPA - ANTIHYPERTENSIVE " ~ "Methyldopa  ",
        drug == "METHYLDOPA - HYPERTENSIVE" ~ "Methyldopa  ",
        drug == "MRTHYLDOPA" ~ "Methyldopa  ",
        drug == "NATRILIX" ~ "DIURETIC  ",
        drug == "NATRIX" ~ "DIURETIC  ",
        drug == "NATRIXAM" ~ "CCB  ",
        drug == "NATRIXAM - CALCIUM CHANNEL BLOCKERS" ~ "CCB  ",
        drug == "NEFIDEPINE" ~ "CCB  ",
        drug == "NEFIDIPINE" ~ "CCB  ",
        drug == "NIFECARD" ~ "CCB  ",
        drug == "NIFECARD " ~ "CCB  ",
        drug == "NIFECARD XL" ~ "CCB  ",
        drug == "NIFECARD XR" ~ "CCB  ",
        drug == "NIFECARD-XL" ~ "CCB  ",
        drug == "NIFEDEPINE" ~ "CCB  ",
        drug == "NIFEDFIPINE" ~ "CCB  ",
        drug == "NIFEDIINE" ~ "CCB  ",
        drug == "NIFEDIL XL" ~ "CCB  ",
        drug == "NIFEDIPINE" ~ "CCB  ",
        drug == "NIFEDIPINE " ~ "CCB  ",
        drug == "NIFEDIPINE  " ~ "CCB  ",
        drug == "NIFEDIPINE    " ~ "CCB  ",
        drug == "NIFEDIPINE      " ~ "CCB  ",
        drug == "NIFEDIPINE (NIFECARD XL) " ~ "CCB  ",
        drug == "NIFEDIPINE XR" ~ "CCB  ",
        drug == "NIFEDIPNE" ~ "CCB  ",
        drug == "NIFEDIPNE " ~ "CCB  ",
        drug == "NIFEFIDINE" ~ "CCB  ",
        drug == "NIFICARD" ~ "CCB  ",
        drug == "NIFIDEPINE" ~ "CCB  ",
        drug == "NIFIDIPINE" ~ "CCB  ",
        drug == "NIMODIPINE" ~ "CCB  ",
        drug == "RAMIPRI" ~ "ACEI  ",
        drug == "RAMIPRIL" ~ "ACEI  ",
        drug == "RAMIPRIL " ~ "ACEI  ",
        drug == "RAMIPRIL  " ~ "ACEI  ",
        drug == "RAMIPRIL - ACE INHIBITOR" ~ "ACEI  ",
        drug == "RAMIPRIL   " ~ "ACEI  ",
        drug == "RAMPRIL" ~ "ACEI  ",
        drug == "RARMPRIL" ~ "ACEI  ",
        drug == "SPIRINOLACTONE" ~ "DIURETIC  ",
        drug == "SPIROCLACTONE" ~ "DIURETIC  ",
        drug == "SPIROLACTONE - ALDOSTERONE" ~ "DIURETIC  ",
        drug == "SPIROLACTONE - ALDOSTERONE " ~ "DIURETIC  ",
        drug == "SPIRONDACTONE" ~ "DIURETIC  ",
        drug == "SPIRONOLACTONE" ~ "DIURETIC  ",
        drug == "SPIRONOLACTONE - ALDOSTERONE      " ~ "DIURETIC  ",
        drug == "TA NIFECARD XL" ~ "CCB  ",
        drug == "TA NIFEDIPINE" ~ "CCB  ",
        drug == "TAB AMLODIPINE" ~ "CCB  ",
        drug == "TAB AMLODIPNE" ~ "CCB  ",
        drug == "TAB BENDROFLUAZIDE" ~ "DIURETIC  ",
        drug == "TAB BENDROFLUAZIDE  " ~ "DIURETIC  ",
        drug == "TAB BISOPROLOL" ~ "BB  ",
        drug == "TAB DIHYDROCHLORID" ~ "DIURETIC  ",
        drug == "TAB LISINOPRIL" ~ "ACEI  ",
        drug == "TAB LOARTAN" ~ "ARB  ",
        drug == "TAB LORSARTAN" ~ "ARB  ",
        drug == "TAB LORSATAN" ~ "ARB  ",
        drug == "TAB LOSAR DENK" ~ "ARB  ",
        drug == "TAB LOSARTAN" ~ "ARB  ",
        drug == "TAB LOSARTAN " ~ "ARB  ",
        drug == "TAB METHYLDOPA" ~ "Methyldopa  ",
        drug == "TAB METHYLDOPA " ~ "Methyldopa  ",
        drug == "TAB NIFECARD" ~ "CCB  ",
        drug == "TAB NIFECARD XL" ~ "CCB  ",
        drug == "TAB NIFEDIINE" ~ "CCB  ",
        drug == "TAB NIFEDIPINE" ~ "CCB  ",
        drug == "TAB NIFEMAX SR" ~ "CCB  ",
        drug == "TAB RAMIPRIL" ~ "ACEI  ",
        drug == "TB AFENOLOL" ~ "BB  ",
        drug == "TB AMLODIPINE" ~ "CCB  ",
        drug == "TB ATENOLOL" ~ "BB  ",
        drug == "TB BENDRO" ~ "DIURETIC  ",
        drug == "TB FUROSAMIDE" ~ "DIURETIC  ",
        drug == "TB LASIX" ~ "DIURETIC  ",
        drug == "TB LISINOPRIL" ~ "ACEI  ",
        drug == "TB LOSARTAN" ~ "ARB  ",
        drug == "TB LOSARTEN" ~ "ARB  ",
        drug == "TB METHYLDOPA" ~ "Methyldopa  ",
        drug == "TB NEFIDEPINE" ~ "CCB  ",
        drug == "TB NIFECARD XL" ~ "CCB  ",
        drug == "TB NIFEDDIPINE" ~ "CCB  ",
        drug == "TB NIFEDIPINE" ~ "CCB  ",
        drug == "TB NIFEDIPINE " ~ "CCB  ",
        drug == "TB SPIRONOLACTONE" ~ "DIURETIC  ",
        drug == "TELMISARTAN" ~ "ARB  ",
        drug == "VALSARTAN" ~ "ARB  ",
        drug == "PROPANOLOL" ~ "BB  ",
        drug == "PROPRANOLOL" ~ "BB  ",
        drug == "TAB CARVEDILOL" ~ "BB  ",
        drug == "TAB CAVEDILOL" ~ "BB  ",
        drug == "BNEDROFLUAZIDE" ~ "DIURETIC  ",
        drug == "CANDESARTAN" ~ "ARB  ",
        drug == "CANDESARTAN " ~ "ARB  ",
        drug == "CARDOFINE" ~ "CCB  ",
        drug == "CARDROFIN" ~ "CCB  ",
        drug == "CARVIDILOL" ~ "BB  ",
        drug == "EX FORGE" ~ "ARB CCB ",
        drug == "EX FORGE HCT" ~ "ARB CCB DIURETIC",
        drug == "EXFORGE" ~ "ARB CCB ",
        drug == "EXFORGE HCT" ~ "ARB CCB DIURETIC",
        drug == "EX-FORGE HCT" ~ "ARB CCB DIURETIC",
        drug == "TAB ATACAND" ~ "ARB  ",
        drug == "TAB EXFORGE" ~ "ARB CCB ",
        drug == "HADRALAZINE" ~ "VASODILATOR  ",
        drug == "INDOMAPAMIZE" ~ "DIURETIC  ",
        drug == "MOXONIDIN" ~ "VASODILATOR  ",
        drug == "TRIPLIXAM" ~ "ACEI  ",
        drug == "TRIPLIXAM - ACE INHIBITORS" ~ "ACEI  ",
        drug == "TWYNSTA (AMLODIPINE/VALSARTAN)" ~ "CCB ARB ",
        drug == "TORASEMIDE" ~ "Diuretic  ",
        drug == "COVERSYL PLUS" ~ "Diuretic ARB ",
        drug == "IMPERIO" ~ "ARB  ",
        drug == "NEBIVOLOL" ~ "BB  ",
        drug == "NOVAPRIL" ~ "ACEI  ",
        drug == "RENANGIO PLUS" ~ "CCB ARB "))
      


X <- 
  df_for_table_five %>% 
  mutate(
    acei_2 = case_when(
      str_detect(hpt_drug_class, "ACEI") ~ 1, 
      TRUE ~ 0), 
    arb_2 = case_when(
      str_detect(hpt_drug_class, "ARB") ~ 1, 
      TRUE ~ 0),
    bb_2 = case_when(
      str_detect(hpt_drug_class, "BB") ~ 1, 
      TRUE ~ 0), 
    diuretics_2 = case_when(
      str_detect(hpt_drug_class, "DIURETIC") ~ 1, 
      TRUE ~ 0), 
    h_alpha_md_2 = case_when(
      str_detect(hpt_drug_class, "Methyldopa") ~ 1, 
      TRUE ~ 0),
    ccb_2 = case_when(
      str_detect(hpt_drug_class, "CCB") ~ 1, 
      TRUE ~ 0),
    h_alpha_ab_2 = case_when(
      str_detect(hpt_drug_class, "VASODILATOR") ~ 1, 
      TRUE ~ 0)) %>% 
  select(pid, eventname, ends_with("_2")) %>% 
  group_by(pid, eventname) %>% 
  reframe(across(acei_2:h_alpha_ab_2, ~max(.x))) %>% 
  ungroup()

Y <- 
  df_pings2_bp %>% 
  select(arm, eventname, pid) %>% 
  arrange(pid, eventname) %>% 
  group_by(pid) %>% 
  fill(arm) %>% 
  ungroup() 

month_12 <- 
  df_pings2_bp %>% 
  select(sbp, pid, eventname) %>% 
  filter(eventname == "Month12") %>% 
  filter(is.na(sbp)) %>% 
  pull(pid)

full_join(X, Y) %>%  
  filter(eventname %in% c("Baseline", "Month12")) %>% 
  select(pid, arm, eventname, acei_2:h_alpha_ab_2) %>% 
  mutate(
    acei_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, acei_2), 
    arb_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, arb_2), 
    bb_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, bb_2), 
    ccb_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, ccb_2),
    diuretics_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, diuretics_2), 
    h_alpha_md_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, h_alpha_md_2),
    h_alpha_ab_2 = ifelse(
      (pid %in% month_12) & (eventname == "Month12"), NA, h_alpha_ab_2),
    hpt_total =  
      acei_2 + arb_2 + bb_2 + ccb_2 + diuretics_2 + 
      h_alpha_md_2 + h_alpha_ab_2) %>%

  
  select(-pid) %>% 
  gtsummary::tbl_strata(
    strata = arm, ~.x %>%
    gtsummary::tbl_summary(
      by = eventname, 
      label = list(
        acei_2 ~ "ACE-Inhibitors", 
        arb_2 ~ "Angiotensin Receptor Blockers",
        bb_2 = "Beta blockers",
        ccb_2 = "Calcium channel blocker",
        diuretic_2 = "Diuretics",
        h_alpha_md_2 = "Methyldopa",
        h_alpha_ab_2  = "Alpha Adrenergic Blockers",
        hpt_total = "Number of BP medications"),
      type = list(hpt_total ~ "continuous"),
      statistic = list(hpt_total ~ "{mean} ({sd})")) %>% 
    gtsummary::add_p() %>% 
    gtsummary::bold_labels())
Characteristic
Intervention
Routine
Baseline
N = 2441
Month12
N = 2441
p-value2 Baseline
N = 2561
Month12
N = 2561
p-value2
ACE-Inhibitors 40 (16%) 33 (17%) >0.9 40 (16%) 52 (25%) 0.014
    Unknown 0 44
0 46
Angiotensin Receptor Blockers 135 (55%) 119 (60%) 0.4 120 (47%) 106 (50%) 0.4
    Unknown 0 44
0 46
Beta blockers 39 (16%) 36 (18%) 0.6 27 (11%) 28 (13%) 0.4
    Unknown 0 44
0 46
diuretics_2 58 (24%) 54 (27%) 0.4 55 (21%) 53 (25%) 0.3
    Unknown 0 44
0 46
Methyldopa 17 (7.0%) 12 (6.0%) 0.7 20 (7.8%) 12 (5.7%) 0.4
    Unknown 0 44
0 46
Calcium channel blocker 181 (74%) 165 (83%) 0.035 174 (68%) 175 (83%) <0.001
    Unknown 0 44
0 46
Alpha Adrenergic Blockers 19 (7.8%) 20 (10%) 0.4 13 (5.1%) 13 (6.2%) 0.6
    Unknown 0 44
0 46
Number of BP medications 2.00 (1.18) 2.20 (1.12) 0.12 1.75 (1.20) 2.09 (1.08) 0.001
    Unknown 0 44
0 46
1 n (%); Mean (SD)
2 Pearson’s Chi-squared test; Wilcoxon rank sum test

Multilevel Data analysis

Show the code
df_for_lda <- 
  df_pings2_bp %>% 
  select(
    sbp_less_140_pp, eventname, pid, mpr, arm, hpt_self_care, 
    hillbone, aa_hkq, p_health, ranking, emerg_visit, datagrp) %>% 
  mutate(
    time = parse_number(eventname),
    time = ifelse(eventname == "Baseline", 0, time),
    hillbone = scale(hillbone),
    mpr = scale(mpr),
    hpt_self_care = scale(hpt_self_care),
    aa_hkq = scale(aa_hkq),
    p_health = scale(p_health),
    ranking = scale(ranking)
    )

mod_glmm_arm <- 
  lme4::glmer(
    sbp_less_140_pp ~ arm  + (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_hill <- 
  lme4::glmer(
    sbp_less_140_pp ~ hillbone + (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_self <- 
  lme4::glmer(
    sbp_less_140_pp ~ hpt_self_care + (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_mpr <- 
  lme4::glmer(
    sbp_less_140_pp ~ mpr +  (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_aa_hkq <- 
  lme4::glmer(
    sbp_less_140_pp ~ aa_hkq + datagrp + (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_p_health <- 
  lme4::glmer(
    sbp_less_140_pp ~ p_health +  (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_rank <- 
  lme4::glmer(
    sbp_less_140_pp ~ ranking  + (1 | pid), 
    data = df_for_lda, family = binomial)

mod_glmm_emerg <- 
  lme4::glmer(
    sbp_less_140_pp ~ emerg_visit + (1 | pid), 
    data = df_for_lda, family = binomial)


gtsummary::tbl_stack(
  tbls = list(
    gtsummary::tbl_regression(
      mod_glmm_arm, exponentiate = TRUE, include = arm),
    gtsummary::tbl_regression(
      mod_glmm_hill, exponentiate = TRUE, include = hillbone), 
    gtsummary::tbl_regression(
      mod_glmm_self, exponentiate = TRUE, include = hpt_self_care), 
    gtsummary::tbl_regression(mod_glmm_mpr, exponentiate = TRUE, include = mpr), 
    gtsummary::tbl_regression(
      mod_glmm_aa_hkq, exponentiate = TRUE, include = aa_hkq), 
    gtsummary::tbl_regression(
      mod_glmm_p_health, exponentiate = TRUE, include = p_health),
    gtsummary::tbl_regression(
      mod_glmm_rank, exponentiate = TRUE, include = ranking), 
    gtsummary::tbl_regression(
      mod_glmm_emerg, exponentiate = TRUE, include = emerg_visit))) %>% 
  gtsummary::bold_p()
Characteristic OR 95% CI p-value
arm


    Intervention
    Routine 0.67 0.52, 0.88 0.003
hillbone 1.21 1.08, 1.35 <0.001
hpt_self_care 0.59 0.50, 0.70 <0.001
mpr 1.04 0.90, 1.20 0.6
aa_hkq 1.81 1.55, 2.11 <0.001
p_health 1.39 1.24, 1.57 <0.001
ranking 0.65 0.57, 0.74 <0.001
emerg_visit


    FALSE
    TRUE 1.39 0.21, 9.23 0.7
Abbreviations: CI = Confidence Interval, OR = Odds Ratio