Cognitive Outcomes SMAART II

Author

Samuel Blay Nguah MD

Published

March 29, 2024

Data cleaning

Code
library(tidyverse)
gtsummary::theme_gtsummary_compact()

df_temp <- 
    readxl::read_xlsx(
        "Cognitive Outcomes Analysis_SMAART_Blay_03012024.xlsx"
        ) %>% 
    janitor::clean_names() %>% 
    select(record_id, income_in_usd, nihss_score)

df_cog <- 
    readxl::read_xlsx(
        "Cognitive Outcomes Analysis_SMAART_added_data_24032024.xlsx",
        sheet = "UPDATED_24032024") %>% 
    janitor::clean_names() %>% 
    left_join(df_temp) %>% 
    rename(
        study_arm = randomization_arm,
        domicile = type_of_domicile, 
        gender = gender_0,
        ageyrs = baseline_age,
        anti_dm = anti_diabetics_v2,
        bmi = bmi_kg_m2_baseline,
        sbp = systolic_blood_pressure_mm,
        dbp = diastolic_blood_pressure_m,
        hba1c_0 = hba1c_baseline,
        totchol = total_cholesterol_mmol_l,
        moca_0 = moca_month_0_19,
        moca_6 = moca_month_6,
        moca_12 = moca_month_12_21,
        language_0 = language_month_0,
        language_6 = language_month_6,
        language_12 = language_month_12,
        executive_0 = executive_function_m0, 
        executive_6 = executive_function_m6,
        executive_12 = executive_function_m12,
        memory_0 = memory_m0,
        memory_6 = memory_m6,
        memory_12 = memory_m12,
        visuospatial_0 = visuospatial_score_m0 ,
        visuospatial_6 = visuospatial_score_m6,
        visuospatial_12 = visuospatial_score_m12,
        vci_0 = vci_categories_m0,
        vci_6 = vci_categories_m6,
        vci_12 = vci_categories_m12,
        hamd_0 = hamd_total_m0_108,
        hamd_6 = hamd_total_m6,
        hamd_12 = hamd_total_m12_109,
        cca_0 = baseline_av_cca,
        cca_12 = m12_average_cca,
        totchol_0 = total_cholesterol_mmol_baseline,
        hdl_0 = hdl_cholesterol_mmol_baseline,
        ldl_0 = ldl_cholesterol_mmol_baseline,
        trigly_0 = triglycerides_mmol_baseline,
        creatinine_0 = creatinine_umol_baseline,
        urine_prot_0 = urine_protein_umol_l,
        egfr_0 = egfr_baseline,
        ast = aspartate_transaminase,
        alt = alanine_transaminase,
        fbs_1 = fasting_blood_sugar_mmol_l_month_1,
        rbs_1 = random_blood_sugar_mmol_l_month_1,
        fbs_3 = fasting_blood_sugar_mmol_l_month_3,
        rbs_3 = random_blood_sugar_mmol_l_month_3,
        fbs_6 = fasting_blood_sugar_mmol_l_month_6,
        rbs_6 = random_blood_sugar_mmol_l_month_6,
        fbs_9 = fasting_blood_sugar_mmol_l_month_9,
        rbs_9 = random_blood_sugar_mmol_l_month_9,
        fbs_12 = fasting_blood_sugar_mmol_l_month_12,
        rbs_12 = random_blood_sugar_mmol_l_month_12,
        totchol_12 = total_cholesterol_mmol_l_month_12, 
        hdl_12 = hdl_cholesterol_mmol_l_month_12,
        ldl_12 = ldl_cholesterol_mmol_l_month_12,
        trigly_12 = triglycerides_mmol_l_month_12,
        creatinine_12 = creatinine_umol_l_month_12,
        sbp_0 = systolic_blood_pressure_mm_baseline,
        dbp_0 = diastolic_blood_pressure_m_baseline,
        pulse_0 = pulse_beats_min_baseline, 
        sbp_1 = systolic_blood_pressure_mm_hg_month_1,
        dbp_1 = diastolic_blood_pressure_mm_hg_month_1,
        pulse_1 = pulse_beats_min_month_1,
        sbp_3 = systolic_blood_pressure_mm_month_3,
        dbp_3 = diastolic_blood_pressure_mm_hg_month_3,
        pulse_3 = pulse_beats_min_month_3,
        sbp_6 = systolic_blood_pressure_mm_hg_month_6,
        dbp_6 = diastolic_blood_pressure_mm_hg_month_6,
        pulse_6 = pulse_beats_min_month_6,
        sbp_9 = systolic_blood_pressure_mm_hg_month_9,
        dbp_9 = diastolic_blood_pressure_mm_hg_month_9,
        pulse_9 = pulse_beats_min_month_9,
        sbp_12 = systolic_blood_pressure_mm_hg_month_12,
        dbp_12 = diastolic_blood_pressure_mm_hg_month_12,
        pulse_12 = pulse_beats_min_month_12,
        whr_0 = waist_to_hip_ratio_baselin
        ) %>% 
    mutate(
        study_arm = toupper(study_arm),
        study_arm = case_when(
            study_arm == "USUAL CARED" ~ "Usual Care",
            study_arm == "POLY  PILL" ~ "Poly Pill",
            study_arm == "USUAL CARE" ~ "Usual Care"
            ),
        domicile = factor(domicile, labels = list("1"="Non-Urban", "2"="Urban")),
        gender = factor(gender, labels = list("0" =  "Female", "1" = "Male")),
        income = case_when(income_in_usd >=3 ~ 3, TRUE ~ income_in_usd) %>% factor(),
        marital_status = factor(
            marital_status, 
            labels = list(
                "0" = "Never married", "1" = "Married", "2" = "Separated", 
                "3" = "Widow/Widower", "4" = "Cohabiting",  "5" = "Divorced")),
        formal_education = factor(
            formal_education, 
            labels = list(
                "0" = "None", "1" = "Primary", "2" = "Secondary", 
                "3" = "Tertiary", "4" = "Postgraduate")),
        religion = factor(
            religion, labels = list("0" = "Christianity", "1" = "Islam")),
        alcohol_use = factor(
            alcohol_use, 
            labels = list(
                "1" = "Never used", "2" = "Past 12 months", 
                "3" = "Formerly used", "4" = "Currently uses", 
                "5" = "Past 30 days")),
        tobacco_use = factor(
            tobacco_use, 
            levels = 1:4,
            labels = list(
                "1" = "Formerly used", "2" = "Stopped after stroke", 
                "3" = "Currently uses", "4" = "Never used")),
        smoke = case_when(
            tobacco_use == "Never used" ~ "No",
            TRUE ~"Yes") %>% factor(),
        anti_dm = factor(anti_dm, labels = list("0" = "No", "1" = "Yes")),
        female = gender == "Female",
        moca_diff_0_6 = moca_6 - moca_0,
        moca_diff_0_12 = moca_12 - moca_0,
        moca_diff_6_12 = moca_12 - moca_6,
        language_diff_0_6 = language_6 - language_0,
        language_diff_0_12 = language_12 - language_0,
        language_diff_6_12 = language_12 - language_6,
        executive_diff_0_6 = executive_6 - executive_0,
        executive_diff_0_12 = executive_12 - executive_0,
        executive_diff_6_12 = executive_12 - executive_6,
        memory_diff_0_6 = memory_6 - memory_0,
        memory_diff_0_12 = memory_12 - memory_0,
        memory_diff_6_12 = memory_12 - memory_6,
        visuospatial_diff_0_6 = visuospatial_6 - visuospatial_0,
        visuospatial_diff_0_12 = visuospatial_12 - visuospatial_0,
        visuospatial_diff_6_12 = visuospatial_12 - visuospatial_6,
        aggregated_0 = language_0 + executive_0 + memory_0 + visuospatial_0,
        aggregated_6 = language_6 + executive_6 + memory_6 + visuospatial_6,
        aggregated_12 = language_12 + executive_12 + memory_12 + visuospatial_12,
        aggregated_0_12 = aggregated_12 - aggregated_0,
        urban = case_when(
            domicile=="Urban" ~ "Yes",  domicile == "Non-Urban" ~ "No"
            ),
        obesity = case_when(bmi>30 ~ "Yes", bmi <= 30 ~ "No")
        ) %>% 
    select(-c(vital_signs_complete, laboratory_data_complete, 
              urine_protein_umol_l_2, creatinine_umol_l_2)
        ) %>% 
    mutate(
        age10 = ageyrs/10, 
        alcohol = case_when(
            alcohol_use ==  "Never used" ~ "No",
            TRUE ~ "Yes"
            ) %>% factor(),
        bmi_5 = bmi/5,
        sbp_10 = sbp/10,
        dbp_10 = dbp/10
        )

#------------------------------ Labelling data ---------------------------------

labelled::var_label(df_cog) <- 
    list(
        ageyrs = "Age (years)",
        female = "Female",
        income_in_usd = "Monthly Income",
        formal_education = "Educational status",
        bmi = "Body mass index",
        whr_0 = "Waist-to-hip",
        sbp = "Systolic BP",
        dbp = "Diastolic BP",
        totchol = "Total cholesterol",
        hba1c_0 = "Glycated hemoglobin",
        moca_0 = "Baseline",
        moca_diff_0_6 = "Month 6 from baseline",
        moca_diff_0_12 = "Month 12 from baseline",
        moca_diff_6_12 = "Month 12 from Month 6",
        language_0 = "Baseline",
        language_diff_0_6 = "Month 6 from baseline",
        language_diff_0_12 = "Month 12 from baseline",
        language_diff_6_12 = "Month 12 from Month 6",
        executive_0 = "Baseline",
        executive_diff_0_6 = "Month 6 from baseline",
        executive_diff_0_12 = "Month 12 from baseline",
        executive_diff_6_12 = "Month 12 from Month 6",
        memory_0 = "Baseline",
        memory_diff_0_6 = "Month 6 from baseline",
        memory_diff_0_12 = "Month 12 from baseline",
        memory_diff_6_12 = "Month 12 from Month 6",
        visuospatial_0 = "Baseline",
        visuospatial_diff_0_6 = "Month 6 from baseline",
        visuospatial_diff_0_12 = "Month 12 from baseline",
        visuospatial_diff_6_12 = "Month 12 from Month 6",
        vci_12 = "Month 12",
        urban = "Urban Residence",
        obesity = "Obesity (BMI>30 kg/m2)",
        alcohol = "Currently Alcohol Use"
        )
#---------------------- Generating wide data format ----------------------------

df_wide <- 
    df_cog %>% 
    pivot_longer(
        cols = c(
            language_0, language_6, language_12, executive_0, executive_6, 
            executive_12, visuospatial_0, visuospatial_6, visuospatial_12, 
            memory_0, memory_6, memory_12, aggregated_0, aggregated_6,
            aggregated_12), 
        names_to = c("limit","visit"), 
        names_pattern = "(.*?)(\\d{1,2})$") %>% 
        pivot_wider(
            id_cols = c(record_id, visit, study_arm), 
            names_from = limit, 
            values_from = value, 
            names_repair = "check_unique") %>% 
        mutate(
            visit2 = as.numeric(visit)/12,
            visit = factor(
                visit, 
                levels = c(0, 6, 12), 
                labels = c("Month 0", "Month 6", "Month 12")))

#----------------------------- Generating long data format ---------------------

df_long <-
    df_wide %>% 
    pivot_longer(
        cols = c(language_, executive_, visuospatial_, memory_, aggregated_)
        ) %>% 
    mutate(
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill"))
        )

#-------------------- Generating long data format (0_6_12) ---------------------

df_long_0_6_12_all <- 
    df_cog %>% 
    pivot_longer(cols = c(aggregated_0, aggregated_6, aggregated_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))

#-------------------- Generating long data format (0_6_12) ---------------------

df_long_6_12 <- 
    df_cog %>% 
    pivot_longer(
        cols = c(
            language_6, language_12, executive_6, executive_12, visuospatial_6,
            visuospatial_12, memory_6, memory_12, aggregated_6, aggregated_12
            )
        ) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/6-1,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill"))) 

#----------------- Language domain change over 0-6-12 months -----------------

df_lang_0_6_12 <- 
    df_cog %>% 
    mutate(age10 = ageyrs/10) %>% 
    select(
        age10, female, formal_education, stroke_type, sbp, dbp, alcohol_use, 
        tobacco_use, totchol, hba1c_0, hamd_0, moca_0, 
#        income_in_usd, nihss_score, 
        language_0, language_6, language_12)

Table 4A: Covariate effects on trajectory of combined domains

Code
df_long_0_6_12_all <- 
    df_cog %>% 
    pivot_longer(cols = c(aggregated_0, aggregated_6, aggregated_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))
    
x <- 
    bind_rows(
        nlme::lme(
        value ~ visit*age10, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed"),
        
        nlme::lme(
        value ~ visit*female, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*formal_education, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*stroke_type, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*income, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*smoke, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*alcohol, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*bmi_5, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
       
        nlme::lme(
        value ~ visit*whr_0, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*sbp_10, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*dbp_10, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"), 
        
        nlme::lme(
        value ~ visit*totchol, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hba1c_0, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*nihss_score, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*modified_rankin_scale_m0, 
        random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*study_arm, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*morisky_m0, random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed")
        )
    
y <-  
    nlme::lme(
        value ~ visit*age10 + visit*sbp_10 + visit*nihss_score + 
            visit*modified_rankin_scale_m0 + visit*hamd_0 + visit:study_arm, 
        random = ~visit|record_id, data = df_long_0_6_12_all, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed") %>% 
    rename(
        effect2 = effect, estimate2 = estimate, std.error2 = std.error, 
        df2 = df, statistic2 = statistic, p.value2 = p.value, 
        conf.low2 = conf.low, conf.high2 = conf.high)
        
x %>% 
    left_join(y)%>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value,
           estimate2, conf.low2, conf.high2, p.value2) %>% 
    mutate(
        across(c(estimate:conf.high, estimate2:conf.high2), ~round(.x, 2)),
        across(c(p.value, p.value2), ~round(.x, 3)), 
        Crude_Est. = paste(estimate, "(", conf.low, ", ", conf.high, ")", sep=""),
        Adj_Est. = paste(estimate2, "(", conf.low2, ", ", conf.high2, ")", sep=""),
        Adj_Est. = case_when(Adj_Est. == "NA(NA, NA)" ~ "", TRUE ~ Adj_Est.),
        term = str_remove(term, "visit:")
        ) %>% 
    select(
        term, `Crude Estimate` = Crude_Est., `Crude p-value` = p.value,
        `Adj Estimate` = Adj_Est., `Adj p-value` = p.value2
        ) %>%
    rstatix::p_format(digits = 3, accuracy = 0.001) %>% 
    flextable::flextable(cwidth = 1) %>%
    flextable::width(j=c(2,4), width = 1.6) %>% 
    flextable::theme_vanilla()
Joining with `by = join_by(term)`

term

Crude Estimate

Crude p-value

Adj Estimate

Adj p-value

age10

2.91(0.64, 5.18)

0.013

2.68(0.57, 4.79)

0.015

femaleTRUE

3.6(-1.9, 9.09)

0.201

formal_educationPrimary

3.12(-4.31, 10.55)

0.415

formal_educationSecondary

-3.15(-11.93, 5.62)

0.485

formal_educationTertiary

-8.08(-17.43, 1.26)

0.094

formal_educationPostgraduate

-12.43(-44.31, 19.45)

0.449

stroke_typeSmall vessel

-0.89(-8.44, 6.65)

0.817

stroke_typeUntyped

2.3(-4.4, 8.99)

0.503

income1

-1.71(-10.52, 7.1)

0.705

income2

-2.27(-11.45, 6.92)

0.631

income3

-5.34(-21.76, 11.08)

0.526

smokeYes

-8.13(-25.33, 9.07)

0.355

alcoholYes

-5.11(-10.98, 0.76)

0.089

bmi_5

-2.73(-5.68, 0.23)

0.072

whr_0

-27.11(-66.7, 12.47)

0.181

sbp_10

-1.62(-3.16, -0.08)

0.040

-1.94(-3.38, -0.5)

0.009

dbp_10

-1.04(-3.01, 0.94)

0.305

totchol

1.99(-0.05, 4.02)

0.057

hba1c_0

0.27(-1.12, 1.65)

0.704

nihss_score

1.27(0.47, 2.07)

0.002

1.18(0.12, 2.24)

0.032

modified_rankin_scale_m0

3.83(0.84, 6.82)

0.013

-0.05(-3.8, 3.7)

0.979

hamd_0

0.68(0.01, 1.34)

0.048

0.34(-0.4, 1.07)

0.378

study_armPoly Pill

6.87(1.44, 12.3)

0.014

2.45(-1.17, 6.06)

0.191

morisky_m0

-2.56(-6.61, 1.49)

0.217

Table 4B: Covariate effects on trajectory of language

Code
df_long_0_6_12_lang <- 
    df_cog %>% 
    pivot_longer(cols = c(language_0, language_6, language_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))
    
x <- 
    bind_rows(
        nlme::lme(
        value ~ visit*age10, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed"),
        
        nlme::lme(
        value ~ visit*female, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*formal_education, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*stroke_type, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*income, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*smoke, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*alcohol, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*bmi_5, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
       
        nlme::lme(
        value ~ visit*whr_0, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*sbp_10, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*dbp_10, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"), 
        
        nlme::lme(
        value ~ visit*totchol, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hba1c_0, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*nihss_score, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*modified_rankin_scale_m0, 
        random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*study_arm, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*morisky_m0, random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed")
        )

y <-  
    nlme::lme(
        value ~ visit*age10 + visit*bmi_5 + visit*nihss_score + visit*study_arm, 
        random = ~visit|record_id, data = df_long_0_6_12_lang, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed") %>% 
    rename(
        effect2 = effect, estimate2 = estimate, std.error2 = std.error, 
        df2 = df, statistic2 = statistic, p.value2 = p.value, 
        conf.low2 = conf.low, conf.high2 = conf.high)
        
x %>% 
    left_join(y)%>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value,
           estimate2, conf.low2, conf.high2, p.value2) %>% 
    mutate(
        across(c(estimate:conf.high, estimate2:conf.high2), ~round(.x, 2)),
        across(c(p.value, p.value2), ~round(.x, 3)), 
        Crude_Est. = paste(estimate, "(", conf.low, ", ", conf.high, ")", sep=""),
        Adj_Est. = paste(estimate2, "(", conf.low2, ", ", conf.high2, ")", sep=""),
        Adj_Est. = case_when(Adj_Est. == "NA(NA, NA)" ~ "", TRUE ~ Adj_Est.),
        term = str_remove(term, "visit:")
        ) %>% 
    select(
        term, `Crude Estimate` = Crude_Est., `Crude p-value` = p.value,
        `Adj Estimate` = Adj_Est., `Adj p-value` = p.value2
        ) %>%
    rstatix::p_format(digits = 3, accuracy = 0.001) %>% 
    flextable::flextable(cwidth = 1) %>%
    flextable::width(j=c(2,4), width = 1.6) %>% 
    flextable::theme_vanilla()
Joining with `by = join_by(term)`

term

Crude Estimate

Crude p-value

Adj Estimate

Adj p-value

age10

0.73(0.12, 1.35)

0.020

0.54(-0.03, 1.12)

0.068

femaleTRUE

1.3(-0.18, 2.77)

0.086

formal_educationPrimary

0.28(-1.76, 2.32)

0.790

formal_educationSecondary

-1.04(-3.44, 1.36)

0.400

formal_educationTertiary

-1.59(-4.18, 1)

0.233

formal_educationPostgraduate

-0.5(-9.4, 8.39)

0.913

stroke_typeSmall vessel

-0.27(-2.3, 1.76)

0.795

stroke_typeUntyped

-0.06(-1.86, 1.74)

0.946

income1

-1.07(-3.43, 1.3)

0.379

income2

-1.18(-3.65, 1.29)

0.352

income3

-1.36(-5.82, 3.1)

0.553

smokeYes

0.4(-4.24, 5.03)

0.867

alcoholYes

-1.46(-3.04, 0.11)

0.070

bmi_5

-0.97(-1.76, -0.19)

0.016

-0.41(-1.17, 0.35)

0.298

whr_0

-9.34(-19.97, 1.3)

0.087

sbp_10

-0.37(-0.79, 0.05)

0.089

dbp_10

-0.33(-0.86, 0.2)

0.219

totchol

0.45(-0.11, 1)

0.116

hba1c_0

0.07(-0.31, 0.46)

0.707

nihss_score

0.46(0.25, 0.66)

0.000

0.41(0.2, 0.61)

0.000

modified_rankin_scale_m0

0.78(-0.03, 1.58)

0.061

hamd_0

0.15(-0.03, 0.33)

0.101

study_armPoly Pill

1.88(0.42, 3.34)

0.012

1.56(0.2, 2.91)

0.026

hamd_0

0.15(-0.03, 0.33)

0.101

morisky_m0

-0.65(-1.75, 0.45)

0.251

Table 4C: Covariate effects on trajectory of Memory

Code
df_long_0_6_12_memo <- 
    df_cog %>% 
    pivot_longer(cols = c(memory_0, memory_6, memory_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))
    
x <- 
    bind_rows(
        nlme::lme(
        value ~ visit*age10, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed"),
        
        nlme::lme(
        value ~ visit*female, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*formal_education, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*stroke_type, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*income, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*smoke, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*alcohol, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*bmi_5, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
       
        nlme::lme(
        value ~ visit*whr_0, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*sbp_10, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*dbp_10, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"), 
        
        nlme::lme(
        value ~ visit*totchol, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hba1c_0, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*nihss_score, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*modified_rankin_scale_m0, 
        random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*study_arm, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*morisky_m0, random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed")
    )

y <-  
    nlme::lme(
        value ~ visit*age10 + visit*sbp_10 + visit*totchol + visit*nihss_score +
            visit*modified_rankin_scale_m0 + visit*study_arm, 
        random = ~visit|record_id, data = df_long_0_6_12_memo, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed") %>% 
    rename(
        effect2 = effect, estimate2 = estimate, std.error2 = std.error, 
        df2 = df, statistic2 = statistic, p.value2 = p.value, 
        conf.low2 = conf.low, conf.high2 = conf.high)
        
x %>% 
    left_join(y)%>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value,
           estimate2, conf.low2, conf.high2, p.value2) %>% 
    mutate(
        across(c(estimate:conf.high, estimate2:conf.high2), ~round(.x, 2)),
        across(c(p.value, p.value2), ~round(.x, 3)), 
        Crude_Est. = paste(estimate, "(", conf.low, ", ", conf.high, ")", sep=""),
        Adj_Est. = paste(estimate2, "(", conf.low2, ", ", conf.high2, ")", sep=""),
        Adj_Est. = case_when(Adj_Est. == "NA(NA, NA)" ~ "", TRUE ~ Adj_Est.),
        term = str_remove(term, "visit:")
        ) %>% 
    select(
        term, `Crude Estimate` = Crude_Est., `Crude p-value` = p.value,
        `Adj Estimate` = Adj_Est., `Adj p-value` = p.value2
        ) %>%
    rstatix::p_format(digits = 3, accuracy = 0.001) %>% 
    flextable::flextable(cwidth = 1) %>%
    flextable::width(j=c(2,4), width = 1.6) %>% 
    flextable::theme_vanilla()
Joining with `by = join_by(term)`

term

Crude Estimate

Crude p-value

Adj Estimate

Adj p-value

age10

1.21(0.14, 2.29)

0.027

1.19(0.18, 2.19)

0.023

femaleTRUE

1.95(-0.62, 4.53)

0.139

formal_educationPrimary

0.87(-2.6, 4.35)

0.625

formal_educationSecondary

-2.47(-6.58, 1.63)

0.243

formal_educationTertiary

-4.21(-8.59, 0.17)

0.063

formal_educationPostgraduate

-10.18(-25.14, 4.78)

0.187

stroke_typeSmall vessel

-0.29(-3.83, 3.25)

0.873

stroke_typeUntyped

1.37(-1.77, 4.51)

0.393

income1

-1.11(-5.22, 3.01)

0.600

income2

-2.29(-6.58, 2)

0.299

income3

-5.5(-13.18, 2.19)

0.165

smokeYes

-1.73(-9.86, 6.4)

0.677

alcoholYes

-2.41(-5.17, 0.35)

0.088

bmi_5

-1.23(-2.62, 0.17)

0.086

whr_0

-12.5(-31.16, 6.15)

0.190

sbp_10

-0.74(-1.47, -0.02)

0.045

-0.75(-1.42, -0.07)

0.033

dbp_10

-0.39(-1.32, 0.54)

0.411

totchol

0.97(0.02, 1.93)

0.047

1.05(0.15, 1.96)

0.025

hba1c_0

0.33(-0.31, 0.97)

0.309

nihss_score

0.47(0.1, 0.85)

0.015

0.43(-0.04, 0.9)

0.081

modified_rankin_scale_m0

1.55(0.14, 2.96)

0.033

0.14(-1.63, 1.9)

0.881

hamd_0

0.26(-0.06, 0.57)

0.110

study_armPoly Pill

2.6(0.03, 5.17)

0.049

2.63(0.24, 5.02)

0.035

morisky_m0

-1.42(-3.32, 0.48)

0.145

Table 4D: Covariate effects on trajectory of Visuopospatial

Code
df_long_0_6_12_visu <- 
    df_cog %>% 
    pivot_longer(cols = c(visuospatial_0, visuospatial_6, visuospatial_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))
    
x <- 
    bind_rows(
        nlme::lme(
        value ~ visit*age10, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed"),
        
        nlme::lme(
        value ~ visit*female, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*formal_education, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*stroke_type, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        # nlme::lme(
        # value ~ visit*income, 
        # random = ~visit|record_id, data = df_long_0_6_12_visu, 
        # na.action = na.omit, method = "ML") %>% 
        # broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*smoke, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*alcohol, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*bmi_5, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
       
        nlme::lme(
        value ~ visit*whr_0, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*sbp_10, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*dbp_10, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"), 
        
        nlme::lme(
        value ~ visit*totchol, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        # nlme::lme(
        # value ~ visit*hba1c_0, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        # na.action = na.omit, method = "ML") %>% 
        # broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*nihss_score, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*modified_rankin_scale_m0, 
        random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*study_arm, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*morisky_m0, random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed")
        
        
    )

y <-  
    nlme::lme(
        value ~ visit*modified_rankin_scale_m0 + visit*morisky_m0 + 
            visit*formal_education, 
        random = ~visit|record_id, data = df_long_0_6_12_visu, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed") %>% 
    rename(
        effect2 = effect, estimate2 = estimate, std.error2 = std.error, 
        df2 = df, statistic2 = statistic, p.value2 = p.value, 
        conf.low2 = conf.low, conf.high2 = conf.high)
        
x %>% 
    left_join(y)%>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value,
           estimate2, conf.low2, conf.high2, p.value2) %>% 
    mutate(
        across(c(estimate:conf.high, estimate2:conf.high2), ~round(.x, 2)),
        across(c(p.value, p.value2), ~round(.x, 3)), 
        Crude_Est. = paste(estimate, "(", conf.low, ", ", conf.high, ")", sep=""),
        Adj_Est. = paste(estimate2, "(", conf.low2, ", ", conf.high2, ")", sep=""),
        Adj_Est. = case_when(Adj_Est. == "NA(NA, NA)" ~ "", TRUE ~ Adj_Est.),
        term = str_remove(term, "visit:")
        ) %>% 
    select(
        term, `Crude Estimate` = Crude_Est., `Crude p-value` = p.value,
        `Adj Estimate` = Adj_Est., `Adj p-value` = p.value2
        ) %>%
    rstatix::p_format(digits = 3, accuracy = 0.001) %>% 
    flextable::flextable(cwidth = 1) %>%
    flextable::width(j=c(2,4), width = 1.6) %>% 
    flextable::theme_vanilla()
Joining with `by = join_by(term)`

term

Crude Estimate

Crude p-value

Adj Estimate

Adj p-value

age10

0.3(-0.27, 0.87)

0.298

femaleTRUE

0.57(-0.79, 1.92)

0.414

formal_educationPrimary

-0.86(-2.7, 0.98)

0.365

-0.82(-2.6, 0.95)

0.371

formal_educationSecondary

-1.81(-3.99, 0.38)

0.109

-1.92(-4.05, 0.2)

0.082

formal_educationTertiary

-2.46(-4.77, -0.15)

0.039

-2.27(-4.47, -0.07)

0.048

formal_educationPostgraduate

-3.02(-10.87, 4.83)

0.455

-2.04(-9.52, 5.43)

0.598

stroke_typeSmall vessel

1.51(-0.33, 3.34)

0.110

stroke_typeUntyped

1.56(-0.07, 3.19)

0.063

smokeYes

-1.62(-5.89, 2.64)

0.456

alcoholYes

-0.76(-2.2, 0.69)

0.307

bmi_5

-0.29(-1.02, 0.44)

0.438

whr_0

0.34(-9.38, 10.06)

0.945

sbp_10

-0.26(-0.64, 0.12)

0.181

dbp_10

-0.23(-0.71, 0.26)

0.363

totchol

0.47(-0.04, 0.98)

0.070

nihss_score

0.19(-0.01, 0.39)

0.065

modified_rankin_scale_m0

1.15(0.42, 1.88)

0.002

1.07(0.34, 1.79)

0.005

hamd_0

0.15(-0.01, 0.32)

0.068

study_armPoly Pill

0.55(-0.8, 1.91)

0.424

hamd_0

0.15(-0.01, 0.32)

0.068

morisky_m0

-1.17(-2.15, -0.19)

0.021

-0.91(-1.86, 0.04)

0.065

Table 4E: Covariate effects on trajectory of Executive

Code
df_long_0_6_12_exec <- 
    df_cog %>% 
    pivot_longer(cols = c(executive_0, executive_6, executive_12)) %>% 
    mutate(
        visit = str_extract(name, "\\d+") %>% as.numeric()/12,
        name2 = str_extract(name, "^[a-z]+"),
        study_arm = factor(study_arm, levels = c("Usual Care","Poly Pill")))
    
x <- 
    bind_rows(
        nlme::lme(
        value ~ visit*age10, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed"),
        
        nlme::lme(
        value ~ visit*female, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*formal_education, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*stroke_type, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*income, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*smoke, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*alcohol, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*bmi_5, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
       
        nlme::lme(
        value ~ visit*whr_0, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*sbp_10, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*dbp_10, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"), 
        
        nlme::lme(
        value ~ visit*totchol, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hba1c_0, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*nihss_score, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*modified_rankin_scale_m0, 
        random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*study_arm, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*hamd_0, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed"),
        
        nlme::lme(
        value ~ visit*morisky_m0, random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T, effects="fixed")
        
        
    )

y <-  
    nlme::lme(
        value ~ visit*age10 + visit*formal_education + visit*stroke_type + 
            visit*smoke + visit*study_arm, 
        random = ~visit|record_id, data = df_long_0_6_12_exec, 
        na.action = na.omit, method = "ML") %>% 
        broom.mixed::tidy(conf.int=T,  effects = "fixed") %>% 
    rename(
        effect2 = effect, estimate2 = estimate, std.error2 = std.error, 
        df2 = df, statistic2 = statistic, p.value2 = p.value, 
        conf.low2 = conf.low, conf.high2 = conf.high)
        
x %>% 
    left_join(y)%>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value,
           estimate2, conf.low2, conf.high2, p.value2) %>% 
    mutate(
        across(c(estimate:conf.high, estimate2:conf.high2), ~round(.x, 2)),
        across(c(p.value, p.value2), ~round(.x, 3)), 
        Crude_Est. = paste(estimate, "(", conf.low, ", ", conf.high, ")", sep=""),
        Adj_Est. = paste(estimate2, "(", conf.low2, ", ", conf.high2, ")", sep=""),
        Adj_Est. = case_when(Adj_Est. == "NA(NA, NA)" ~ "", TRUE ~ Adj_Est.),
        term = str_remove(term, "visit:")
        ) %>% 
    select(
        term, `Crude Estimate` = Crude_Est., `Crude p-value` = p.value,
        `Adj Estimate` = Adj_Est., `Adj p-value` = p.value2
        ) %>%
    rstatix::p_format(digits = 3, accuracy = 0.001) %>% 
    flextable::flextable(cwidth = 1) %>%
    flextable::width(j=c(2,4), width = 1.6) %>% 
    flextable::theme_vanilla()
Joining with `by = join_by(term)`

term

Crude Estimate

Crude p-value

Adj Estimate

Adj p-value

age10

0.73(0.1, 1.37)

0.024

0.59(-0.01, 1.2)

0.062

femaleTRUE

-0.03(-1.57, 1.5)

0.966

formal_educationPrimary

3.16(1.13, 5.18)

0.003

3.05(1.11, 4.99)

0.003

formal_educationSecondary

2.18(-0.22, 4.59)

0.079

3.17(0.86, 5.49)

0.009

formal_educationTertiary

0.24(-2.29, 2.77)

0.853

0.97(-1.49, 3.43)

0.451

formal_educationPostgraduate

1.37(-7.21, 9.95)

0.757

3.84(-4.33, 12)

0.368

stroke_typeSmall vessel

-2.1(-4.17, -0.02)

0.049

-1.49(-3.42, 0.44)

0.141

stroke_typeUntyped

-0.68(-2.53, 1.16)

0.471

-0.8(-2.49, 0.9)

0.369

income1

2.17(-0.24, 4.57)

0.080

income2

2.16(-0.35, 4.67)

0.094

income3

2.33(-2.1, 6.77)

0.305

smokeYes

-5.39(-10.13, -0.65)

0.027

-5.65(-10.16, -1.13)

0.017

alcoholYes

-0.61(-2.25, 1.03)

0.466

bmi_5

-0.27(-1.1, 0.56)

0.528

whr_0

-5.58(-16.58, 5.42)

0.321

sbp_10

-0.32(-0.75, 0.1)

0.140

dbp_10

-0.23(-0.78, 0.33)

0.423

totchol

0.02(-0.55, 0.59)

0.944

hba1c_0

0.11(-0.26, 0.48)

0.556

nihss_score

0.2(-0.03, 0.44)

0.086

modified_rankin_scale_m0

0.49(-0.36, 1.33)

0.264

hamd_0

0.14(-0.05, 0.32)

0.152

study_armPoly Pill

2.03(0.52, 3.53)

0.009

1.69(0.28, 3.11)

0.022

hamd_0

0.14(-0.05, 0.32)

0.152

morisky_m0

0.55(-0.57, 1.66)

0.339