df_ptb <-
readxl:: read_xlsx ("./Data/PTB Response.xlsx" ) %>%
janitor:: clean_names () %>%
select (- c (timestamp, question, dropdown, stephanie_janet_badu_peprah)) %>%
rename (
ghon_focus = question_persistent_calcification_ghons_focus,
tuberculoma = question_tuberculoma,
miliary = question_miliary_nodules,
peribronchial_fibrosis = question_peribronchial_fibrosis,
consolidation = question_consolidation,
cavitation = question_cavitation,
perihilar_lymphadenopathy = question_perihilar_lymphadenopathy,
reticulonodular_infiltrates = question_reticulonodular_infiltrates,
reticular_infiltrates = question_reticular_infiltrates,
lung_volume_loss = question_lung_volume_loss,
cxr_conclusion = based_on_xtics_above_cxr_signifies,
extent_of_lung_involved_segment = extent_of_lung_involved,
extent_of_effusion_minimal = extent_of_effusion,
pleural_effusion_present_unilateral = pleural_effusion_present
) %>%
mutate (
consolid_rul = case_when (
str_detect (consolidation, "Right upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
consolid_lul = case_when (
str_detect (consolidation, "Left upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
consolid_rml = case_when (
str_detect (consolidation, "Right middle lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
consolid_lml = case_when (
str_detect (consolidation, "Left middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
consolid_rll = case_when (
str_detect (consolidation, "Right lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
consolid_lll = case_when (
str_detect (consolidation, "Left lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_rul = case_when (
str_detect (cavitation, "Right upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_lul = case_when (
str_detect (cavitation, "Left upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_rml = case_when (
str_detect (cavitation, "Right middle lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_lml = case_when (
str_detect (cavitation, "Left middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_rll = case_when (
str_detect (cavitation, "Right lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
cavit_lll = case_when (
str_detect (cavitation, "Left lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (levels = c ("No" , "Yes" )),
tuberculoma = case_when (
str_detect (tuberculoma, "." )~ "Yes" ,
TRUE ~ "No" ) %>% factor (levels = c ("No" , "Yes" )),
miliary = case_when (
str_detect (miliary, "." )~ "Yes" ,
TRUE ~ "No" ) %>% factor (levels = c ("No" , "Yes" )),
peri_lymph_rml = case_when (
str_detect (perihilar_lymphadenopathy, "Right middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
peri_lymph_lml = case_when (
str_detect (perihilar_lymphadenopathy, "Left middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_rul = case_when (
str_detect (reticulonodular_infiltrates, "Right upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_lul = case_when (
str_detect (reticulonodular_infiltrates, "Left upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_rml = case_when (
str_detect (reticulonodular_infiltrates, "Right middle lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_lml = case_when (
str_detect (reticulonodular_infiltrates, "Left middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_rll = case_when (
str_detect (reticulonodular_infiltrates, "Right lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_nod_lll = case_when (
str_detect (reticulonodular_infiltrates, "Left lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_rul = case_when (
str_detect (reticular_infiltrates, "Right upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_lul = case_when (
str_detect (reticular_infiltrates, "Left upper lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_rml = case_when (
str_detect (reticular_infiltrates, "Right middle lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_lml = case_when (
str_detect (reticular_infiltrates, "Left middle" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_rll = case_when (
str_detect (reticular_infiltrates, "Right lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
ret_lll = case_when (
str_detect (reticular_infiltrates, "Left lower lobe" )~ "Yes" ,
TRUE ~ "No" ) %>% factor (),
total_lung_damaged = factor (
total_lung_damaged,
levels = c ("None" , "Small" , "Moderate" , "Large" )
),
ghon_focus = ifelse (is.na (ghon_focus), "None" , ghon_focus),
lung_volume_loss = ifelse (
is.na (lung_volume_loss), "None" , lung_volume_loss
),
peribronchial_fibrosis = ifelse (
is.na (peribronchial_fibrosis), "None" , peribronchial_fibrosis
),
cxr_conclusion = ifelse (
cxr_conclusion == "Previous/Chronic TB" , "Active TB" , cxr_conclusion
) %>% factor (),
extent_of_lung_involved_segment = ifelse (
is.na (extent_of_lung_involved_segment),
"No" ,
extent_of_lung_involved_segment
),
extent_of_lung_involved_one_lobe = ifelse (
is.na (extent_of_lung_involved_one_lobe),
"No" ,
extent_of_lung_involved_one_lobe
),
extent_of_lung_involved_two_lobes = ifelse (
is.na (extent_of_lung_involved_two_lobes),
"No" ,
extent_of_lung_involved_two_lobes
),
extent_of_lung_involved_more_than_2lobes = ifelse (
is.na (extent_of_lung_involved_more_than_2lobes),
"No" ,
extent_of_lung_involved_more_than_2lobes
),
extent_of_lung_involved_none = ifelse (
is.na (extent_of_lung_involved_none),
"No" ,
extent_of_lung_involved_none
),
extent_of_effusion_minimal = ifelse (
is.na (extent_of_effusion_minimal),
"No" ,
extent_of_effusion_minimal
),
extent_of_effusion_up_to_middle_lung_zone = ifelse (
is.na (extent_of_effusion_up_to_middle_lung_zone),
"No" ,
extent_of_effusion_up_to_middle_lung_zone
),
extent_of_effusion_massive = ifelse (
is.na (extent_of_effusion_massive),
"No" ,
extent_of_effusion_massive
) %>% factor (levels = c ("No" , "Yes" )),
extent_of_effusion_none = ifelse (
is.na (extent_of_effusion_none),
"No" ,
extent_of_effusion_none
) %>% factor (levels = c ("No" , "Yes" )),
pleural_effusion_present_unilateral = ifelse (
is.na (pleural_effusion_present_unilateral),
"No" ,
pleural_effusion_present_unilateral
) %>% factor (levels = c ("No" , "Yes" )),
pleural_effusion_present_bilateral = ifelse (
is.na (pleural_effusion_present_bilateral),
"No" ,
pleural_effusion_present_bilateral
) %>% factor (levels = c ("No" , "Yes" )),
pleural_effusion_present_none = ifelse (
is.na (pleural_effusion_present_none),
"No" ,
pleural_effusion_present_none
) %>% factor (levels = c ("No" , "Yes" ))
)
df_ptb <-
df_ptb %>%
labelled:: set_variable_labels (
consolid_rul = "Consolidation: Right Upper Lobe" ,
consolid_rml = "Consolidation: Right Middle Lobe" ,
consolid_rll = "Consolidation: Right Lower Lobe" ,
consolid_lul = "Consolidation: Left Upper Lobe" ,
consolid_lml = "Consolidation: Left Middle Lung Zone" ,
consolid_lll = "Consolidation: Left Lower Lobe" ,
#---------------------------------------------
cavit_rul = "Cavitation: Right Upper Lobe" ,
cavit_rml = "Cavitation: Right Middle Lobe" ,
cavit_rll = "Cavitation: Right Lower Lobe" ,
cavit_lul = "Cavitation: Left Upper Lobe" ,
cavit_lml = "Cavitation: Left Middle Lung Zone" ,
cavit_lll = "Cavitation: Left Lower Lobe" ,
#----------------------------------------------
tuberculoma = "Tuberculoma" ,
miliary = "Miliary" ,
#----------------------------------------------
peri_lymph_lml = "Perihilar Lymphadenopathy: Left Middle Lung Zone" ,
peri_lymph_rml = "Perihilar Lymphadenopathy: Right Middle Lobe" ,
#----------------------------------------------
ret_nod_rul = "Ret. Nodular Infiltrates: Right Upper Lobe" ,
ret_nod_rml = "Ret. Nodular Infiltrates: Right Middle Lobe" ,
ret_nod_rll = "Ret. Nodular Infiltrates: Right Lower Lobe" ,
ret_nod_lul = "Ret. Nodular Infiltrates: Left Upper Lobe" ,
ret_nod_lml = "Ret. Nodular Infiltrates: Left Middle Lung Zone" ,
ret_nod_lll = "Ret. Nodular Infiltrates: Left Lower Lobe" ,
#---------------------------------------------
ret_rul = "Reticular Infiltrates: Right Upper Lobe" ,
ret_rml = "Reticular Infiltrates: Right Middle Lobe" ,
ret_rll = "Reticular Infiltrates: Right Lower Lobe" ,
ret_lul = "Reticular Infiltrates: Left Upper Lobe" ,
ret_lml = "Reticular Infiltrates: Left Middle Lung Zone" ,
ret_lll = "Reticular Infiltrates: Left Lower Lobe" ,
#---------------------------------------------
total_lung_damaged = "Total Lung Damage" ,
ghon_focus = "Persistent Calcification Ghon Focus" ,
cxr_conclusion = "CXR conclusion" ,
extent_of_lung_involved_segment = "Extent of lung involved: Segment" ,
extent_of_lung_involved_one_lobe = "Extent of lung involved: One Lobe" ,
extent_of_lung_involved_two_lobes = "Extent of lung involved: Two Lobes" ,
extent_of_lung_involved_more_than_2lobes = "Extent of lung involved: > Two Lobes" ,
extent_of_lung_involved_none = "Extent of lung involved: None" ,
extent_of_effusion_minimal = "Extent of Effusion: Minimal" ,
extent_of_effusion_up_to_middle_lung_zone = "Extent of Effusion: Up to middle lung zone" ,
extent_of_effusion_massive = "Extent of Effusion: Massive" ,
extent_of_effusion_none = "Extent of Effusion: None" ,
pleural_effusion_present_unilateral = "Pleural Effusion Present: Unilateral" ,
pleural_effusion_present_bilateral = "Pleural Effusion Present: Bilateral" ,
pleural_effusion_present_none = "Pleural Effusion Present: None" ,
lung_volume_loss = "Lung volume loss" ,
peribronchial_fibrosis = "Peribronchail Fibrosis"
)
# df_ptb %>% summarytools::dfSummary(labels.col = F, graph.col = F)
df_ptb2 <- df_ptb
df_ptb <-
df_ptb %>%
filter (! is.na (cxr_conclusion))
write_rds (x = df_ptb, file = "ptb_data.rds" )