Cognitive Outcomes SMAART

Author

Samuel Blay Nguah MD

Published

March 26, 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 <- 
    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)) %>% 
    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 1: Baseline

Code
df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            ageyrs, female, formal_education, bmi, whr_0, sbp, dbp, totchol,
            hba1c_0, moca_0, moca_6, moca_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})",
            gtsummary::all_categorical()~ "{n} ({p})"
            ),
        digits = list(
            gtsummary::all_continuous()~1,
            gtsummary::all_categorical()~c(0, 1),
            whr_0 ~ 2
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::modify_spanning_header(
        gtsummary::all_stat_cols() ~ "**Randomization Arm**"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
        )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels() %>% 
    gtsummary::modify_caption(
        "Table 1: Comparison of baseline characteristics of study participants"
    )
Table 1: Comparison of baseline characteristics of study participants
Characteristic Overall, N = 1481 Randomization Arm p-value2
Poly Pill, N = 741 Usual Care, N = 741
Age (years) 58.3(12.0) 58.5(10.7) 58.1(13.3) 0.828
Female 74 (50.0) 38 (51.4) 36 (48.6) 0.742
Educational status


0.172
    None 26 (17.6) 11 (14.9) 15 (20.3)
    Primary 70 (47.3) 42 (56.8) 28 (37.8)
    Secondary 30 (20.3) 12 (16.2) 18 (24.3)
    Tertiary 21 (14.2) 9 (12.2) 12 (16.2)
    Postgraduate 1 (0.7) 0 (0.0) 1 (1.4)
Body mass index 25.6(4.7) 25.4(4.3) 25.7(5.1) 0.779
    Missing 2 1 1
Waist-to-hip 0.94(0.07) 0.94(0.07) 0.93(0.07) 0.416
    Missing 2 1 1
Systolic BP 160.9(17.5) 161.3(17.2) 160.4(18.0) 0.769
Diastolic BP 92.3(14.2) 92.0(13.9) 92.6(14.6) 0.800
Total cholesterol 4.3(1.4) 4.3(1.4) 4.3(1.3) 0.923
    Missing 2 1 1
Glycated hemoglobin 6.8(2.2) 6.5(1.7) 7.0(2.5) 0.179
    Missing 15 7 8
Baseline 15.8(6.7) 15.4(7.4) 16.2(5.9) 0.468
moca_6 19.6(5.9) 19.1(6.1) 20.3(5.7) 0.274
    Missing 29 13 16
moca_12 21.4(6.3) 21.2(5.9) 21.6(6.7) 0.720
    Missing 27 15 12
1 Mean(SD); n (%)
2 Welch Two Sample t-test; Pearson’s Chi-squared test; Fisher’s exact test

Table 2: Domain changes

Code
tbl_moca <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            moca_0, moca_diff_0_6, moca_diff_0_12, moca_diff_6_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})"
            ),
        digits = list(
            gtsummary::all_continuous()~1
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::modify_spanning_header(
        gtsummary::all_stat_cols() ~ "**Randomization Arm**"
        ) %>%
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
        )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()


#-------- Language

tbl_language <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            language_0, language_diff_0_6, language_diff_0_12, language_diff_6_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})"
            ),
        digits = list(
            gtsummary::all_continuous()~1
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
        )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()

#--------

tbl_executive <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            executive_0, executive_diff_0_6, executive_diff_0_12, executive_diff_6_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})"
            ),
        digits = list(
            gtsummary::all_continuous()~1
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
        )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()


#-------- Memory

tbl_memory <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            memory_0, memory_diff_0_6, memory_diff_0_12, memory_diff_6_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})"
            ),
        digits = list(
            gtsummary::all_continuous()~1
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
        )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()

#-------- Visuospatial

tbl_visuospatial <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = c(
            visuospatial_0, visuospatial_diff_0_6, visuospatial_diff_0_12, visuospatial_diff_6_12),
        by = study_arm,
        statistic = list(
            gtsummary::all_continuous()~ "{mean}({sd})"
            ),
        digits = list(
            gtsummary::all_continuous()~1
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3),
        test = list(
            gtsummary::all_continuous() ~ "t.test"
            )
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()

#-------- VCI

tbl_vci <- 
    df_cog %>% 
    gtsummary::tbl_summary(
        include = vci_12,
        by = study_arm,
        statistic = list(
            gtsummary::all_categorical()~ "{n}({p})"
            ),
        digits = list(
            gtsummary::all_categorical()~ c(0,1)
            ),
        missing_text = "Missing"
        ) %>% 
    gtsummary::add_p(
        pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3)
        ) %>% 
    gtsummary::add_overall() %>% 
    gtsummary::bold_p() %>% 
    gtsummary::bold_labels()

#-------- Combining tables

table2_All <- 
    gtsummary::tbl_stack(
        group_header = list(
            "Global Cognition, MOCA", "Language domain", "Executive domain",
            "Memory domain", "Visuospatial domain", 
            "Vascular Cognitive Impairment"
            ),
        tbls = list(
            tbl_moca, tbl_language, tbl_executive, tbl_language, 
            tbl_visuospatial, tbl_vci
            )
        ) %>% 
    gtsummary::bold_labels() %>% 
    gtsummary::modify_caption(
        "Table 2: Comparison of Changes in Cognitive measures over 12 months"
    )

table2_All
Table 2: Comparison of Changes in Cognitive measures over 12 months
Characteristic Overall, N = 1481 Randomization Arm p-value2
Poly Pill, N = 741 Usual Care, N = 741
Global Cognition, MOCA
Baseline 15.8(6.7) 15.4(7.4) 16.2(5.9) 0.468
Month 6 from baseline 3.5(3.4) 2.9(3.4) 4.1(3.3) 0.037
    Missing 29 13 16
Month 12 from baseline 5.3(4.6) 5.2(4.2) 5.4(5.0) 0.796
    Missing 27 15 12
Month 12 from Month 6 1.9(3.4) 2.2(3.5) 1.6(3.3) 0.306
    Missing 39 18 21
Language domain
Baseline 18.1(3.9) 17.4(4.9) 18.9(2.4) 0.020
Month 6 from baseline 1.0(3.1) 1.3(3.6) 0.7(2.5) 0.271
    Missing 28 13 15
Month 12 from baseline 0.8(3.9) 1.4(3.7) 0.2(4.1) 0.091
    Missing 26 15 11
Month 12 from Month 6 -0.1(2.7) 0.3(1.6) -0.5(3.4) 0.098
    Missing 37 18 19
Executive domain
Baseline 12.5(5.3) 11.6(6.0) 13.4(4.2) 0.043
Month 6 from baseline 2.5(3.9) 2.6(4.7) 2.3(3.0) 0.622
    Missing 28 13 15
Month 12 from baseline 3.2(4.4) 4.1(4.2) 2.4(4.4) 0.029
    Missing 26 15 11
Month 12 from Month 6 0.8(3.7) 1.7(3.8) 0.0(3.3) 0.014
    Missing 37 18 19
Memory domain
Baseline 18.1(3.9) 17.4(4.9) 18.9(2.4) 0.020
Month 6 from baseline 1.0(3.1) 1.3(3.6) 0.7(2.5) 0.271
    Missing 28 13 15
Month 12 from baseline 0.8(3.9) 1.4(3.7) 0.2(4.1) 0.091
    Missing 26 15 11
Month 12 from Month 6 -0.1(2.7) 0.3(1.6) -0.5(3.4) 0.098
    Missing 37 18 19
Visuospatial domain
Baseline 7.5(4.7) 6.9(4.9) 8.0(4.5) 0.141
Month 6 from baseline 1.2(3.9) 1.6(3.6) 0.7(4.2) 0.195
    Missing 28 13 15
Month 12 from baseline 1.5(3.9) 1.8(3.6) 1.3(4.1) 0.495
    Missing 26 15 11
Month 12 from Month 6 0.3(3.2) 0.1(3.2) 0.5(3.2) 0.493
    Missing 37 18 19
Vascular Cognitive Impairment
Month 12


0.108
    NO VCI 112(91.8) 53(89.8) 59(93.7)
    VAD 2(1.6) 0(0.0) 2(3.2)
    VCI 8(6.6) 6(10.2) 2(3.2)
    Missing 26 15 11
1 Mean(SD)
2 Welch Two Sample t-test

Table 3A: Crude domains tragectory 0-6-12 months

Code
df_long_0_6_12 %>% 
    nest(data = -name2) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit*study_arm, 
        random = ~ visit | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T, effects ="fixed")),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name2, final) %>% 
    unnest(cols = c(name2, final)) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

name2

estimate

conf.low

conf.high

p.value

language

1.8767047

0.41729026

3.336119

0.012381246

executive

2.0264793

0.51986386

3.533095

0.008936027

visuospatial

0.5545147

-0.80224482

1.911274

0.423942345

memory

2.6011075

0.03010238

5.172113

0.048539513

aggregated

6.8696958

1.44051207

12.298879

0.013834837

Table 3A: Adjusted domain tragectory 0-6-12 months

Code
df_long_0_6_12 %>% 
    nest(data = -name2) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit*study_arm + formal_education + hba1c_0 +  hamd_0 + stroke_type, 
        random = ~ visit | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T, effects ="fixed")),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name2, final) %>% 
    unnest(cols = c(name2, final)) %>% 
    flextable::flextable()%>% 
    flextable::theme_vanilla()

name2

estimate

conf.low

conf.high

p.value

language

1.9493147

0.3424973

3.556132

0.01971635

executive

2.5494660

1.0343392

4.064593

0.00130329

visuospatial

0.8188655

-0.6868825

2.324614

0.29341970

memory

2.3211790

-0.4066991

5.049057

0.10083477

aggregated

7.4621517

1.6126678

13.311636

0.01427565

Table 3C: Crude domains 6-12 months trajectory

Code
df_long_6_12 %>% 
    nest(data = -name2) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit*study_arm, 
        random = ~ visit | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T, effects ="fixed")),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name2, final) %>% 
    unnest(cols = c(name2, final)) %>% 
    flextable::flextable()%>% 
    flextable::theme_vanilla()

name2

estimate

conf.low

conf.high

p.value

language

0.7669030

-0.1589431

1.6927491

0.10639252

executive

1.5139510

0.1934128

2.8344891

0.02623513

visuospatial

-0.4450064

-1.6313409

0.7413282

0.46253218

memory

1.3347184

-0.8687789

3.5382157

0.23640938

aggregated

3.3726334

-0.7965924

7.5418593

0.11473617

Table 3D: Adjusted domains 6-12 months trajectory

Code
df_long_6_12 %>% 
    nest(data = -name2) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit*study_arm + formal_education + hba1c_0 + hamd_0 + stroke_type, 
        random = ~ visit | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T, effects ="fixed")),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name2, final) %>% 
    unnest(cols = c(name2, final)) %>% 
    flextable::flextable()%>% 
    flextable::theme_vanilla()

name2

estimate

conf.low

conf.high

p.value

language

0.9285455

-0.1079593

1.965050

0.08730075

executive

1.6309064

0.2693399

2.992473

0.02305259

visuospatial

-0.4890668

-1.8150586

0.836925

0.47864306

memory

1.3611915

-0.9602116

3.682595

0.26097886

aggregated

3.6962577

-0.7674077

8.159923

0.11359563

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*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*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")
        
        
    )


x %>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

term

estimate

conf.low

conf.high

p.value

visit:age10

2.9109197

0.64370210

5.17813733

0.012516995

visit:femaleTRUE

3.5954552

-1.89735299

9.08826339

0.200793940

visit:formal_educationPrimary

3.1201635

-4.30754351

10.54787051

0.414822376

visit:formal_educationSecondary

-3.1537483

-11.93162836

5.62413177

0.485447013

visit:formal_educationTertiary

-8.0825214

-17.42564589

1.26060303

0.093840988

visit:formal_educationPostgraduate

-12.4330632

-44.31127057

19.44514423

0.448947403

visit:stroke_typeSmall vessel

-0.8929048

-8.43503906

6.64922946

0.817188110

visit:stroke_typeUntyped

2.2959774

-4.40128215

8.99323700

0.503424247

visit:income1

-1.7116783

-10.51898690

7.09563039

0.705089670

visit:income2

-2.2672676

-11.45072697

6.91619172

0.630712358

visit:income3

-5.3435015

-21.76422634

11.07722339

0.526398707

visit:smokeYes

-8.1297457

-25.32865391

9.06916253

0.355188076

visit:alcoholYes

-5.1104627

-10.97711637

0.75619092

0.089085204

visit:bmi_5

-2.7268821

-5.68160574

0.22784151

0.071764423

visit:whr_0

-27.1146120

-66.69517003

12.46594601

0.180701774

visit:sbp_10

-1.6226415

-3.16457710

-0.08070589

0.040251365

visit:dbp_10

-1.0365804

-3.01239956

0.93923873

0.304909534

visit:totchol

1.9871291

-0.05030935

4.02456758

0.057166161

visit:hba1c_0

0.2686552

-1.11580089

1.65311129

0.704098151

visit:nihss_score

1.2710638

0.46833676

2.07379088

0.002144138

visit:modified_rankin_scale_m0

3.8309533

0.83944215

6.82246449

0.012743068

visit:hamd_0

0.6757958

0.00963181

1.34195985

0.047936242

visit:study_armPoly Pill

6.8696958

1.44051207

12.29887946

0.013834837

visit:hamd_0

0.6757958

0.00963181

1.34195985

0.047936242

visit:morisky_m0

-2.5583951

-6.60710044

1.49031026

0.216782460

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")
        
        
    )

x %>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

term

estimate

conf.low

conf.high

p.value

visit:age10

0.73476189

0.12145059

1.34807319

0.01969493677

visit:femaleTRUE

1.29710011

-0.17660659

2.77080681

0.08583034770

visit:formal_educationPrimary

0.27983780

-1.76353984

2.32321545

0.79023141065

visit:formal_educationSecondary

-1.04132541

-3.44469571

1.36204489

0.40032842468

visit:formal_educationTertiary

-1.58984944

-4.17647744

0.99677855

0.23319013378

visit:formal_educationPostgraduate

-0.50226828

-9.39545367

8.39091712

0.91263945724

visit:stroke_typeSmall vessel

-0.27079688

-2.30171477

1.76012100

0.79459622806

visit:stroke_typeUntyped

-0.06193108

-1.86015032

1.73628816

0.94638224060

visit:income1

-1.06804255

-3.43256627

1.29648117

0.37939233400

visit:income2

-1.17918814

-3.64508559

1.28670932

0.35211087276

visit:income3

-1.35906476

-5.82087582

3.10274630

0.55316389003

visit:smokeYes

0.39629173

-4.23976474

5.03234821

0.86710057404

visit:alcoholYes

-1.46388366

-3.04272246

0.11495515

0.07045220730

visit:bmi_5

-0.97471100

-1.76415168

-0.18527033

0.01628026797

visit:whr_0

-9.33524985

-19.96733459

1.29683489

0.08659716244

visit:sbp_10

-0.36881281

-0.79228273

0.05465711

0.08914839191

visit:dbp_10

-0.33380304

-0.86437938

0.19677330

0.21879865777

visit:totchol

0.44555544

-0.10735898

0.99846985

0.11561800200

visit:hba1c_0

0.07350428

-0.30896232

0.45597087

0.70681068135

visit:nihss_score

0.45816200

0.25401084

0.66231315

0.00001641732

visit:modified_rankin_scale_m0

0.77621810

-0.03156213

1.58399834

0.06088312227

visit:hamd_0

0.15172307

-0.02906682

0.33251296

0.10134411497

visit:study_armPoly Pill

1.87670472

0.41729026

3.33611919

0.01238124611

visit:hamd_0

0.15172307

-0.02906682

0.33251296

0.10134411497

visit:morisky_m0

-0.64649868

-1.74792707

0.45492972

0.25115946999

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*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*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")
        
        
    )

x %>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

term

estimate

conf.low

conf.high

p.value

visit:age10

1.2141132

0.14240473

2.28582159

0.02734158

visit:femaleTRUE

1.9529799

-0.62479356

4.53075328

0.13891803

visit:formal_educationPrimary

0.8745256

-2.60066153

4.34971280

0.62504193

visit:formal_educationSecondary

-2.4722134

-6.57736491

1.63293820

0.24274139

visit:formal_educationTertiary

-4.2091212

-8.58604578

0.16780347

0.06270961

visit:formal_educationPostgraduate

-10.1779134

-25.13927162

4.78344475

0.18715198

visit:stroke_typeSmall vessel

-0.2892858

-3.82993858

3.25136691

0.87324502

visit:stroke_typeUntyped

1.3743255

-1.76589214

4.51454317

0.39313555

visit:income1

-1.1088654

-5.22414524

3.00641439

0.59983548

visit:income2

-2.2923878

-6.58344919

1.99867366

0.29867194

visit:income3

-5.4956938

-13.18157688

2.19018928

0.16459108

visit:smokeYes

-1.7282585

-9.85768694

6.40116999

0.67731923

visit:alcoholYes

-2.4125620

-5.17166045

0.34653654

0.08788847

visit:bmi_5

-1.2254224

-2.61717617

0.16633140

0.08572325

visit:whr_0

-12.5040059

-31.16290706

6.15489526

0.19034362

visit:sbp_10

-0.7431930

-1.46635184

-0.02003407

0.04511897

visit:dbp_10

-0.3906201

-1.31950591

0.53826580

0.41068237

visit:totchol

0.9730472

0.01824290

1.92785146

0.04694923

visit:hba1c_0

0.3321081

-0.30626426

0.97048047

0.30908936

visit:nihss_score

0.4744131

0.09517132

0.85365494

0.01493705

visit:modified_rankin_scale_m0

1.5502913

0.13717355

2.96340906

0.03255432

visit:hamd_0

0.2574607

-0.05718567

0.57210706

0.11011971

visit:study_armPoly Pill

2.6011075

0.03010238

5.17211258

0.04853951

visit:hamd_0

0.2574607

-0.05718567

0.57210706

0.11011971

visit:morisky_m0

-1.4191970

-3.32002244

0.48162853

0.14471945

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")
        
        
    )

x %>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

term

estimate

conf.low

conf.high

p.value

visit:age10

0.3027036

-0.26594861

0.8713559

0.29789610

visit:femaleTRUE

0.5655128

-0.78840605

1.9194316

0.41384491

visit:formal_educationPrimary

-0.8594346

-2.70144393

0.9825748

0.36516855

visit:formal_educationSecondary

-1.8076669

-3.99264502

0.3773113

0.10899111

visit:formal_educationTertiary

-2.4596839

-4.76909856

-0.1502693

0.03942880

visit:formal_educationPostgraduate

-3.0193143

-10.87251733

4.8338888

0.45541852

visit:stroke_typeSmall vessel

1.5066656

-0.32867482

3.3420059

0.10988644

visit:stroke_typeUntyped

1.5570498

-0.07229258

3.1863923

0.06298614

visit:smokeYes

-1.6236725

-5.88987473

2.6425298

0.45647704

visit:alcoholYes

-0.7562695

-2.20460954

0.6920705

0.30718735

visit:bmi_5

-0.2894713

-1.02031250

0.4413698

0.43839267

visit:whr_0

0.3407552

-9.38104600

10.0625564

0.94529412

visit:sbp_10

-0.2605834

-0.64115165

0.1199848

0.18089747

visit:dbp_10

-0.2262670

-0.71282895

0.2602949

0.36302223

visit:totchol

0.4717153

-0.03557588

0.9790064

0.06966868

visit:nihss_score

0.1917115

-0.01088797

0.3943111

0.06490160

visit:modified_rankin_scale_m0

1.1535217

0.42393988

1.8831036

0.00217656

visit:hamd_0

0.1530872

-0.01041457

0.3165890

0.06775250

visit:study_armPoly Pill

0.5545147

-0.80224482

1.9112743

0.42394234

visit:hamd_0

0.1530872

-0.01041457

0.3165890

0.06775250

visit:morisky_m0

-1.1690031

-2.15198448

-0.1860218

0.02060174

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")
        
        
    )

x %>% 
    filter(str_detect(term,":")) %>% 
    select(term, estimate, conf.low, conf.high, p.value) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

term

estimate

conf.low

conf.high

p.value

visit:age10

0.73487500

0.09922185

1.3705281

0.024362771

visit:femaleTRUE

-0.03328116

-1.56634932

1.4997870

0.966100126

visit:formal_educationPrimary

3.15777972

1.13347466

5.1820848

0.002686956

visit:formal_educationSecondary

2.18056028

-0.22393128

4.5850518

0.079104468

visit:formal_educationTertiary

0.24203031

-2.28964567

2.7737063

0.852677744

visit:formal_educationPostgraduate

1.36543562

-7.21483218

9.9457034

0.757245227

visit:stroke_typeSmall vessel

-2.09870817

-4.17396834

-0.0234480

0.049212255

visit:stroke_typeUntyped

-0.68145551

-2.52788773

1.1649767

0.471354111

visit:income1

2.16724530

-0.23768483

4.5721754

0.080206864

visit:income2

2.15949064

-0.34769364

4.6666749

0.094407127

visit:income3

2.33446229

-2.09705176

6.7659763

0.305434407

visit:smokeYes

-5.39430807

-10.13447777

-0.6541384

0.026658472

visit:alcoholYes

-0.61030482

-2.25012656

1.0295169

0.466479115

visit:bmi_5

-0.26715255

-1.09515326

0.5608482

0.527793867

visit:whr_0

-5.58199329

-16.58251769

5.4185311

0.321020543

visit:sbp_10

-0.32272137

-0.75015116

0.1047084

0.140269943

visit:dbp_10

-0.22643243

-0.77887387

0.3260090

0.422617940

visit:totchol

0.02036675

-0.55085985

0.5915933

0.944352498

visit:hba1c_0

0.11022095

-0.25618959

0.4766315

0.556126011

visit:nihss_score

0.20473407

-0.02776456

0.4372327

0.085681737

visit:modified_rankin_scale_m0

0.48526467

-0.36355188

1.3340812

0.263666820

visit:hamd_0

0.13618193

-0.04969633

0.3220602

0.152359498

visit:study_armPoly Pill

2.02647931

0.51986386

3.5330948

0.008936027

visit:hamd_0

0.13618193

-0.04969633

0.3220602

0.152359498

visit:morisky_m0

0.54640909

-0.57118106

1.6639992

0.338943725

Table 5: Cognitive domain changes with missing data

Code
df_long %>% 
    drop_na() %>% 
    nest(data = -name) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit2*study_arm, 
        random = ~ visit2 | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T, effects ="fixed")),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit2:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name, final) %>% 
    unnest(cols = c(name, final)) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

name

estimate

conf.low

conf.high

p.value

language_

1.8767047

0.41729026

3.336119

0.012381246

executive_

2.0264793

0.51986386

3.533095

0.008936027

visuospatial_

0.5545147

-0.80224482

1.911274

0.423942345

memory_

2.6011075

0.03010238

5.172113

0.048539513

aggregated_

6.8696958

1.44051207

12.298879

0.013834837

Table 6: Cognitive domain changes with imputed data

Code
df_long %>% 
    missRanger::missRanger(formula = . ~ ., seed = 777, num.trees = 1000,verbose = F) %>% 
    nest(data = -name) %>% 
    mutate(
        model = map(.x = data, ~nlme::lme(
        value ~ visit2*study_arm, 
        random = ~ visit2 | record_id, data = .x, 
        na.action = na.omit, method = "ML")),
        temp1 = map(.x = model, ~broom.mixed::tidy(.x, conf.int=T)),
        temp2 = map(.x = temp1, ~filter(.x, term == "visit2:study_armPoly Pill")),
        final = map(.x = temp2, ~select(.x, estimate, conf.low, conf.high, p.value))
        ) %>% 
    select(name, final) %>% 
    unnest(cols = c(name, final)) %>% 
    flextable::flextable() %>% 
    flextable::theme_vanilla()

name

estimate

conf.low

conf.high

p.value

language_

1.8390466

0.4642860

3.213807

0.009227462

executive_

2.1788649

0.5956023

3.762127

0.007417873

visuospatial_

0.7296686

-0.7097229

2.169060

0.321446522

memory_

2.7637950

0.1192739

5.408316

0.041493143

aggregated_

7.3010125

1.5744779

13.027547

0.013041442