rm(list=ls()) #install.packages("survival",destdir="D:/R_total/Rbag") options("scipen"=100,"digits"=4) # Disable scientific notation library(haven) data <- read_sav("E:/data/work/hospital.sav") attach(data) names(data) # Part A: Initial Data Cleaning # 1. Remove outliers table(data$cancer_diagnosis) data$cancer_diagnosis <- gsub('[\n]','',data$cancer_diagnosis) # Remove leading and trailing spaces data$cancer_diagnosis <- trimws(data$cancer_diagnosis, which = c("both","left","right"), whitespace = "[ \t\r\n]") table(data$cancer_diagnosis) newdata <- data.frame(table(data$cancer_diagnosis)) # 2. Check missing value ratio pMiss <- function(x){sum(is.na(x))/length(x)*100} apply(data,2,pMiss) # Part B: Statistical Analysis # B-1. Select lung cancer population # Lung cancer variable data$lung_a <- ifelse( grepl("lung",data$cancer_diagnosis)==TRUE & grepl("cancer",data$cancer_diagnosis)==TRUE,"100", "0" ) data$lung_a table(data$lung_a) data1 <- data[data$lung_a=="100",] table(data1$cancer_diagnosis) data1$lung_b <- ifelse( data1$cancer_diagnosis=="lung mass, breast cancer" | data1$cancer_diagnosis=="colorectal cancer lung metastasis","non", "1" ) data1$lung_b table(data1$lung_b) # Export all lung cancer data data_lung <- data1[data1$lung_b=="1",] table(data_lung$cancer_diagnosis) data_lung <- data_lung[!duplicated(data_lung$case_number),] ############################## Table 1 # A. Table 1: General Description # 1. shapiro.test(data_lung$age) shapiro.test(data_lung$age[data_lung$planned_admission==0]) shapiro.test(data_lung$age[data_lung$planned_admission==1]) wilcox.test(data_lung$age ~ data_lung$planned_admission) # 2. shapiro.test(data_lung$BMI) shapiro.test(data_lung$BMI[data_lung$planned_admission==0]) shapiro.test(data_lung$BMI[data_lung$planned_admission==1]) wilcox.test(data_lung$BMI ~ data_lung$planned_admission) # 3. shapiro.test(data_lung$SOFA_score) shapiro.test(data_lung$SOFA_score[data_lung$planned_admission==0]) shapiro.test(data_lung$SOFA_score[data_lung$planned_admission==1]) wilcox.test(data_lung$SOFA_score ~ data_lung$planned_admission) # shapiro.test(data_lung$APACHE_score) shapiro.test(data_lung$APACHE_score[data_lung$planned_admission==0]) shapiro.test(data_lung$APACHE_score[data_lung$planned_admission==1]) wilcox.test(data_lung$APACHE_score ~ data_lung$planned_admission) library(tableone) myVars <- c("age","gender","BMI", "SOFA_score","APACHE_score", "survival_90d","ICU_death","hospital_death", "mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis") catVars <- c("gender","mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis", "survival_90d","ICU_death","hospital_death") # Define categorical variables nonvar <- c("age","BMI","SOFA_score","APACHE_score") # Specify which variables are non-normally distributed table <- CreateTableOne(vars = myVars, ## Variables to display factorVars = catVars, # Categorical variables strata = "planned_admission", # Stratification data = data_lung, addOverall = TRUE) # Add overall column table1 <- print(table, # Create table function (including conditions 1.2) showAllLevels=TRUE, # Show all variables catDigits = 1,contDigits = 1,pDigits = 3, # Number of decimal places nonnormal = nonvar, quote = FALSE, # Do not show quotes noSpaces = TRUE, # Delete spaces for alignment printToggle = TRUE) # Display output results #write.csv(table1, "E:/outcome/6.csv",fileEncoding="GBK") names(data_lung) # A Table <- xtabs(~data_lung$planned_admission + data_lung$ICU_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$planned_admission + data_lung$hospital_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$planned_admission + data_lung$survival_90d, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction # B Table <- xtabs(~data_lung$planned_admission + data_lung$gender, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # D Table <- xtabs(~data_lung$planned_admission + data_lung$mechanical_ventilation, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$planned_admission + data_lung$sedation_treatment, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$planned_admission + data_lung$conventional_oxygen, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # F Table <- xtabs(~data_lung$planned_admission + data_lung$shock_diagnosis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$planned_admission + data_lung$sepsis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$planned_admission + data_lung$respiratory_failure, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$planned_admission + data_lung$ARDS, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$planned_admission + data_lung$acute_kidney_injury, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ############################## Table 2 names(data_lung) table(data_lung$transfer_source) data_lung$transfer_source_new <- ifelse( data_lung$transfer_source == 4,3,data_lung$transfer_source ) data_lung$transfer_source_new table(data_lung$transfer_source_new) # A. Table 1: General Description # 1. shapiro.test(data_lung$age) shapiro.test(data_lung$age[data_lung$transfer_source_new==1]) shapiro.test(data_lung$age[data_lung$transfer_source_new==2]) shapiro.test(data_lung$age[data_lung$transfer_source_new==3]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(age ~ transfer_source_new, data=data_lung) # 2. shapiro.test(data_lung$BMI) shapiro.test(data_lung$BMI[data_lung$transfer_source_new==1]) shapiro.test(data_lung$BMI[data_lung$transfer_source_new==2]) shapiro.test(data_lung$BMI[data_lung$transfer_source_new==3]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(BMI ~ transfer_source_new, data=data_lung) # 3. shapiro.test(data_lung$SOFA_score) shapiro.test(data_lung$SOFA_score[data_lung$transfer_source_new==1]) shapiro.test(data_lung$SOFA_score[data_lung$transfer_source_new==2]) shapiro.test(data_lung$SOFA_score[data_lung$transfer_source_new==3]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(SOFA_score ~ transfer_source_new, data=data_lung) # shapiro.test(data_lung$APACHE_score) shapiro.test(data_lung$APACHE_score[data_lung$transfer_source_new==1]) shapiro.test(data_lung$APACHE_score[data_lung$transfer_source_new==2]) shapiro.test(data_lung$APACHE_score[data_lung$transfer_source_new==3]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(APACHE_score ~ transfer_source_new, data=data_lung) library(tableone) myVars <- c("age","gender","BMI", "SOFA_score","APACHE_score", "survival_90d","ICU_death","hospital_death", "mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis") catVars <- c("gender","mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis", "survival_90d","ICU_death","hospital_death") # Define categorical variables nonvar <- c("age","BMI","SOFA_score","APACHE_score") # Specify which variables are non-normally distributed table <- CreateTableOne(vars = myVars, ## Variables to display factorVars = catVars, # Categorical variables strata = "transfer_source_new", # Stratification data = data_lung, addOverall = TRUE) # Add overall column table1 <- print(table, # Create table function (including conditions 1.2) showAllLevels=TRUE, # Show all variables catDigits = 1,contDigits = 1,pDigits = 3, # Number of decimal places nonnormal = nonvar, quote = FALSE, # Do not show quotes noSpaces = TRUE, # Delete spaces for alignment printToggle = TRUE) # Display output results #write.csv(table1, "E:/outcome/9.csv",fileEncoding="GBK") names(data_lung) # A Table <- xtabs(~data_lung$transfer_source_new + data_lung$ICU_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies fisher.test(Table) Table <- xtabs(~data_lung$transfer_source_new + data_lung$hospital_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies fisher.test(Table) Table <- xtabs(~data_lung$transfer_source_new + data_lung$survival_90d, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction # B Table <- xtabs(~data_lung$transfer_source_new + data_lung$gender, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies fisher.test(Table) # C Table <- xtabs(~data_lung$transfer_source_new + data_lung$mechanical_ventilation, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$transfer_source_new + data_lung$sedation_treatment, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$transfer_source_new + data_lung$conventional_oxygen, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies fisher.test(Table) # D Table <- xtabs(~data_lung$transfer_source_new + data_lung$shock_diagnosis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies fisher.test(Table) Table <- xtabs(~data_lung$transfer_source_new + data_lung$sepsis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies fisher.test(Table) Table <- xtabs(~data_lung$transfer_source_new + data_lung$respiratory_failure, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$transfer_source_new + data_lung$ARDS, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies fisher.test(Table) Table <- xtabs(~data_lung$transfer_source_new + data_lung$acute_kidney_injury, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies fisher.test(Table) ############################## Table 3 names(data_lung) table(data_lung$transfer_source) # Grouping data_lung$treatment_history_group <- ifelse( data_lung$radiation_history == 1 | data_lung$chemotherapy_history == 1,0,1 ) data_lung$treatment_history_group table(data_lung$treatment_history_group) # A. Table 1: General Description # 1. shapiro.test(data_lung$age) shapiro.test(data_lung$age[data_lung$treatment_history_group==0]) shapiro.test(data_lung$age[data_lung$treatment_history_group==1]) wilcox.test(data_lung$age ~ data_lung$treatment_history_group) # 2. shapiro.test(data_lung$BMI) shapiro.test(data_lung$BMI[data_lung$treatment_history_group==0]) shapiro.test(data_lung$BMI[data_lung$treatment_history_group==1]) wilcox.test(data_lung$BMI ~ data_lung$treatment_history_group) # 3. shapiro.test(data_lung$SOFA_score) shapiro.test(data_lung$SOFA_score[data_lung$treatment_history_group==0]) shapiro.test(data_lung$SOFA_score[data_lung$treatment_history_group==1]) wilcox.test(data_lung$SOFA_score ~ data_lung$treatment_history_group) # shapiro.test(data_lung$APACHE_score) shapiro.test(data_lung$APACHE_score[data_lung$treatment_history_group==0]) shapiro.test(data_lung$APACHE_score[data_lung$treatment_history_group==1]) wilcox.test(data_lung$APACHE_score ~ data_lung$treatment_history_group) library(tableone) myVars <- c("age","gender","BMI", "SOFA_score","APACHE_score", "survival_90d","ICU_death","hospital_death", "mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis") catVars <- c("gender","mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis", "survival_90d","ICU_death","hospital_death") # Define categorical variables nonvar <- c("age","BMI","SOFA_score","APACHE_score") # Specify which variables are non-normally distributed table <- CreateTableOne(vars = myVars, ## Variables to display factorVars = catVars, # Categorical variables strata = "treatment_history_group", # Stratification data = data_lung, addOverall = TRUE) # Add overall column table1 <- print(table, # Create table function (including conditions 1.2) showAllLevels=TRUE, # Show all variables catDigits = 1,contDigits = 1,pDigits = 3, # Number of decimal places nonnormal = nonvar, quote = FALSE, # Do not show quotes noSpaces = TRUE, # Delete spaces for alignment printToggle = TRUE) # Display output results #write.csv(table1, "E:/outcome/51.csv",fileEncoding="GBK") names(data_lung) # A Table <- xtabs(~data_lung$treatment_history_group + data_lung$ICU_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$treatment_history_group + data_lung$hospital_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$treatment_history_group + data_lung$survival_90d, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction # B Table <- xtabs(~data_lung$treatment_history_group + data_lung$gender, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # D Table <- xtabs(~data_lung$treatment_history_group + data_lung$mechanical_ventilation, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$treatment_history_group + data_lung$sedation_treatment, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$treatment_history_group + data_lung$conventional_oxygen, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # F Table <- xtabs(~data_lung$treatment_history_group + data_lung$shock_diagnosis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$treatment_history_group + data_lung$sepsis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$treatment_history_group + data_lung$respiratory_failure, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$treatment_history_group + data_lung$ARDS, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$treatment_history_group + data_lung$acute_kidney_injury, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ############################## Table 4 names(data_lung) table(data_lung$other_infection_medications) # Grouping data_lung$fungal_gp <- ifelse( data_lung$echinocandins == 1 | data_lung$triazoles == 1,1,0 ) data_lung$fungal_gp table(data_lung$fungal_gp) data_lung$bacterial_gp <- ifelse( data_lung$carbapenems == 1 | data_lung$beta_lactam == 1 | data_lung$glycopeptides == 1 | data_lung$tigecycline == 1,1,0 ) data_lung$bacterial_gp table(data_lung$bacterial_gp) data_lung$anti_infection_gp <- ifelse( data_lung$fungal_gp == 0 & data_lung$bacterial_gp == 0,0, ifelse( data_lung$fungal_gp == 1 & data_lung$bacterial_gp == 1,1,2 ) ) data_lung$anti_infection_gp table(data_lung$anti_infection_gp) h <- data_lung[data_lung$anti_infection_gp == 0,] table(h$fungal_gp) table(h$bacterial_gp) table(h$other_infection_medications) data_lung$anti_infection_group <- ifelse( data_lung$anti_infection_gp == 0 & data_lung$other_infection_medications == 0,0, ifelse( data_lung$anti_infection_gp == 1,1,2 ) ) data_lung$anti_infection_group table(data_lung$anti_infection_group) # A. Table 1: General Description # 1. shapiro.test(data_lung$age) shapiro.test(data_lung$age[data_lung$anti_infection_group == 0]) shapiro.test(data_lung$age[data_lung$anti_infection_group == 1]) shapiro.test(data_lung$age[data_lung$anti_infection_group == 2]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(age ~ anti_infection_group, data=data_lung) # 2. shapiro.test(data_lung$BMI) shapiro.test(data_lung$BMI[data_lung$anti_infection_group == 0]) shapiro.test(data_lung$BMI[data_lung$anti_infection_group == 1]) shapiro.test(data_lung$BMI[data_lung$anti_infection_group == 2]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(BMI ~ anti_infection_group, data=data_lung) # 3. shapiro.test(data_lung$SOFA_score) shapiro.test(data_lung$SOFA_score[data_lung$anti_infection_group == 0]) shapiro.test(data_lung$SOFA_score[data_lung$anti_infection_group == 1]) shapiro.test(data_lung$SOFA_score[data_lung$anti_infection_group == 2]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(SOFA_score ~ anti_infection_group, data=data_lung) # shapiro.test(data_lung$APACHE_score) shapiro.test(data_lung$APACHE_score[data_lung$anti_infection_group == 0]) shapiro.test(data_lung$APACHE_score[data_lung$anti_infection_group == 1]) shapiro.test(data_lung$APACHE_score[data_lung$anti_infection_group == 2]) # Kruskal-Wallis H test - non-parametric test (3 groups) - differences between groups kruskal.test(APACHE_score ~ anti_infection_group, data=data_lung) library(tableone) myVars <- c("age","gender","BMI", "SOFA_score","APACHE_score", "survival_90d","ICU_death","hospital_death", "mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis") catVars <- c("gender","mechanical_ventilation","sedation_treatment","conventional_oxygen", "sepsis","respiratory_failure","ARDS","acute_kidney_injury","shock_diagnosis", "survival_90d","ICU_death","hospital_death") # Define categorical variables nonvar <- c("age","BMI","SOFA_score","APACHE_score") # Specify which variables are non-normally distributed table <- CreateTableOne(vars = myVars, ## Variables to display factorVars = catVars, # Categorical variables strata = "anti_infection_group", # Stratification data = data_lung, addOverall = TRUE) # Add overall column table1 <- print(table, # Create table function (including conditions 1.2) showAllLevels=TRUE, # Show all variables catDigits = 1,contDigits = 1,pDigits = 3, # Number of decimal places nonnormal = nonvar, quote = FALSE, # Do not show quotes noSpaces = TRUE, # Delete spaces for alignment printToggle = TRUE) # Display output results #write.csv(table1, "E:/outcome/123.csv",fileEncoding="GBK") names(data_lung) # A Table <- xtabs(~data_lung$anti_infection_group + data_lung$ICU_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$anti_infection_group + data_lung$hospital_death, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$anti_infection_group + data_lung$survival_90d, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction # B Table <- xtabs(~data_lung$anti_infection_group + data_lung$gender, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # D Table <- xtabs(~data_lung$anti_infection_group + data_lung$mechanical_ventilation, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction Table <- xtabs(~data_lung$anti_infection_group + data_lung$sedation_treatment, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$anti_infection_group + data_lung$conventional_oxygen, data=data_lung) Table prop.table(Table,1) # Calculate row frequency ratio chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value # F Table <- xtabs(~data_lung$anti_infection_group + data_lung$shock_diagnosis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$anti_infection_group + data_lung$sepsis, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$anti_infection_group + data_lung$respiratory_failure, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$anti_infection_group + data_lung$ARDS, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction ab <- chisq.test(Table,correct = F) # Chi-square test correct = F No correction round(ab$p.value,3) # Extract p-value Table <- xtabs(~data_lung$anti_infection_group + data_lung$acute_kidney_injury, data=data_lung) Table chisq.test(Table)$expected # View expected frequencies chisq.test(Table,correct = F) # Chi-square test correct = F No correction