## Preamble --------------------------- ## ## Name: Script for Label and Level 22-08-16 Final_StrokeCaregiverBurden_Raw ## Purpose: To Label and Level 22-08-16 Final_StrokeCaregiverBurden_Raw ## Author: Mohd Azmi Bin Suliman ## Date Created: 2022-08-16 ## Email: mohd.azmi@student.usm.my ## ## Packages --------------------------- ## ## if tidyverse available, can load tidyverse. ## library(tidyverse) require(dplyr) require(magrittr) require(forcats) require(stringr) require(tidyr) require(readr) ## Data Import --------------------------- dt_raw <- read_csv("22-08-16 Final_StrokeCaregiverBurden_Raw.csv", col_types = cols(...1 = col_skip())) %>% suppressMessages() ### Baseline --------------------------- ## ## also patient's demographic and caregiver's demographic strokeds_base <- dt_raw %>% filter(redcap_event_name == "pre_discharge_arm_1") %>% select(record_id:cg_paidcg, -redcap_event_name) %>% mutate(pt_gender = fct_recode(as_factor(pt_gender), "Female" = "0", "Male" = "1"), pt_hosp = fct_recode(as_factor(pt_hosp), "Hospital A" = "0", "Hospital B" = "1", "Hospital C" = "2"), dc_mrslab = fct_recode(as_factor(dc_mrs), "No symptoms" = "0", "Symptoms but no disability" = "1", "Mild disability" = "2", "Moderate disability" = "3", "Moderate severe disability" = "4", "Severe disability / bedridden" = "5"), dc_mrscat = fct_recode(as_factor(dc_mrs), "Independence" = "0", "Independence" = "1", "Independence" = "2", "Dependence" = "3", "Dependence" = "4", "Dependence" = "5"), across(.cols = c(pt_bi_phyg, pt_bi_bath, pt_bi_wcha), .fns = as_factor), across(.cols = c(pt_bi_phyg, pt_bi_bath, pt_bi_wcha), .fns = fct_recode, .names = "{.col}score", "3" = "2", "4" = "3", "5" = "4"), across(.cols = c(pt_bi_feed:pt_bi_blad), .fns = as_factor), across(.cols = c(pt_bi_feed:pt_bi_blad), .fns = fct_recode, .names = "{.col}score", "2" = "1", "5" = "2", "8" = "3", "10" = "4"), across(.cols = c(pt_bi_tran, pt_bi_ambu), .fns = as_factor), across(.cols = c(pt_bi_tran, pt_bi_ambu), .fns = fct_recode, .names = "{.col}score", "3" = "1", "8" = "2", "12" = "3", "15" = "4"), pt_bi_ambu_stat = fct_recode(as_factor(pt_bi_ambu_stat), "Ambulate (Walk)" = "0", "Wheelchair" = "1")) %>% rename_with(.cols = c(pt_bi_phyg:pt_bi_tran, pt_bi_ambu, pt_bi_wcha), .fn = ~str_c(., "lab")) %>% mutate(across(.cols = c(pt_bi_phyglab:pt_bi_tranlab, pt_bi_ambulab, pt_bi_wchalab), .fns = fct_recode, "Unable to perform task" = "0", "Substantial help required" = "1", "Moderate help required" = "2", "Minimal help required" = "3", "Fully independent" = "4"), stroke_episode = fct_recode(as_factor(stroke_episode), "Never" = "0", "Had Prev" = "1"), cg_gender = fct_recode(as_factor(cg_gender), "Female" = "0", "Male" = "1"), cg_livept = fct_recode(as_factor(cg_livept), "No" = "0", "Yes" = "1"), cg_relation = fct_recode(as_factor(cg_relation), "Spouse" = "0", "Children" = "1", "Child-in-law" = "2", "Grandchildren" = "3", "Siblings" = "4", "Parent" = "5"), cg_marital = fct_recode(as_factor(cg_marital), "Single" = "0", "Married" = "1"), cg_edulevel = fct_recode(as_factor(cg_edulevel), "Didn't go to school" = "0", "Secondary School" = "2", "College / University" = "3"), cg_occupation = fct_recode(as_factor(cg_occupation), "Unemployed" = "0", "Student" = "1", "Employed" = "2"), cg_personalincome = fct_recode(as_factor(cg_personalincome), "No Income" = "0", "< RM 1,000" = "1", "RM 1,000 - 2,999" = "2", "RM 3,000 - 4,999" = "3", "> RM 5,000" = "4"), cg_hhincome = fct_recode(as_factor(cg_hhincome), "< RM 1,000" = "0", "RM 1,000 - 2,999" = "1", "RM 3,000 - 4,999" = "2", "RM 5,000 - 7,999" = "3", "> RM 8,000" = "4"), cg_othercr = fct_recode(as_factor(cg_othercr), "No" = "0", "Yes" = "1"), cg_nocrlab = fct_recode(as_factor(cg_nocr), "1 Dependence" = "1", "2 Dependence" = "2", "3 Dependence" = "3", "4 Dependence" = "4", "5 Dependence" = "5"), cg_paidcg = fct_recode(as_factor(cg_paidcg), "No" = "0")) %>% relocate(dc_mrslab, dc_mrscat, pt_bi_phygscore, pt_bi_phyglab, pt_bi_bathscore, pt_bi_bathlab, pt_bi_feedscore, pt_bi_feedlab, pt_bi_toilscore, pt_bi_toillab, pt_bi_stairscore, pt_bi_stairlab, pt_bi_dresscore, pt_bi_dreslab, pt_bi_bowelscore, pt_bi_bowellab, pt_bi_bladscore, pt_bi_bladlab, pt_bi_transcore, pt_bi_tranlab, pt_bi_ambu_stat, pt_bi_ambuscore, pt_bi_ambulab, pt_bi_wchascore, pt_bi_wchalab, .after = dc_mrs) %>% relocate(cg_nocrlab, .after = cg_nocr) ### ZBI --------------------------- strokeds_zbi <- dt_raw %>% select(record_id, starts_with("zbi")) %>% mutate(event_name = cut(zbi_dcdurday, breaks = c(0, 20, 45, 75, 180), labels = c("W1", "M1", "M2", "M3")), event_name = fct_explicit_na(event_name, "Base"), across(.cols = c(zbi_q1:zbi_q21), .fns = as_factor), across(.cols = c(zbi_q1:zbi_q21), .fns = fct_recode, .names = "{.col}lab", "Never" = "0", "Rarely" = "1", "Sometimes" = "2", "Quite Frequently" = "3", "Nearly Always" = "4"), zbi_q22lab = fct_recode(as_factor(zbi_q22), "Not at all" = "0", "A little" = "1", "Moderately" = "2", "Quite a bit" = "3", "Extremely" = "4")) %>% rename_with(.cols = c(zbi_q1:zbi_q22), .fn = ~str_c(., "score")) %>% relocate(event_name, .after = record_id) %>% relocate(zbi_q1score, zbi_q1lab, zbi_q2score, zbi_q2lab, zbi_q3score, zbi_q3lab, zbi_q4score, zbi_q4lab, zbi_q5score, zbi_q5lab, zbi_q6score, zbi_q6lab, zbi_q7score, zbi_q7lab, zbi_q8score, zbi_q8lab, zbi_q9score, zbi_q9lab, zbi_q10score, zbi_q10lab, zbi_q11score, zbi_q11lab, zbi_q12score, zbi_q12lab, zbi_q13score, zbi_q13lab, zbi_q14score, zbi_q14lab, zbi_q15score, zbi_q15lab, zbi_q16score, zbi_q16lab, zbi_q17score, zbi_q17lab, zbi_q18score, zbi_q18lab, zbi_q19score, zbi_q19lab, zbi_q20score, zbi_q20lab, zbi_q21score, zbi_q21lab, zbi_q22score, zbi_q22lab, .after = zbi_cgnum) ### CAFU --------------------------- strokeds_cafu <- dt_raw %>% select(record_id, starts_with("cafu")) %>% mutate(event_name = cut(cafu_dcdurday, breaks = c(0, 20, 45, 75, 180), labels = c("W1", "M1", "M2", "M3")), event_name = fct_explicit_na(event_name, "Base")) %>% rename_with(.cols = ends_with("_f"), .fn = ~str_c(., "lab")) %>% mutate(across(.cols = ends_with("_flab"), .fns = as_factor), across(.cols = ends_with("_flab"), .fns = fct_recode, "Pt didn't require help" = "0", "Pt require help" = "1"), across(.cols = ends_with("_f_score"), .fns = as_factor, .names = "{.col}lab"), across(.cols = ends_with("_f_scorelab"), .fns = fct_recode, "Pt Need Help >75%" = "1", "Pt Need Help 75%" = "2", "Pt Need Help 50%" = "3", "Pt Need Help 25%" = "4", "Pt Need Help <25%" = "5", "Pt Didn't Need Help, Require Modification" = "6", "Pt Didn't Need Help, No Modification" = "7")) %>% mutate(across(.cols = ends_with("_u"), .fns = as_factor, .names = "{.col}lab"), across(.cols = ends_with("_ulab"), .fns = fct_recode, "Cg didn't help this activity" = "0", "Cg help this activity" = "1"), across(.cols = ends_with("_u_score"), .fns = as_factor, .names = "{.col}lab"), across(.cols = ends_with("_u_scorelab"), .fns = fct_recode, "Not at all" = "0", "A little" = "1", "Moderately" = "2", "Very much" = "3", "Extremely" = "4")) %>% relocate(event_name, .after = record_id) %>% relocate(cafu_q1_flab, cafu_q1_f_score, cafu_q1_d_score, cafu_q1_f_scorelab, cafu_q1_u, cafu_q1_ulab, cafu_q1_u_score, cafu_q1_u_scorelab, cafu_q2_flab, cafu_q2_f_score, cafu_q2_d_score, cafu_q2_f_scorelab, cafu_q2_u, cafu_q2_ulab, cafu_q2_u_score, cafu_q2_u_scorelab, cafu_q3_flab, cafu_q3_f_score, cafu_q3_d_score, cafu_q3_f_scorelab, cafu_q3_u, cafu_q3_ulab, cafu_q3_u_score, cafu_q3_u_scorelab, cafu_q4_flab, cafu_q4_f_score, cafu_q4_d_score, cafu_q4_f_scorelab, cafu_q4_u, cafu_q4_ulab, cafu_q4_u_score, cafu_q4_u_scorelab, cafu_q5_flab, cafu_q5_f_score, cafu_q5_d_score, cafu_q5_f_scorelab, cafu_q5_u, cafu_q5_ulab, cafu_q5_u_score, cafu_q5_u_scorelab, cafu_q6_flab, cafu_q6_f_score, cafu_q6_d_score, cafu_q6_f_scorelab, cafu_q6_u, cafu_q6_ulab, cafu_q6_u_score, cafu_q6_u_scorelab, cafu_q7_flab, cafu_q7_f_score, cafu_q7_d_score, cafu_q7_f_scorelab, cafu_q7_u, cafu_q7_ulab, cafu_q7_u_score, cafu_q7_u_scorelab, cafu_q8_flab, cafu_q8_f_score, cafu_q8_d_score, cafu_q8_f_scorelab, cafu_q8_u, cafu_q8_ulab, cafu_q8_u_score, cafu_q8_u_scorelab, .after = cafu_cgnum) %>% relocate(cafu_q10_flab, cafu_q10_f_score, cafu_q10_d_score, cafu_q10_f_scorelab, cafu_q10_u, cafu_q10_ulab, cafu_q10_u_score, cafu_q10_u_scorelab, cafu_q11_flab, cafu_q11_f_score, cafu_q11_d_score, cafu_q11_f_scorelab, cafu_q11_u, cafu_q11_ulab, cafu_q11_u_score, cafu_q11_u_scorelab, cafu_q12_flab, cafu_q12_f_score, cafu_q12_d_score, cafu_q12_f_scorelab, cafu_q12_u, cafu_q12_ulab, cafu_q12_u_score, cafu_q12_u_scorelab, cafu_q13_flab, cafu_q13_f_score, cafu_q13_d_score, cafu_q13_f_scorelab, cafu_q13_u, cafu_q13_ulab, cafu_q13_u_score, cafu_q13_u_scorelab, cafu_q14_flab, cafu_q14_f_score, cafu_q14_d_score, cafu_q14_f_scorelab, cafu_q14_u, cafu_q14_ulab, cafu_q14_u_score, cafu_q14_u_scorelab, cafu_q15_flab, cafu_q15_f_score, cafu_q15_d_score, cafu_q15_f_scorelab, cafu_q15_u, cafu_q15_ulab, cafu_q15_u_score, cafu_q15_u_scorelab, cafu_q16_flab, cafu_q16_f_score, cafu_q16_d_score, cafu_q16_f_scorelab, cafu_q16_u, cafu_q16_ulab, cafu_q16_u_score, cafu_q16_u_scorelab, .after = cafu_iadl_u_meanscore) %>% filter(record_id != 25 & event_name != "Base") ### Combine (Long Format) --------------------------- ## ## combine in long format ## combine zbi and cafu first strokeds_survey <- right_join(strokeds_zbi, strokeds_cafu, by = c("record_id", "event_name")) ## combine zbi and cafu with baseline strokeds_long <- full_join(strokeds_base, strokeds_survey, by = "record_id") %>% relocate(event_name, .after = record_id) %>% #use trimws instead of as.char because as.char become error mutate(event_name = fct_explicit_na(event_name, "Base"), event_name = fct_relevel(event_name, "Base"), across(.cols = ends_with("score"), .fns = trimws), across(.cols = ends_with("score"), .fns = as.numeric)) %>% filter(record_id != 20) strokeds_long ### Wide Format --------------------------- strokeds_wide <- strokeds_long %>% pivot_wider(id_cols = c(record_id:cg_paidcg), names_from = event_name, values_from = c(zbi_dcdurday:cafu_adl_u_meanscore), names_vary = "slowest") %>% select(-c(ends_with("_Base"))) strokeds_wide