reformatting code to select needed df for analysis

This commit is contained in:
Tanushree Tunstall 2020-11-20 11:43:03 +00:00
parent a6cbaab40a
commit b72c4df796
7 changed files with 243 additions and 102 deletions

View file

@ -30,11 +30,11 @@ meta_data_cols = c("mosaic", "gender", "age"
, "adult"
, "flustat", "type"
, "obesity"
, "obese2"
, "height", "height_unit"
, "weight", "weight_unit"
, "ia_height_ftin", "ia_height_m", "ia_weight"
, "visual_est_bmi", "bmi_rating"
#, "obese2"
#, "height", "height_unit"
#, "weight", "weight_unit"
#, "ia_height_ftin", "ia_height_m", "ia_weight"
#, "visual_est_bmi", "bmi_rating"
)
# check if these columns to select are present in the data
@ -55,9 +55,9 @@ if (table(adult_df$adult == 1)[[1]] == nrow(adult_df) ){
cat ("\nFAIL: adult df number mismatch!")
}
#==============
#=================================
# FLU positive: adult patients
#==============
#=================================
# extract the flu positive population
fp_adults = adult_df[adult_df$flustat == 1,]
@ -67,6 +67,53 @@ if (table(fp_adults$flustat == 1)[[1]] == nrow(fp_adults) ){
cat ("\nFAIL: adult df number mismatch!")
}
#=============================================
# FLU positive adult patients: without asthma
#=============================================
#-----------------------------------
# asthma and copd status correction
# for conflicting field!
#------------------------------------
# Reassign the copd and asthma status and do some checks
table(fp_adults$ia_exac_copd); sum(is.na(fp_adults$ia_exac_copd))
fp_adults$ia_exac_copd[fp_adults$ia_exac_copd< 1]<- 0
fp_adults$ia_exac_copd[is.na(fp_adults$ia_exac_copd)] <- 0
table(fp_adults$ia_exac_copd); sum(is.na(fp_adults$ia_exac_copd))
# check copd and asthma status
table(fp_adults$ia_exac_copd, fp_adults$asthma)
check_copd_and_asthma_1<- subset(fp_adults, ia_exac_copd ==1 & asthma == 1) # check this is 3
# reassign these 3 so these are treated as non-asthmatics as copd with asthma is NOT TRUE asthma
fp_adults$asthma[fp_adults$ia_exac_copd == 1 & fp_adults$asthma == 1]= 0
table(fp_adults$ia_exac_copd, fp_adults$asthma)
foo<- subset(fp_adults, asthma==1 & ia_exac_copd ==1) # check that its 0
rm(check_copd_and_asthma_1, foo)
if ( table(fp_adults$ia_exac_copd, fp_adults$asthma) [[2,2]] == 0 ){
cat("\nPASS: asthma and copd do not conflict")
} else{
cat ("\nFAIL: asthma and copd conflict not resolved!")
quit()
}
cat("\nExtracting flu positive without asthma")
table(fp_adults$asthma)
cat("\nNo. of asthmatics:", table(fp_adults$asthma)[[2]]
, "\nNo. of non-asthmatics:", table(fp_adults$asthma)[[1]])
str(fp_adults$asthma)
table(fp_adults$obesity)
table(fp_adults$obesity, fp_adults$asthma)
fp_adults_na = fp_adults[fp_adults$asthma == 0,]
table(fp_adults_na$obesity)
table(fp_adults_na$obesity, fp_adults_na$asthma)
#============
# hc
#============