df_new_selected <-
df_new %>%
select (
age, gender, nationality, ethnicity, religion,
marital_status, educational_level, employment,
residence, region, are_you_a_smoker, do_you_drink_alcohol,
bmi_category, hypertension_systemic, diabetes_mellitus,
blood_pressure_systolic_mm_hg, blood_pressure_diastolic_mm_hg,
rhythm, arrhythmia_specify, sob_exertional_resting: bmi,
ef_simpson_s_percent, outcome, fs_percent,
heart_failure_phenotype, nyha_class, monthly_income,
type_of_settlement, unique_id, are_you_a_smoker) %>%
mutate (
blood_pressure_systolic_mm_hg =
as.numeric (blood_pressure_systolic_mm_hg),
blood_pressure_diastolic_mm_hg =
as.numeric (blood_pressure_diastolic_mm_hg),
bmi = as.numeric (bmi),
bmi = case_when (bmi > 2 & bmi < 100 ~ bmi),
afib = case_when (
str_detect (
arrhythmia_specify, "fib" ) ~ "Yes" ,
! is.na (arrhythmia_specify) ~ "No" ),
afib2 = case_when (afib == "Yes" ~ "Yes" , TRUE ~ "No" ),
aflut = case_when (
str_detect (arrhythmia_specify, "lut" ) ~ "Yes" ,
! is.na (arrhythmia_specify) ~ "No" ),
aflut2 = case_when (aflut == "Yes" ~ "Yes" , TRUE ~ "No" ),
monthly_income = factor (
monthly_income,
levels = c (
"Less than 500 Cedis" , "500-999 Cedis" ,
"1000-5000 Cedis" , "> 5000 Cedis" ),
labels = c (
"Less than 500 Cedis" , "500-999 Cedis" ,
"1000-5000 Cedis" , "> 5000 Cedis" )),
gender = case_when (
unique_id == "AGPH/11" ~ "Female" ,
unique_id == "CCTH/097" ~ "Female" ,
unique_id == "KBTH/255" ~ "Male" ,
TRUE ~ gender),
educational_level = case_when (
educational_level %in% c (
"Postgraduate Studies" ,
"University" , "Diploma" ) ~ "Tertiary" ,
educational_level %in% "No Formal Education" ~ "None" ,
educational_level %in% "Basic" ~ "Primary" ,
educational_level %in% "Senior High School" ~ "Secondary" ),
employment = factor (employment) %>%
fct_lump (n = 5 , other_level = "Other" ),
region = factor (region) %>% fct_lump (n= 6 ),
blood_pressure_systolic_mm_hg = case_when (
blood_pressure_systolic_mm_hg > 20 ~
blood_pressure_systolic_mm_hg),
blood_pressure_diastolic_mm_hg = case_when (
blood_pressure_diastolic_mm_hg > 10 ~
blood_pressure_diastolic_mm_hg),
sbp_hpt = case_when (
hypertension_systemic == "Yes" ~ blood_pressure_systolic_mm_hg),
dbp_hpt = case_when (
hypertension_systemic == "Yes" ~ blood_pressure_diastolic_mm_hg),
sbp_nohpt = case_when (
hypertension_systemic == "No" ~ blood_pressure_systolic_mm_hg),
dbp_nohpt = case_when (
hypertension_systemic == "No" ~ blood_pressure_diastolic_mm_hg),
agecat = case_when (
age <= 40 ~ "40 yrs or less" ,
age > 40 & age < 65 ~ "41 to 64 yrs" ,
age >= 65 ~ "65 yrs or more" ),
across (
c (sob_exertional_resting, orthopnoea, pnd, easy_fatigability,
bipedal_swelling, nyha_class, nocturnal_cough, palpitation,
bloated_feeling_early_satiety, loss_of_appetite, chest_pain,
others),
~ fun_one (.)),
weight = case_when (weight > 10 ~ weight),
height = ifelse (height < 0.1 , NA , height),
height = ifelse (height > 100 , height/ 100 , height),
height = ifelse (height > 25 , (height+ 100 )/ 100 , height),
ef_simpson_s_percent = case_when (
(ef_simpson_s_percent > 0 ) & (ef_simpson_s_percent < 100 ) ~
ef_simpson_s_percent),
outcome = fct_na_level_to_value (outcome, "N/A" ),
fs_percent = case_when (fs_percent > 1 ~ fs_percent))