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)