library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(gtsummary)
library(survival)
library(labelled)
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ stringr 1.4.0
## ✓ tidyr   1.1.1     ✓ forcats 0.5.0
## ✓ readr   1.3.1
## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(broom)
library(ggplot2)
library(survminer)
## Loading required package: ggpubr
library(VIM)
## Loading required package: colorspace
## Loading required package: grid
## VIM is ready to use.
## Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues
## 
## Attaching package: 'VIM'
## The following object is masked from 'package:datasets':
## 
##     sleep
library(tibble)
library(ggplot2)
library(OddsPlotty)
library(e1071)
library(ggthemes)
library(mlbench)
library(caret)
## Loading required package: lattice
## 
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
## 
##     lift
## The following object is masked from 'package:survival':
## 
##     cluster
load("TextbookOutcomes.RData")
TextbookOutcomes <- 
  TextbookOutcomes %>%
  mutate(TextbookOutcomes, Age = ifelse(Age >= 85, "85+", 
                                               ifelse(Age >= 75, "75-84", 
                                                      ifelse(Age >= 65, "65-74", 
                                                             ifelse(Age >=0, "0-65", NA)))))
### Recoding mortality


TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == -99] <- "No"

TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 0] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 1] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 2] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 3] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 4] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 5] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 6] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 7] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 8] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 9] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 10] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 11] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 12] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 13] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 14] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 15] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 16] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 17] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 18] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 19] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 20] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 21] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 22] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 23] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 24] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 25] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 26] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 27] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 28] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 29] <- "Yes"
TextbookOutcomes$DOpertoD[TextbookOutcomes$DOpertoD == 30] <- "Yes"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "EXCISION AMPULLA VATER"] <- NA
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "EXCISION LESION PANCREAS"] <- NA
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "UNLISTED PROCEDURE PANCREAS"] <- NA
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT WHIPPLE W/O PANCREATOJEJUNOSTOMY"] <- "Whipple"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT W/PANCREATOJEJUNOSTOMY"] <- "Whipple"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT DSTL STOT W/PNCRTCOJEJUNOSTOMY"] <- "Distal Pancreatectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT DSTL STOT W/O PNCRTCOJEJUNOSTOMY"] <- "Distal Pancreatectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT PROX STOT W/PANCREATOJEJUNOSTOMY"] <- "Whipple"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT PROX STOT W/O PANCREATOJEJUNOSTOMY"] <- "Whipple"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PANCREATECTOMY TOTAL"] <- "Total Pancreatectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "PNCRTECT DSTL NR-TOT W/PRSRV DUO CHLD-TYP PX"] <- "Total Pancreatectomy"


TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "HEPATECTOMY RESCJ PARTIAL LOBECTOMY"] <- "Partial Lobectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "HEPATECTOMY RESCJ TOTAL LEFT LOBECTOMY"] <- "Lobectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "HEPATECTOMY RESCJ TOTAL RIGHT LOBECTOMY"] <- "Lobectomy"
TextbookOutcomes$PRNCPTX[TextbookOutcomes$PRNCPTX == "HEPATECTOMY RESCJ TRISEGMENTECTOMY"] <- "Trisegmentectomy"
table(TextbookOutcomes$PRNCPTX)
## 
## Distal Pancreatectomy             Lobectomy     Partial Lobectomy 
##                  8292                  4274                 11817 
##  Total Pancreatectomy      Trisegmentectomy               Whipple 
##                   706                  1366                 16464
TextbookOutcomes <-
  TextbookOutcomes %>%
  mutate(TextbookOutcomes, PatientGroup = ifelse(PRNCPTX == "Partial Lobectomy", "Liver",
                                                 ifelse(PRNCPTX == "Lobectomy", "Liver",
                                                        ifelse(PRNCPTX == "Trisegmentectomy", "Liver",
                                                               ifelse(PRNCPTX == "Whipple", "Pancreas",
                                                                             ifelse(PRNCPTX == "Distal Pancreatectomy", "Pancreas",
                                                                                    ifelse(PRNCPTX == "Total Pancreatectomy", "Pancreas", NA)))))))
### Recoding readmission


TextbookOutcomes$READMISSION1[TextbookOutcomes$READMISSION1 == "NULL"] <- NA


TextbookOutcomes$READMISSION1[TextbookOutcomes$READMISSION1 == "NULL"] <- NA
table(TextbookOutcomes$READMISSION1)
## 
##    No   Yes 
## 27725  6219
TextbookOutcomes$DOptoDis[TextbookOutcomes$DOptoDis == -99] <- NA
table(TextbookOutcomes$PRNCPTX)
## 
## Distal Pancreatectomy             Lobectomy     Partial Lobectomy 
##                  8292                  4274                 11817 
##  Total Pancreatectomy      Trisegmentectomy               Whipple 
##                   706                  1366                 16464
TextbookOutcomes$RACE_NEW[TextbookOutcomes$RACE_NEW == "American Indian or Alaska Native"] <- "Other"
TextbookOutcomes$RACE_NEW[TextbookOutcomes$RACE_NEW == "Asian"] <- "Other"
TextbookOutcomes$RACE_NEW[TextbookOutcomes$RACE_NEW == "Native Hawaiian or Pacific Islander"] <- "Other"
TextbookOutcomes$RACE_NEW[TextbookOutcomes$RACE_NEW == "Black or African American"] <- "Black"
TextbookOutcomes$RACE_NEW[TextbookOutcomes$RACE_NEW == "Unknown/Not Reported"] <- NA
TextbookOutcomes$WEIGHT[TextbookOutcomes$WEIGHT ==-99] <- NA
TextbookOutcomes$HEIGHT[TextbookOutcomes$HEIGHT ==-99] <- NA
TextbookOutcomes$BMI <- (TextbookOutcomes$WEIGHT / TextbookOutcomes$HEIGHT / TextbookOutcomes$HEIGHT) *703
TextbookOutcomes <- 
  TextbookOutcomes %>%
  mutate(TextbookOutcomes, BMILabled = ifelse(BMI >= 40, "Morbidly Obese", 
                                               ifelse(BMI >= 30, "Obese", 
                                                      ifelse(BMI >= 25, "Overweight", 
                                                             ifelse(BMI >=18.5, "Normal Weight",
                                                                    ifelse(BMI <= 18.49, "Underweight", NA))))))
TextbookOutcomes$ASACLAS[TextbookOutcomes$ASACLAS == "5-Moribund"] <- NA

TextbookOutcomes$ASACLAS[TextbookOutcomes$ASACLAS == "None assigned"] <- NA
### Create MFI column

TextbookOutcomes$DIABETES[TextbookOutcomes$DIABETES == "INSULIN"] <- "Yes"

TextbookOutcomes$DIABETES[TextbookOutcomes$DIABETES == "NON-INSULIN"] <- "Yes"
###Create new numeric column that will be used to create the MFI5 column 0, >1, and greater than >2
##Diabeties recoded for MFI
TextbookOutcomes <-
  TextbookOutcomes %>%
  mutate(TextbookOutcomes, Diabetes1 = ifelse(DIABETES == "INSULIN", "Yes",
                                          ifelse(DIABETES == "NON-INSULIN", "Yes",
                                                 ifelse(DIABETES == "NO", "No", "NA"))))

###Create new numeric column that will be used to create the MFI5 column 0, >1, and greater than >2 ###CHF recoded for MFI

TextbookOutcomes <- TextbookOutcomes %>% mutate(TextbookOutcomes, CHFMFI = ifelse(HXCHF == “Yes”, “1”, ifelse(HXCHF == “No”, “0”, “NA”)))

###Create new numeric column that will be used to create the MFI5 column 0, >1, and greater than >2 ### COPD recoded for MFI

TextbookOutcomes <- TextbookOutcomes %>% mutate(TextbookOutcomes, COPDMFI = ifelse(HXCOPD == “Yes”, “1”, ifelse(HXCOPD == “No”, “0”, “NA”)))

###Create new numeric column that will be used to create the MFI5 column 0, >1, and greater than >2 ### Hypertension with medications recoded for MFI

TextbookOutcomes <- TextbookOutcomes %>% mutate(TextbookOutcomes, HYPERMEDMFI = ifelse(HYPERMED == “Yes”, “1”, ifelse(HYPERMED == “No”, “0”, “NA”)))

##recode fnstatus2

TextbookOutcomes$FNSTATUS2[TextbookOutcomes$FNSTATUS2 == "Unknown"] <- NA

TextbookOutcomes <- TextbookOutcomes %>% mutate(TextbookOutcomes, FuncStatus = ifelse(FNSTATUS2 == “Yes”, “1”, ifelse(FNSTATUS2 == “No”, “0”, NA)))

##making the columns numeric to add them properly

TextbookOutcomesHYPERMEDMFI<−as.numeric(TextbookOutcomesHYPERMEDMFI) TextbookOutcomesCOPDMFI<−as.numeric(TextbookOutcomesCOPDMFI) TextbookOutcomesCHFMFI<−as.numeric(TextbookOutcomesCHFMFI) TextbookOutcomesDiabetesMFI<−as.numeric(TextbookOutcomesDiabetesMFI) TextbookOutcomesFuncStatus<−as.numeric(TextbookOutcomesFuncStatus)

###Creating MFI column

TextbookOutcomesMFI5<−(TextbookOutcomesHYPERMEDMFI + TextbookOutcomesCOPDMFI+TextbookOutcomesCHFMFI + TextbookOutcomesDiabetesMFI+TextbookOutcomesFuncStatus )

##recoding Hep and Pan targeted Complications to yes or no (will need to add in targeted complications Pan: Fistula, Delayed Gastric Emptying and what about percdrain? | Hep: Bile leakage, hepliverfail)

TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Biochemical Leak only"] <- "No"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="No evidence of Biochemical Leak or POPF"] <- "No"

TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-persistent drainage, drain continued >7 days"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-clinical diagnosis, percutaneous drainage performed"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-persistent drainage, percutaneous drainage performed"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-persistent drainage, NPO-TPN"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-clinical diagnosis, drain continued >7 days"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes, Grade B POPF present"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-clinical diagnosis, spontaneous wound drainage"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-clinical diagnosis, NPO-TPN"] <- "Yes"

TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-clinical diagnosis, reoperation performed"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes, Grade C POPF present"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Yes-persistent drainage, reoperation performed"] <- "Yes"
TextbookOutcomes$PAN_FISTULA[TextbookOutcomes$PAN_FISTULA =="Unknown"] <- NA



####Delayed Gastric Emptying Recode to yes or no
TextbookOutcomes$PAN_DELGASTRIC_20140315[TextbookOutcomes$PAN_DELGASTRIC_20140315 =="Yes-no oral intake by POD 14"] <- "Yes"
TextbookOutcomes$PAN_DELGASTRIC_20140315[TextbookOutcomes$PAN_DELGASTRIC_20140315 =="Yes-tube to external drainage/NG tube present/reinserted"] <- "Yes"


TextbookOutcomes$PAN_DELGASTRIC_20140315[TextbookOutcomes$PAN_DELGASTRIC_20140315 =="Unknown"] <- NA

###recoding Hep targeted complications bileleakage
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Unknown"] <- NA
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-clinical diagnosis, drain continued on or after POD3"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-clinical diagnosis, percutaneous drainage performed"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-clinical diagnosis, reoperation performed"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-clinical diagnosis, spontaneous wound drainage"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-persistent drainage, drain continued on or after POD3"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-persistent drainage, percutaneous drainage performed"] <- "Yes"
TextbookOutcomes$HEP_BILELEAKAGE[TextbookOutcomes$HEP_BILELEAKAGE =="Yes-persistent drainage, reoperation performed"] <- "Yes"

##recoding hep targeted complications Liver failure (Post Hepatectomy Liver Failure)
TextbookOutcomes$HEP_LIVERFAIL[TextbookOutcomes$HEP_LIVERFAIL =="Yes-PHLF (receiving clotting factors to maintain INR)"] <- "Yes"
TextbookOutcomes$HEP_LIVERFAIL[TextbookOutcomes$HEP_LIVERFAIL =="Yes-meets criteria for PHLF"] <- "Yes"

TextbookOutcomes$HEP_LIVERFAIL[TextbookOutcomes$HEP_LIVERFAIL =="No-does not meet criteria for PHLF"] <- "No"

table(TextbookOutcomes$HEP_LIVERFAIL)
## 
##    No   Yes 
## 16629   828
table(TextbookOutcomes$PRNCPTX)
## 
## Distal Pancreatectomy             Lobectomy     Partial Lobectomy 
##                  8292                  4274                 11817 
##  Total Pancreatectomy      Trisegmentectomy               Whipple 
##                   706                  1366                 16464
###Creating Targeted Column for Hep Complications
TextbookOutcomes1 <- TextbookOutcomes %>%
  mutate(TextbookOutcomes, HepComplications = ifelse(HEP_LIVERFAIL == "Yes", "Yes",
                                                   ifelse(HEP_BILELEAKAGE == "Yes", "Yes", "No")))
table(TextbookOutcomes1$HepComplications)
## 
##    No   Yes 
## 15510  1842
TextbookOutcomes2 <- TextbookOutcomes1 %>%
  mutate(TextbookOutcomes, PanComplications = ifelse(PAN_FISTULA == "Yes", "Yes",
                                                   ifelse(PAN_DELGASTRIC_20140315 == "Yes", "Yes", "No")))
str(TextbookOutcomes2$PanComplications)
##  chr [1:44235] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA ...
sum(is.na(TextbookOutcomes2$PanComplications))
## [1] 17754
###creating a true textbookoutcomes column for pan and liver

TextbookOutcomes2$PanComplications[TextbookOutcomes2$PanComplications ==NA] <- "NA"
TextbookOutcomes2$PanComplications[TextbookOutcomes2$HepComplications ==NA] <- "NA"

table(TextbookOutcomes2$PanComplications)
## 
##    No   Yes 
## 19879  6602
TextbookOutcomes2$PanComplications[TextbookOutcomes2$PanComplications ==NA] <- "NA"

sum(is.na(TextbookOutcomes2$PanComplications))
## [1] 17754
table(is.na(TextbookOutcomes2$PanComplications))
## 
## FALSE  TRUE 
## 26481 17754
### Ifelse function to create new column for any complication (will need to add in targeted complications Pan: Fistula, Delayed Gastric Emptying | Hep: Bile leakage, hepliverfail)

TextbookOutcomes3 <- TextbookOutcomes2 %>%
  mutate(TextbookOutcomes, AnyComplication = ifelse(CDARREST == "Cardiac Arrest Requiring CPR", "Yes",
                                                   ifelse(CDMI == "Myocardial Infarction", "Yes",
                                                          ifelse(OUPNEUMO == "Pneumonia", "Yes",
                                                                 ifelse(RENAINSF == "Progressive Renal Insufficiency", "Yes",
                                                                        ifelse(OPRENAFL == "Acute Renal Failure", "Yes",
                                                                               ifelse(PULEMBOL == "Pulmonary Embolism", "Yes",
                                                                                      ifelse(OTHDVT == "DVT Requiring Therapy", "Yes",
                                                                                             ifelse(RETURNOR == "Yes", "Yes",
                                                                                                    ifelse(ORGSPCSSI == "Organ/Space SSI", "Yes",
                                                                                                           ifelse(PRSEPIS == "Yes", "Yes",
                                                                                                                  ifelse(REINTUB == "Unplanned Intubation", "Yes",
                                                                                                                         ifelse(URNINFEC == "Urinary Tract Infection", "Yes",
                                                                                                                                ifelse(SUPINFEC == "Superficial Incisional SSI", "Yes",
                                                                                                                                       ifelse(FAILWEAN == "On Ventilator greater than 48 Hours", "Yes",
                                                                                                                                              ifelse(CNSCVA == "Stroke/CVA", "Yes",
                                                                                                                                                     ifelse(DEHIS == "Wound Disruption", "Yes", "No")))))))))))))))))
##subsetting Procedure with DoptoDIS information to obtain the mean

TextbookOutcomesDistalPan <-
  subset(TextbookOutcomes,  PRNCPTX == "Distal Pancreatectomy")

TextbookOutcomesLobectomy <-
  subset(TextbookOutcomes,  PRNCPTX == "Lobectomy")
  
TextbookOutcomesOtherPan <-
  subset(TextbookOutcomes,  PRNCPTX == "Other Pancreas")
  
TextbookOutcomesPartialLobectomy <-
  subset(TextbookOutcomes,  PRNCPTX == "Partial Lobectomy")
  
TextbookOutcomesTotalPan <-
  subset(TextbookOutcomes,  PRNCPTX == "Total Pancreatectomy")
  
TextbookOutcomesTrisegmentectomy <-
  subset(TextbookOutcomes,  PRNCPTX == "Trisegmentectomy")
  
TextbookOutcomesWhipple <-
  subset(TextbookOutcomes,  PRNCPTX == "Whipple")
###obtaining the 75th percential for LOS defined as day of surgery to date of discharge

SeventyFifthPercentileDistalPan = TextbookOutcomesDistalPan$DOptoDis
SeventyFifthPercentileLobectomy = TextbookOutcomesLobectomy$DOptoDis
SeventyFifthPercentileOtherPan = TextbookOutcomesOtherPan$DOptoDis
SeventyFifthPercentilePartialLobectomy = TextbookOutcomesPartialLobectomy$DOptoDis
SeventyFifthPercentileTotalPan = TextbookOutcomesTotalPan$DOptoDis
SeventyFifthPercentileTrisegmentectomy = TextbookOutcomesTrisegmentectomy$DOptoDis
SeventyFifthPercentileWhipple = TextbookOutcomesWhipple$DOptoDis
quantile(SeventyFifthPercentileDistalPan, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    4    5    7   88
quantile(SeventyFifthPercentileLobectomy, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    5    6    8  114
quantile(SeventyFifthPercentileOtherPan, na.rm = T)
##   0%  25%  50%  75% 100% 
##   NA   NA   NA   NA   NA
quantile(SeventyFifthPercentilePartialLobectomy, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    3    5    6   85
quantile(SeventyFifthPercentileTotalPan, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    6    8   12   89
quantile(SeventyFifthPercentileTrisegmentectomy, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    5    7   10   78
quantile(SeventyFifthPercentileWhipple, na.rm = T)
##   0%  25%  50%  75% 100% 
##    0    6    8   12  111
TextbookOutcomes3$ELOSDistalPan <- ifelse(TextbookOutcomes3$PRNCPTX == "Distal Pancreatectomy" & TextbookOutcomes3$DOptoDis >= 7, "Yes", "No")

TextbookOutcomes3$ELOSLobectomy <- ifelse(TextbookOutcomes3$PRNCPTX == "Lobectomy" & TextbookOutcomes3$DOptoDis >= 8, "Yes", "No")

TextbookOutcomes3$ELOSOtherPan <- ifelse(TextbookOutcomes3$PRNCPTX == "Other Pancreas" & TextbookOutcomes3$DOptoDis >= 7, "Yes", "No")

TextbookOutcomes3$ELOSPartial <- ifelse(TextbookOutcomes3$PRNCPTX == "Partial Lobectomy" & TextbookOutcomes3$DOptoDis >= 6, "Yes", "No")

TextbookOutcomes3$ELOSTotal <- ifelse(TextbookOutcomes3$PRNCPTX == "Total Pancreatectomy" & TextbookOutcomes3$DOptoDis >= 12, "Yes", "No")

TextbookOutcomes3$ELOSTrisegmentectomy <- ifelse(TextbookOutcomes3$PRNCPTX == "Trisegmentectomy" & TextbookOutcomes3$DOptoDis >= 10, "Yes", "No")

TextbookOutcomes3$ELOSWhipple <- ifelse(TextbookOutcomes3$PRNCPTX == "Whipple" & TextbookOutcomes3$DOptoDis >= 12, "Yes", "No")

table(TextbookOutcomes3$ELOSPartial)
## 
##    No   Yes 
## 39501  4153
###recode 9 and up to be considered increased LOS

PanTextbookOutcomes <- TextbookOutcomes3 %>%
  mutate(TextbookOutcomes3, ELOS = ifelse(ELOSDistalPan == "Yes", "Yes", 
                                          ifelse(ELOSLobectomy == "Yes", "Yes",
                                                 ifelse(ELOSOtherPan == "Yes", "Yes",
                                                        ifelse(ELOSPartial == "Yes", "Yes",
                                                               ifelse(ELOSTotal == "Yes", "Yes",
                                                                      ifelse(ELOSTrisegmentectomy == "Yes", "Yes",
                                                                             ifelse(ELOSWhipple == "Yes", "Yes", "No"))))))))

table(PanTextbookOutcomes$ELOS)
## 
##    No   Yes 
## 30578 12853

###subset pancreatic cancer patients prior to creating a Textbook Outcomes Table double the 75th percentile number afterwards

PanTextbookOutcomes <- subset(TextbookOutcomes4, PanComplications == “Yes” | PanComplications == “No”)

table(PanTextbookOutcomes$HepComplications)

PanTextbookOutcomes$TextbookOutcomeHep <- ifelse(PanTextbookOutcomes$ELOS == "No" & PanTextbookOutcomes$DOpertoD == "No" & PanTextbookOutcomes$HepComplications == "No" & PanTextbookOutcomes$AnyComplication == "No" & PanTextbookOutcomes$READMISSION1 == "No",
                  "Yes",
                  "No")



PanTextbookOutcomes$TextbookOutcomePan <- ifelse(PanTextbookOutcomes$ELOS == "No" & PanTextbookOutcomes$DOpertoD == "No" & PanTextbookOutcomes$PanComplications == "No" & PanTextbookOutcomes$AnyComplication == "No" & PanTextbookOutcomes$READMISSION1 == "No",
                  "Yes",
                  "No")


PanTextbookOutcomes$TextbookOutcomeAll <- ifelse(PanTextbookOutcomes$TextbookOutcomePan == "No" & PanTextbookOutcomes$TextbookOutcomeHep == "No",
                  "No",
                  "Yes")


table(PanTextbookOutcomes$TextbookOutcomeHep)
## 
##    No   Yes 
## 20105  6950
table(PanTextbookOutcomes$TextbookOutcomePan)
## 
##    No   Yes 
## 21045  9165
table(PanTextbookOutcomes$TextbookOutcomeAll)
## 
##    No   Yes 
## 19790 16115

PanTextbookOutcomes3 <- PanTextbookOutcomes %>% mutate(PanTextbookOutcomes, TextbookOutcomeAll = ifelse(TextbookOutcomePan == NA, “Yes”, ifelse(TextbookOutcomeHep == “Yes”, “Yes”,“NA”)))

table(PanTextbookOutcomes3$TextbookOutcomeAll)

PanTextbookOutcomes1 <- PanTextbookOutcomes %>% mutate(PanTextbookOutcomes, ModifiedFrailtyIndex5 = ifelse(MFI5 == 0, “0”, ifelse(MFI5 == 1, “1”, ifelse(MFI5 > 2, “>2”, NA))))

PantextBookOutcomesDT <-
  PanTextbookOutcomes %>%
  select(PatientGroup, DOptoDis, Age, SEX, RACE_NEW, BMILabled, ASACLAS, DOpertoD, OPTIME, ELOS, READMISSION1, STEROID, DIABETES, HYPERMED, ASACLAS, ASCITES, HXCHF, DYSPNEA, SMOKE, HXCOPD, DIALYSIS, OPRENAFL, FNSTATUS2, AnyComplication, TextbookOutcomeHep, TextbookOutcomePan, TextbookOutcomeAll, PanComplications, HepComplications, PRNCPTX)
ByProcedure <-
  PanTextbookOutcomes %>%
  select(PatientGroup, DOptoDis, Age, SEX, RACE_NEW, BMILabled, ASACLAS, DOpertoD, OPTIME, ELOS, READMISSION1, STEROID, DIABETES, HYPERMED, ASACLAS, ASCITES, HXCHF, DYSPNEA, SMOKE, HXCOPD, DIALYSIS, OPRENAFL, FNSTATUS2, PAN_FISTULA, PAN_DELGASTRIC_20140315, HEP_LIVERFAIL, HEP_BILELEAKAGE, CDARREST, CDMI, OUPNEUMO, RENAINSF, OPRENAFL, PULEMBOL, OTHDVT, RETURNOR, ORGSPCSSI, PRSEPIS, REINTUB, URNINFEC, SUPINFEC, PRNCPTX)
Underweight <-
  PanTextbookOutcomes %>%
  select(PatientGroup, DOptoDis, Age, SEX, RACE_NEW, BMILabled, ASACLAS, DOpertoD, TextbookOutcomeHep, TextbookOutcomePan, TextbookOutcomeAll)
LOSTable <-
  PanTextbookOutcomes %>%
  select(PRNCPTX, DOptoDis, PatientGroup)
LOSTable %>%
  tbl_summary(
    by = PRNCPTX,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 1316 observations missing `PRNCPTX` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `PRNCPTX` column before passing to `tbl_summary()`.
Variable Overall, N = 42,9191 *Textbook Outcomes Partial Lobectomy, N = 11,8171 Total Pancreatectomy, N = 7061 Trisegmentectomy, N = 1,3661 Whipple, N = 16,4641 p-value2
Distal Pancreatectomy, N = 8,2921 Lobectomy, N = 4,2741
DOptoDis 6.00 (5.00, 9.00) 5.00 (4.00, 7.00) 6.00 (5.00, 8.00) 5.00 (3.00, 6.00) 8.00 (6.00, 12.00) 7.00 (5.00, 10.00) 8.00 (6.00, 12.00) <0.001
Unknown 242 25 21 19 8 10 159
PatientGroup <0.001
Liver 17,457 (41%) 0 (0%) 4,274 (100%) 11,817 (100%) 0 (0%) 1,366 (100%) 0 (0%)
Pancreas 25,462 (59%) 8,292 (100%) 0 (0%) 0 (0%) 706 (100%) 0 (0%) 16,464 (100%)

1 Statistics presented: Median (IQR); n (%)

2 Statistical tests performed: Kruskal-Wallis test; chi-square test of independence

TextbookOutcomes2\(PanComplications[TextbookOutcomes2\)PanComplications ==NA] <- “NA”

TextbookOutcomes3 <- TextbookOutcomes2 %>% mutate(TextbookOutcomes, AnyComplication = ifelse(CDARREST == “Cardiac Arrest Requiring CPR”, “Yes”, ifelse(CDMI == “Myocardial Infarction”, “Yes”, ifelse(OUPNEUMO == “Pneumonia”, “Yes”, ifelse(RENAINSF == “Progressive Renal Insufficiency”, “Yes”, ifelse(OPRENAFL == “Acute Renal Failure”, “Yes”, ifelse(PULEMBOL == “Pulmonary Embolism”, “Yes”, ifelse(OTHDVT == “DVT Requiring Therapy”, “Yes”, ifelse(RETURNOR == “Yes”, “Yes”, ifelse(ORGSPCSSI == “Organ/Space SSI”, “Yes”, ifelse(PRSEPIS == “Yes”, “Yes”, ifelse(REINTUB == “Unplanned Intubation”, “Yes”, ifelse(URNINFEC == “Urinary Tract Infection”, “Yes”, ifelse(SUPINFEC == “Superficial Incisional SSI”, “Yes”, ifelse(FAILWEAN == “On Ventilator greater than 48 Hours”, “Yes”, ifelse(CNSCVA == “Stroke/CVA”, “Yes”, ifelse(DEHIS == “Wound Disruption”, “Yes”,

ByProcedure %>%
  tbl_summary(
    by = PatientGroup,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 1316 observations missing `PatientGroup` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `PatientGroup` column before passing to `tbl_summary()`.
## There was an error in 'add_p()' for variable 'PAN_FISTULA', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'PAN_DELGASTRIC_20140315', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'HEP_LIVERFAIL', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'HEP_BILELEAKAGE', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
Variable Overall, N = 42,9191 *Textbook Outcomes p-value2
Liver, N = 17,4571 Pancreas, N = 25,4621
DOptoDis 6.00 (5.00, 9.00) 5.00 (4.00, 7.00) 7.00 (5.00, 10.00) <0.001
Unknown 242 50 192
Age <0.001
0-65 22,630 (53%) 10,737 (62%) 11,893 (47%)
65-74 13,302 (31%) 4,660 (27%) 8,642 (34%)
75-84 6,399 (15%) 1,907 (11%) 4,492 (18%)
85+ 588 (1.4%) 153 (0.9%) 435 (1.7%)
SEX 0.040
female 21,264 (50%) 8,754 (50%) 12,510 (49%)
male 21,655 (50%) 8,703 (50%) 12,952 (51%)
RACE_NEW <0.001
Black 3,648 (10%) 1,468 (11%) 2,180 (9.8%)
Other 2,498 (6.9%) 1,298 (9.3%) 1,200 (5.4%)
White 29,943 (83%) 11,130 (80%) 18,813 (85%)
Unknown 6,830 3,561 3,269
BMILabled <0.001
Morbidly Obese 1,926 (4.5%) 908 (5.2%) 1,018 (4.0%)
Normal Weight 13,726 (32%) 5,229 (30%) 8,497 (34%)
Obese 11,570 (27%) 5,058 (29%) 6,512 (26%)
Overweight 14,594 (34%) 5,880 (34%) 8,714 (34%)
Underweight 879 (2.1%) 268 (1.5%) 611 (2.4%)
Unknown 224 114 110
ASACLAS <0.001
1-No Disturb 428 (1.0%) 253 (1.5%) 175 (0.7%)
2-Mild Disturb 10,403 (24%) 4,395 (25%) 6,008 (24%)
3-Severe Disturb 29,056 (68%) 11,495 (66%) 17,561 (69%)
4-Life Threat 2,951 (6.9%) 1,270 (7.3%) 1,681 (6.6%)
Unknown 81 44 37
DOpertoD 609 (1.4%) 257 (1.5%) 352 (1.4%) 0.47
OPTIME 270.00 (186.00, 373.00) 216.00 (154.00, 300.00) 312.00 (221.00, 409.00) <0.001
ELOS 12,853 (30%) 5,727 (33%) 7,126 (28%) <0.001
Unknown 242 50 192
READMISSION1 6,018 (18%) 1,725 (13%) 4,293 (22%) <0.001
Unknown 9,960 4,301 5,659
STEROID 1,290 (3.0%) 533 (3.1%) 757 (3.0%) 0.65
DIABETES <0.001
NO 33,197 (77%) 14,381 (82%) 18,816 (74%)
Yes 9,722 (23%) 3,076 (18%) 6,646 (26%)
HYPERMED 21,343 (50%) 8,021 (46%) 13,322 (52%) <0.001
ASCITES 169 (0.4%) 96 (0.5%) 73 (0.3%) <0.001
HXCHF 164 (0.4%) 59 (0.3%) 105 (0.4%) 0.25
DYSPNEA 0.082
AT REST 69 (0.2%) 37 (0.2%) 32 (0.1%)
MODERATE EXERTION 2,241 (5.2%) 921 (5.3%) 1,320 (5.2%)
No 40,609 (95%) 16,499 (95%) 24,110 (95%)
SMOKE 7,065 (16%) 2,698 (15%) 4,367 (17%) <0.001
HXCOPD 1,670 (3.9%) 640 (3.7%) 1,030 (4.0%) 0.049
DIALYSIS 151 (0.4%) 51 (0.3%) 100 (0.4%) 0.10
OPRENAFL 0.30
Acute Renal Failure 373 (0.9%) 162 (0.9%) 211 (0.8%)
No Complication 42,546 (99%) 17,295 (99%) 25,251 (99%)
FNSTATUS2 0.077
Independent 42,512 (99%) 17,308 (99%) 25,204 (99%)
Partially Dependent 319 (0.7%) 111 (0.6%) 208 (0.8%)
Totally Dependent 24 (<0.1%) 8 (<0.1%) 16 (<0.1%)
Unknown 64 30 34
PAN_FISTULA 4,318 (17%) 0 (NA%) 4,318 (17%)
Unknown 17,684 17,457 227
PAN_DELGASTRIC_20140315 3,258 (13%) 0 (NA%) 3,258 (13%)
Unknown 17,577 17,457 120
HEP_LIVERFAIL 828 (4.7%) 828 (4.7%) 0 (NA%)
Unknown 25,462 0 25,462
HEP_BILELEAKAGE 1,252 (7.2%) 1,252 (7.2%) 0 (NA%)
Unknown 25,589 127 25,462
CDARREST <0.001
Cardiac Arrest Requiring CPR 375 (0.9%) 120 (0.7%) 255 (1.0%)
No Complication 42,544 (99%) 17,337 (99%) 25,207 (99%)
CDMI 0.006
Myocardial Infarction 434 (1.0%) 148 (0.8%) 286 (1.1%)
No Complication 42,485 (99%) 17,309 (99%) 25,176 (99%)
OUPNEUMO 0.11
No Complication 41,484 (97%) 16,903 (97%) 24,581 (97%)
Pneumonia 1,435 (3.3%) 554 (3.2%) 881 (3.5%)
RENAINSF 0.20
No Complication 42,653 (99%) 17,338 (99%) 25,315 (99%)
Progressive Renal Insufficiency 266 (0.6%) 119 (0.7%) 147 (0.6%)
PULEMBOL 0.64
No Complication 42,386 (99%) 17,246 (99%) 25,140 (99%)
Pulmonary Embolism 533 (1.2%) 211 (1.2%) 322 (1.3%)
OTHDVT <0.001
DVT Requiring Therapy 957 (2.2%) 284 (1.6%) 673 (2.6%)
No Complication 41,962 (98%) 17,173 (98%) 24,789 (97%)
RETURNOR 1,768 (4.1%) 510 (2.9%) 1,258 (4.9%) <0.001
ORGSPCSSI <0.001
No Complication 37,896 (88%) 16,140 (92%) 21,756 (85%)
Organ/Space SSI 5,023 (12%) 1,317 (7.5%) 3,706 (15%)
PRSEPIS 0.55
None 42,360 (99%) 17,216 (99%) 25,144 (99%)
Sepsis 162 (0.4%) 74 (0.4%) 88 (0.3%)
Septic Shock 20 (<0.1%) 9 (<0.1%) 11 (<0.1%)
SIRS 377 (0.9%) 158 (0.9%) 219 (0.9%)
REINTUB <0.001
No Complication 41,773 (97%) 17,078 (98%) 24,695 (97%)
Unplanned Intubation 1,146 (2.7%) 379 (2.2%) 767 (3.0%)
URNINFEC <0.001
No Complication 41,937 (98%) 17,110 (98%) 24,827 (98%)
Urinary Tract Infection 982 (2.3%) 347 (2.0%) 635 (2.5%)
SUPINFEC <0.001
No Complication 40,825 (95%) 16,851 (97%) 23,974 (94%)
Superficial Incisional SSI 2,094 (4.9%) 606 (3.5%) 1,488 (5.8%)
PRNCPTX <0.001
Distal Pancreatectomy 8,292 (19%) 0 (0%) 8,292 (33%)
Lobectomy 4,274 (10.0%) 4,274 (24%) 0 (0%)
Partial Lobectomy 11,817 (28%) 11,817 (68%) 0 (0%)
Total Pancreatectomy 706 (1.6%) 0 (0%) 706 (2.8%)
Trisegmentectomy 1,366 (3.2%) 1,366 (7.8%) 0 (0%)
Whipple 16,464 (38%) 0 (0%) 16,464 (65%)

1 Statistics presented: Median (IQR); n (%)

2 Statistical tests performed: Wilcoxon rank-sum test; chi-square test of independence

ByProcedure %>%
  tbl_summary(
    by = PRNCPTX,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 1316 observations missing `PRNCPTX` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `PRNCPTX` column before passing to `tbl_summary()`.
## There was an error in 'add_p()' for variable 'ASCITES', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location). LDSTP=10560 is too small for this problem,
##   (pastp=310.94, ipn_0:=ipoin[itp=121]=1692, stp[ipn_0]=312.105).
## Increase workspace or consider using 'simulate.p.value=TRUE'
## There was an error in 'add_p()' for variable 'DYSPNEA', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 501.
## The hash table key cannot be computed because the largest key
## is larger than the largest representable int.
## The algorithm cannot proceed.
## Reduce the workspace, consider using 'simulate.p.value=TRUE' or another algorithm.
## There was an error in 'add_p()' for variable 'DIALYSIS', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location). LDSTP=10560 is too small for this problem,
##   (pastp=363.838, ipn_0:=ipoin[itp=125]=1844, stp[ipn_0]=364.916).
## Increase workspace or consider using 'simulate.p.value=TRUE'
## There was an error in 'add_p()' for variable 'FNSTATUS2', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): Bug in fexact3, it[i=4]=20390: negative key -984893980 (kyy=41809)
## There was an error in 'add_p()' for variable 'RENAINSF', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 7(location). LDSTP=10560 is too small for this problem,
##   (pastp=288.129, ipn_0:=ipoin[itp=259]=345, stp[ipn_0]=286.738).
## Increase workspace or consider using 'simulate.p.value=TRUE'
## There was an error in 'add_p()' for variable 'PRSEPIS', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 501.
## The hash table key cannot be computed because the largest key
## is larger than the largest representable int.
## The algorithm cannot proceed.
## Reduce the workspace, consider using 'simulate.p.value=TRUE' or another algorithm.
Variable Overall, N = 42,9191 *Textbook Outcomes Partial Lobectomy, N = 11,8171 Total Pancreatectomy, N = 7061 Trisegmentectomy, N = 1,3661 Whipple, N = 16,4641 p-value2
Distal Pancreatectomy, N = 8,2921 Lobectomy, N = 4,2741
PatientGroup <0.001
Liver 17,457 (41%) 0 (0%) 4,274 (100%) 11,817 (100%) 0 (0%) 1,366 (100%) 0 (0%)
Pancreas 25,462 (59%) 8,292 (100%) 0 (0%) 0 (0%) 706 (100%) 0 (0%) 16,464 (100%)
DOptoDis 6.00 (5.00, 9.00) 5.00 (4.00, 7.00) 6.00 (5.00, 8.00) 5.00 (3.00, 6.00) 8.00 (6.00, 12.00) 7.00 (5.00, 10.00) 8.00 (6.00, 12.00) <0.001
Unknown 242 25 21 19 8 10 159
Age <0.001
0-65 22,630 (53%) 4,420 (53%) 2,616 (61%) 7,281 (62%) 371 (53%) 840 (61%) 7,102 (43%)
65-74 13,302 (31%) 2,508 (30%) 1,147 (27%) 3,122 (26%) 228 (32%) 391 (29%) 5,906 (36%)
75-84 6,399 (15%) 1,249 (15%) 480 (11%) 1,298 (11%) 99 (14%) 129 (9.4%) 3,144 (19%)
85+ 588 (1.4%) 115 (1.4%) 31 (0.7%) 116 (1.0%) 8 (1.1%) 6 (0.4%) 312 (1.9%)
SEX <0.001
female 21,264 (50%) 4,540 (55%) 2,105 (49%) 5,981 (51%) 353 (50%) 668 (49%) 7,617 (46%)
male 21,655 (50%) 3,752 (45%) 2,169 (51%) 5,836 (49%) 353 (50%) 698 (51%) 8,847 (54%)
RACE_NEW <0.001
Black 3,648 (10%) 833 (11%) 343 (11%) 1,032 (11%) 52 (8.6%) 93 (9.0%) 1,295 (9.1%)
Other 2,498 (6.9%) 389 (5.3%) 343 (11%) 879 (9.1%) 38 (6.3%) 76 (7.4%) 773 (5.4%)
White 29,943 (83%) 6,061 (83%) 2,556 (79%) 7,713 (80%) 515 (85%) 861 (84%) 12,237 (86%)
Unknown 6,830 1,009 1,032 2,193 101 336 2,159
BMILabled <0.001
Morbidly Obese 1,926 (4.5%) 465 (5.6%) 173 (4.1%) 693 (5.9%) 24 (3.4%) 42 (3.1%) 529 (3.2%)
Normal Weight 13,726 (32%) 2,431 (29%) 1,367 (32%) 3,384 (29%) 275 (39%) 478 (35%) 5,791 (35%)
Obese 11,570 (27%) 2,525 (31%) 1,217 (29%) 3,503 (30%) 162 (23%) 338 (25%) 3,825 (23%)
Overweight 14,594 (34%) 2,681 (32%) 1,417 (33%) 3,995 (34%) 222 (32%) 468 (34%) 5,811 (35%)
Underweight 879 (2.1%) 164 (2.0%) 72 (1.7%) 165 (1.4%) 20 (2.8%) 31 (2.3%) 427 (2.6%)
Unknown 224 26 28 77 3 9 81
ASACLAS <0.001
1-No Disturb 428 (1.0%) 104 (1.3%) 103 (2.4%) 139 (1.2%) 2 (0.3%) 11 (0.8%) 69 (0.4%)
2-Mild Disturb 10,403 (24%) 2,376 (29%) 1,055 (25%) 3,003 (25%) 153 (22%) 337 (25%) 3,479 (21%)
3-Severe Disturb 29,056 (68%) 5,337 (64%) 2,765 (65%) 7,844 (67%) 488 (69%) 886 (65%) 11,736 (71%)
4-Life Threat 2,951 (6.9%) 458 (5.5%) 336 (7.9%) 805 (6.8%) 61 (8.7%) 129 (9.5%) 1,162 (7.1%)
Unknown 81 17 15 26 2 3 18
DOpertoD 609 (1.4%) 74 (0.9%) 101 (2.4%) 101 (0.9%) 12 (1.7%) 55 (4.0%) 266 (1.6%) <0.001
OPTIME 270.00 (186.00, 373.00) 215.00 (159.00, 288.00) 262.00 (196.00, 342.00) 193.00 (139.00, 264.00) 345.00 (238.50, 447.75) 310.00 (225.00, 409.00) 356.00 (279.00, 445.00) <0.001
ELOS 12,853 (30%) 2,753 (33%) 1,220 (29%) 4,153 (35%) 193 (28%) 354 (26%) 4,180 (26%) <0.001
Unknown 242 25 21 19 8 10 159
READMISSION1 6,018 (18%) 1,386 (22%) 493 (15%) 1,020 (12%) 146 (25%) 212 (20%) 2,761 (21%) <0.001
Unknown 9,960 1,937 981 3,003 124 317 3,598
STEROID 1,290 (3.0%) 294 (3.5%) 115 (2.7%) 384 (3.2%) 32 (4.5%) 34 (2.5%) 431 (2.6%) <0.001
DIABETES <0.001
NO 33,197 (77%) 6,254 (75%) 3,518 (82%) 9,703 (82%) 436 (62%) 1,160 (85%) 12,126 (74%)
Yes 9,722 (23%) 2,038 (25%) 756 (18%) 2,114 (18%) 270 (38%) 206 (15%) 4,338 (26%)
HYPERMED 21,343 (50%) 4,266 (51%) 1,912 (45%) 5,520 (47%) 350 (50%) 589 (43%) 8,706 (53%) <0.001
ASCITES 169 (0.4%) 19 (0.2%) 16 (0.4%) 71 (0.6%) 6 (0.8%) 9 (0.7%) 48 (0.3%)
HXCHF 164 (0.4%) 41 (0.5%) 13 (0.3%) 44 (0.4%) 2 (0.3%) 2 (0.1%) 62 (0.4%) 0.40
DYSPNEA
AT REST 69 (0.2%) 11 (0.1%) 8 (0.2%) 26 (0.2%) 0 (0%) 3 (0.2%) 21 (0.1%)
MODERATE EXERTION 2,241 (5.2%) 473 (5.7%) 236 (5.5%) 609 (5.2%) 37 (5.2%) 76 (5.6%) 810 (4.9%)
No 40,609 (95%) 7,808 (94%) 4,030 (94%) 11,182 (95%) 669 (95%) 1,287 (94%) 15,633 (95%)
SMOKE 7,065 (16%) 1,372 (17%) 696 (16%) 1,769 (15%) 128 (18%) 233 (17%) 2,867 (17%) <0.001
HXCOPD 1,670 (3.9%) 354 (4.3%) 141 (3.3%) 452 (3.8%) 21 (3.0%) 47 (3.4%) 655 (4.0%) 0.076
DIALYSIS 151 (0.4%) 50 (0.6%) 13 (0.3%) 37 (0.3%) 3 (0.4%) 1 (<0.1%) 47 (0.3%)
OPRENAFL <0.001
Acute Renal Failure 373 (0.9%) 38 (0.5%) 59 (1.4%) 69 (0.6%) 6 (0.8%) 34 (2.5%) 167 (1.0%)
No Complication 42,546 (99%) 8,254 (100%) 4,215 (99%) 11,748 (99%) 700 (99%) 1,332 (98%) 16,297 (99%)
FNSTATUS2
Independent 42,512 (99%) 8,207 (99%) 4,239 (99%) 11,710 (99%) 697 (99%) 1,359 (100%) 16,300 (99%)
Partially Dependent 319 (0.7%) 71 (0.9%) 26 (0.6%) 81 (0.7%) 7 (1.0%) 4 (0.3%) 130 (0.8%)
Totally Dependent 24 (<0.1%) 3 (<0.1%) 2 (<0.1%) 6 (<0.1%) 0 (0%) 0 (0%) 13 (<0.1%)
Unknown 64 11 7 20 2 3 21
PAN_FISTULA 4,318 (17%) 1,511 (18%) 0 (NA%) 0 (NA%) 49 (7.1%) 0 (NA%) 2,758 (17%) <0.001
Unknown 17,684 79 4,274 11,817 11 1,366 137
PAN_DELGASTRIC_20140315 3,258 (13%) 407 (4.9%) 0 (NA%) 0 (NA%) 98 (14%) 0 (NA%) 2,753 (17%) <0.001
Unknown 17,577 43 4,274 11,817 5 1,366 72
HEP_LIVERFAIL 828 (4.7%) 0 (NA%) 388 (9.1%) 253 (2.1%) 0 (NA%) 187 (14%) 0 (NA%) <0.001
Unknown 25,462 8,292 0 0 706 0 16,464
HEP_BILELEAKAGE 1,252 (7.2%) 0 (NA%) 438 (10%) 572 (4.9%) 0 (NA%) 242 (18%) 0 (NA%) <0.001
Unknown 25,589 8,292 35 84 706 8 16,464
CDARREST <0.001
Cardiac Arrest Requiring CPR 375 (0.9%) 50 (0.6%) 59 (1.4%) 43 (0.4%) 12 (1.7%) 18 (1.3%) 193 (1.2%)
No Complication 42,544 (99%) 8,242 (99%) 4,215 (99%) 11,774 (100%) 694 (98%) 1,348 (99%) 16,271 (99%)
CDMI <0.001
Myocardial Infarction 434 (1.0%) 78 (0.9%) 52 (1.2%) 80 (0.7%) 9 (1.3%) 16 (1.2%) 199 (1.2%)
No Complication 42,485 (99%) 8,214 (99%) 4,222 (99%) 11,737 (99%) 697 (99%) 1,350 (99%) 16,265 (99%)
OUPNEUMO <0.001
No Complication 41,484 (97%) 8,046 (97%) 4,088 (96%) 11,528 (98%) 664 (94%) 1,287 (94%) 15,871 (96%)
Pneumonia 1,435 (3.3%) 246 (3.0%) 186 (4.4%) 289 (2.4%) 42 (5.9%) 79 (5.8%) 593 (3.6%)
RENAINSF
No Complication 42,653 (99%) 8,264 (100%) 4,227 (99%) 11,759 (100%) 701 (99%) 1,352 (99%) 16,350 (99%)
Progressive Renal Insufficiency 266 (0.6%) 28 (0.3%) 47 (1.1%) 58 (0.5%) 5 (0.7%) 14 (1.0%) 114 (0.7%)
PULEMBOL <0.001
No Complication 42,386 (99%) 8,171 (99%) 4,198 (98%) 11,703 (99%) 698 (99%) 1,345 (98%) 16,271 (99%)
Pulmonary Embolism 533 (1.2%) 121 (1.5%) 76 (1.8%) 114 (1.0%) 8 (1.1%) 21 (1.5%) 193 (1.2%)
OTHDVT <0.001
DVT Requiring Therapy 957 (2.2%) 167 (2.0%) 100 (2.3%) 119 (1.0%) 24 (3.4%) 65 (4.8%) 482 (2.9%)
No Complication 41,962 (98%) 8,125 (98%) 4,174 (98%) 11,698 (99%) 682 (97%) 1,301 (95%) 15,982 (97%)
RETURNOR 1,768 (4.1%) 279 (3.4%) 191 (4.5%) 243 (2.1%) 55 (7.8%) 76 (5.6%) 924 (5.6%) <0.001
ORGSPCSSI <0.001
No Complication 37,896 (88%) 7,323 (88%) 3,853 (90%) 11,136 (94%) 628 (89%) 1,151 (84%) 13,805 (84%)
Organ/Space SSI 5,023 (12%) 969 (12%) 421 (9.9%) 681 (5.8%) 78 (11%) 215 (16%) 2,659 (16%)
PRSEPIS
None 42,360 (99%) 8,165 (98%) 4,191 (98%) 11,683 (99%) 697 (99%) 1,342 (98%) 16,282 (99%)
Sepsis 162 (0.4%) 36 (0.4%) 31 (0.7%) 37 (0.3%) 2 (0.3%) 6 (0.4%) 50 (0.3%)
Septic Shock 20 (<0.1%) 6 (<0.1%) 5 (0.1%) 4 (<0.1%) 2 (0.3%) 0 (0%) 3 (<0.1%)
SIRS 377 (0.9%) 85 (1.0%) 47 (1.1%) 93 (0.8%) 5 (0.7%) 18 (1.3%) 129 (0.8%)
REINTUB <0.001
No Complication 41,773 (97%) 8,144 (98%) 4,122 (96%) 11,662 (99%) 677 (96%) 1,294 (95%) 15,874 (96%)
Unplanned Intubation 1,146 (2.7%) 148 (1.8%) 152 (3.6%) 155 (1.3%) 29 (4.1%) 72 (5.3%) 590 (3.6%)
URNINFEC 0.004
No Complication 41,937 (98%) 8,100 (98%) 4,179 (98%) 11,599 (98%) 686 (97%) 1,332 (98%) 16,041 (97%)
Urinary Tract Infection 982 (2.3%) 192 (2.3%) 95 (2.2%) 218 (1.8%) 20 (2.8%) 34 (2.5%) 423 (2.6%)
SUPINFEC <0.001
No Complication 40,825 (95%) 8,077 (97%) 4,105 (96%) 11,468 (97%) 678 (96%) 1,278 (94%) 15,219 (92%)
Superficial Incisional SSI 2,094 (4.9%) 215 (2.6%) 169 (4.0%) 349 (3.0%) 28 (4.0%) 88 (6.4%) 1,245 (7.6%)

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: chi-square test of independence; Kruskal-Wallis test; Fisher's exact test

ByProcedurePanc <- 
  subset(ByProcedure, PatientGroup == "Pancreas")

ByProcedurePanc %>%
  tbl_summary(
    by = PRNCPTX,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## There was an error in 'add_p()' for variable 'PatientGroup', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'ASACLAS', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 501.
## The hash table key cannot be computed because the largest key
## is larger than the largest representable int.
## The algorithm cannot proceed.
## Reduce the workspace, consider using 'simulate.p.value=TRUE' or another algorithm.
## There was an error in 'add_p()' for variable 'DYSPNEA', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 6.  LDKEY=462 is too small for this problem,
##   (ii := key2[itp=693] = 1021557532, ldstp=13860)
## Try increasing the size of the workspace and possibly 'mult'
## There was an error in 'add_p()' for variable 'FNSTATUS2', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 6.  LDKEY=462 is too small for this problem,
##   (ii := key2[itp=505] = 87232564, ldstp=13860)
## Try increasing the size of the workspace and possibly 'mult'
## There was an error in 'add_p()' for variable 'HEP_LIVERFAIL', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'HEP_BILELEAKAGE', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'PRSEPIS', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 501.
## The hash table key cannot be computed because the largest key
## is larger than the largest representable int.
## The algorithm cannot proceed.
## Reduce the workspace, consider using 'simulate.p.value=TRUE' or another algorithm.
Variable Overall, N = 25,4621 *Textbook Outcomes Whipple, N = 16,4641 p-value2
Distal Pancreatectomy, N = 8,2921 Total Pancreatectomy, N = 7061
PatientGroup
Pancreas 25,462 (100%) 8,292 (100%) 706 (100%) 16,464 (100%)
DOptoDis 7.00 (5.00, 10.00) 5.00 (4.00, 7.00) 8.00 (6.00, 12.00) 8.00 (6.00, 12.00) <0.001
Unknown 192 25 8 159
Age <0.001
0-65 11,893 (47%) 4,420 (53%) 371 (53%) 7,102 (43%)
65-74 8,642 (34%) 2,508 (30%) 228 (32%) 5,906 (36%)
75-84 4,492 (18%) 1,249 (15%) 99 (14%) 3,144 (19%)
85+ 435 (1.7%) 115 (1.4%) 8 (1.1%) 312 (1.9%)
SEX <0.001
female 12,510 (49%) 4,540 (55%) 353 (50%) 7,617 (46%)
male 12,952 (51%) 3,752 (45%) 353 (50%) 8,847 (54%)
RACE_NEW <0.001
Black 2,180 (9.8%) 833 (11%) 52 (8.6%) 1,295 (9.1%)
Other 1,200 (5.4%) 389 (5.3%) 38 (6.3%) 773 (5.4%)
White 18,813 (85%) 6,061 (83%) 515 (85%) 12,237 (86%)
Unknown 3,269 1,009 101 2,159
BMILabled <0.001
Morbidly Obese 1,018 (4.0%) 465 (5.6%) 24 (3.4%) 529 (3.2%)
Normal Weight 8,497 (34%) 2,431 (29%) 275 (39%) 5,791 (35%)
Obese 6,512 (26%) 2,525 (31%) 162 (23%) 3,825 (23%)
Overweight 8,714 (34%) 2,681 (32%) 222 (32%) 5,811 (35%)
Underweight 611 (2.4%) 164 (2.0%) 20 (2.8%) 427 (2.6%)
Unknown 110 26 3 81
ASACLAS
1-No Disturb 175 (0.7%) 104 (1.3%) 2 (0.3%) 69 (0.4%)
2-Mild Disturb 6,008 (24%) 2,376 (29%) 153 (22%) 3,479 (21%)
3-Severe Disturb 17,561 (69%) 5,337 (64%) 488 (69%) 11,736 (71%)
4-Life Threat 1,681 (6.6%) 458 (5.5%) 61 (8.7%) 1,162 (7.1%)
Unknown 37 17 2 18
DOpertoD 352 (1.4%) 74 (0.9%) 12 (1.7%) 266 (1.6%) <0.001
OPTIME 312.00 (221.00, 409.00) 215.00 (159.00, 288.00) 345.00 (238.50, 447.75) 356.00 (279.00, 445.00) <0.001
ELOS 7,126 (28%) 2,753 (33%) 193 (28%) 4,180 (26%) <0.001
Unknown 192 25 8 159
READMISSION1 4,293 (22%) 1,386 (22%) 146 (25%) 2,761 (21%) 0.11
Unknown 5,659 1,937 124 3,598
STEROID 757 (3.0%) 294 (3.5%) 32 (4.5%) 431 (2.6%) <0.001
DIABETES <0.001
NO 18,816 (74%) 6,254 (75%) 436 (62%) 12,126 (74%)
Yes 6,646 (26%) 2,038 (25%) 270 (38%) 4,338 (26%)
HYPERMED 13,322 (52%) 4,266 (51%) 350 (50%) 8,706 (53%) 0.035
ASCITES 73 (0.3%) 19 (0.2%) 6 (0.8%) 48 (0.3%) 0.025
HXCHF 105 (0.4%) 41 (0.5%) 2 (0.3%) 62 (0.4%) 0.37
DYSPNEA
AT REST 32 (0.1%) 11 (0.1%) 0 (0%) 21 (0.1%)
MODERATE EXERTION 1,320 (5.2%) 473 (5.7%) 37 (5.2%) 810 (4.9%)
No 24,110 (95%) 7,808 (94%) 669 (95%) 15,633 (95%)
SMOKE 4,367 (17%) 1,372 (17%) 128 (18%) 2,867 (17%) 0.18
HXCOPD 1,030 (4.0%) 354 (4.3%) 21 (3.0%) 655 (4.0%) 0.19
DIALYSIS 100 (0.4%) 50 (0.6%) 3 (0.4%) 47 (0.3%) <0.001
OPRENAFL <0.001
Acute Renal Failure 211 (0.8%) 38 (0.5%) 6 (0.8%) 167 (1.0%)
No Complication 25,251 (99%) 8,254 (100%) 700 (99%) 16,297 (99%)
FNSTATUS2
Independent 25,204 (99%) 8,207 (99%) 697 (99%) 16,300 (99%)
Partially Dependent 208 (0.8%) 71 (0.9%) 7 (1.0%) 130 (0.8%)
Totally Dependent 16 (<0.1%) 3 (<0.1%) 0 (0%) 13 (<0.1%)
Unknown 34 11 2 21
PAN_FISTULA 4,318 (17%) 1,511 (18%) 49 (7.1%) 2,758 (17%) <0.001
Unknown 227 79 11 137
PAN_DELGASTRIC_20140315 3,258 (13%) 407 (4.9%) 98 (14%) 2,753 (17%) <0.001
Unknown 120 43 5 72
HEP_LIVERFAIL 0 (NA%) 0 (NA%) 0 (NA%) 0 (NA%)
Unknown 25,462 8,292 706 16,464
HEP_BILELEAKAGE 0 (NA%) 0 (NA%) 0 (NA%) 0 (NA%)
Unknown 25,462 8,292 706 16,464
CDARREST <0.001
Cardiac Arrest Requiring CPR 255 (1.0%) 50 (0.6%) 12 (1.7%) 193 (1.2%)
No Complication 25,207 (99%) 8,242 (99%) 694 (98%) 16,271 (99%)
CDMI 0.16
Myocardial Infarction 286 (1.1%) 78 (0.9%) 9 (1.3%) 199 (1.2%)
No Complication 25,176 (99%) 8,214 (99%) 697 (99%) 16,265 (99%)
OUPNEUMO <0.001
No Complication 24,581 (97%) 8,046 (97%) 664 (94%) 15,871 (96%)
Pneumonia 881 (3.5%) 246 (3.0%) 42 (5.9%) 593 (3.6%)
RENAINSF 0.001
No Complication 25,315 (99%) 8,264 (100%) 701 (99%) 16,350 (99%)
Progressive Renal Insufficiency 147 (0.6%) 28 (0.3%) 5 (0.7%) 114 (0.7%)
PULEMBOL 0.15
No Complication 25,140 (99%) 8,171 (99%) 698 (99%) 16,271 (99%)
Pulmonary Embolism 322 (1.3%) 121 (1.5%) 8 (1.1%) 193 (1.2%)
OTHDVT <0.001
DVT Requiring Therapy 673 (2.6%) 167 (2.0%) 24 (3.4%) 482 (2.9%)
No Complication 24,789 (97%) 8,125 (98%) 682 (97%) 15,982 (97%)
RETURNOR 1,258 (4.9%) 279 (3.4%) 55 (7.8%) 924 (5.6%) <0.001
ORGSPCSSI <0.001
No Complication 21,756 (85%) 7,323 (88%) 628 (89%) 13,805 (84%)
Organ/Space SSI 3,706 (15%) 969 (12%) 78 (11%) 2,659 (16%)
PRSEPIS
None 25,144 (99%) 8,165 (98%) 697 (99%) 16,282 (99%)
Sepsis 88 (0.3%) 36 (0.4%) 2 (0.3%) 50 (0.3%)
Septic Shock 11 (<0.1%) 6 (<0.1%) 2 (0.3%) 3 (<0.1%)
SIRS 219 (0.9%) 85 (1.0%) 5 (0.7%) 129 (0.8%)
REINTUB <0.001
No Complication 24,695 (97%) 8,144 (98%) 677 (96%) 15,874 (96%)
Unplanned Intubation 767 (3.0%) 148 (1.8%) 29 (4.1%) 590 (3.6%)
URNINFEC 0.41
No Complication 24,827 (98%) 8,100 (98%) 686 (97%) 16,041 (97%)
Urinary Tract Infection 635 (2.5%) 192 (2.3%) 20 (2.8%) 423 (2.6%)
SUPINFEC <0.001
No Complication 23,974 (94%) 8,077 (97%) 678 (96%) 15,219 (92%)
Superficial Incisional SSI 1,488 (5.8%) 215 (2.6%) 28 (4.0%) 1,245 (7.6%)

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: Kruskal-Wallis test; chi-square test of independence; Fisher's exact test

ByProcedureLiver <- 
  subset(ByProcedure, PatientGroup == "Liver")

ByProcedureLiver %>%
  tbl_summary(
    by = PRNCPTX,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## There was an error in 'add_p()' for variable 'PatientGroup', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'DYSPNEA', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 6.  LDKEY=512 is too small for this problem,
##   (ii := key2[itp=59] = 531740699, ldstp=15360)
## Try increasing the size of the workspace and possibly 'mult'
## There was an error in 'add_p()' for variable 'PAN_FISTULA', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'PAN_DELGASTRIC_20140315', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'PRSEPIS', p-value omitted:
## Error in stats::fisher.test(data[[variable]], as.factor(data[[by]])): FEXACT error 501.
## The hash table key cannot be computed because the largest key
## is larger than the largest representable int.
## The algorithm cannot proceed.
## Reduce the workspace, consider using 'simulate.p.value=TRUE' or another algorithm.
Variable Overall, N = 17,4571 *Textbook Outcomes Trisegmentectomy, N = 1,3661 p-value2
Lobectomy, N = 4,2741 Partial Lobectomy, N = 11,8171
PatientGroup
Liver 17,457 (100%) 4,274 (100%) 11,817 (100%) 1,366 (100%)
DOptoDis 5.00 (4.00, 7.00) 6.00 (5.00, 8.00) 5.00 (3.00, 6.00) 7.00 (5.00, 10.00) <0.001
Unknown 50 21 19 10
Age 0.086
0-65 10,737 (62%) 2,616 (61%) 7,281 (62%) 840 (61%)
65-74 4,660 (27%) 1,147 (27%) 3,122 (26%) 391 (29%)
75-84 1,907 (11%) 480 (11%) 1,298 (11%) 129 (9.4%)
85+ 153 (0.9%) 31 (0.7%) 116 (1.0%) 6 (0.4%)
SEX 0.20
female 8,754 (50%) 2,105 (49%) 5,981 (51%) 668 (49%)
male 8,703 (50%) 2,169 (51%) 5,836 (49%) 698 (51%)
RACE_NEW 0.005
Black 1,468 (11%) 343 (11%) 1,032 (11%) 93 (9.0%)
Other 1,298 (9.3%) 343 (11%) 879 (9.1%) 76 (7.4%)
White 11,130 (80%) 2,556 (79%) 7,713 (80%) 861 (84%)
Unknown 3,561 1,032 2,193 336
BMILabled <0.001
Morbidly Obese 908 (5.2%) 173 (4.1%) 693 (5.9%) 42 (3.1%)
Normal Weight 5,229 (30%) 1,367 (32%) 3,384 (29%) 478 (35%)
Obese 5,058 (29%) 1,217 (29%) 3,503 (30%) 338 (25%)
Overweight 5,880 (34%) 1,417 (33%) 3,995 (34%) 468 (34%)
Underweight 268 (1.5%) 72 (1.7%) 165 (1.4%) 31 (2.3%)
Unknown 114 28 77 9
ASACLAS <0.001
1-No Disturb 253 (1.5%) 103 (2.4%) 139 (1.2%) 11 (0.8%)
2-Mild Disturb 4,395 (25%) 1,055 (25%) 3,003 (25%) 337 (25%)
3-Severe Disturb 11,495 (66%) 2,765 (65%) 7,844 (67%) 886 (65%)
4-Life Threat 1,270 (7.3%) 336 (7.9%) 805 (6.8%) 129 (9.5%)
Unknown 44 15 26 3
DOpertoD 257 (1.5%) 101 (2.4%) 101 (0.9%) 55 (4.0%) <0.001
OPTIME 216.00 (154.00, 300.00) 262.00 (196.00, 342.00) 193.00 (139.00, 264.00) 310.00 (225.00, 409.00) <0.001
ELOS 5,727 (33%) 1,220 (29%) 4,153 (35%) 354 (26%) <0.001
Unknown 50 21 19 10
READMISSION1 1,725 (13%) 493 (15%) 1,020 (12%) 212 (20%) <0.001
Unknown 4,301 981 3,003 317
STEROID 533 (3.1%) 115 (2.7%) 384 (3.2%) 34 (2.5%) 0.086
DIABETES 0.036
NO 14,381 (82%) 3,518 (82%) 9,703 (82%) 1,160 (85%)
Yes 3,076 (18%) 756 (18%) 2,114 (18%) 206 (15%)
HYPERMED 8,021 (46%) 1,912 (45%) 5,520 (47%) 589 (43%) 0.008
ASCITES 96 (0.5%) 16 (0.4%) 71 (0.6%) 9 (0.7%) 0.20
HXCHF 59 (0.3%) 13 (0.3%) 44 (0.4%) 2 (0.1%) 0.42
DYSPNEA
AT REST 37 (0.2%) 8 (0.2%) 26 (0.2%) 3 (0.2%)
MODERATE EXERTION 921 (5.3%) 236 (5.5%) 609 (5.2%) 76 (5.6%)
No 16,499 (95%) 4,030 (94%) 11,182 (95%) 1,287 (94%)
SMOKE 2,698 (15%) 696 (16%) 1,769 (15%) 233 (17%) 0.029
HXCOPD 640 (3.7%) 141 (3.3%) 452 (3.8%) 47 (3.4%) 0.26
DIALYSIS 51 (0.3%) 13 (0.3%) 37 (0.3%) 1 (<0.1%) 0.33
OPRENAFL <0.001
Acute Renal Failure 162 (0.9%) 59 (1.4%) 69 (0.6%) 34 (2.5%)
No Complication 17,295 (99%) 4,215 (99%) 11,748 (99%) 1,332 (98%)
FNSTATUS2 0.50
Independent 17,308 (99%) 4,239 (99%) 11,710 (99%) 1,359 (100%)
Partially Dependent 111 (0.6%) 26 (0.6%) 81 (0.7%) 4 (0.3%)
Totally Dependent 8 (<0.1%) 2 (<0.1%) 6 (<0.1%) 0 (0%)
Unknown 30 7 20 3
PAN_FISTULA 0 (NA%) 0 (NA%) 0 (NA%) 0 (NA%)
Unknown 17,457 4,274 11,817 1,366
PAN_DELGASTRIC_20140315 0 (NA%) 0 (NA%) 0 (NA%) 0 (NA%)
Unknown 17,457 4,274 11,817 1,366
HEP_LIVERFAIL 828 (4.7%) 388 (9.1%) 253 (2.1%) 187 (14%) <0.001
HEP_BILELEAKAGE 1,252 (7.2%) 438 (10%) 572 (4.9%) 242 (18%) <0.001
Unknown 127 35 84 8
CDARREST <0.001
Cardiac Arrest Requiring CPR 120 (0.7%) 59 (1.4%) 43 (0.4%) 18 (1.3%)
No Complication 17,337 (99%) 4,215 (99%) 11,774 (100%) 1,348 (99%)
CDMI 0.002
Myocardial Infarction 148 (0.8%) 52 (1.2%) 80 (0.7%) 16 (1.2%)
No Complication 17,309 (99%) 4,222 (99%) 11,737 (99%) 1,350 (99%)
OUPNEUMO <0.001
No Complication 16,903 (97%) 4,088 (96%) 11,528 (98%) 1,287 (94%)
Pneumonia 554 (3.2%) 186 (4.4%) 289 (2.4%) 79 (5.8%)
RENAINSF <0.001
No Complication 17,338 (99%) 4,227 (99%) 11,759 (100%) 1,352 (99%)
Progressive Renal Insufficiency 119 (0.7%) 47 (1.1%) 58 (0.5%) 14 (1.0%)
PULEMBOL <0.001
No Complication 17,246 (99%) 4,198 (98%) 11,703 (99%) 1,345 (98%)
Pulmonary Embolism 211 (1.2%) 76 (1.8%) 114 (1.0%) 21 (1.5%)
OTHDVT <0.001
DVT Requiring Therapy 284 (1.6%) 100 (2.3%) 119 (1.0%) 65 (4.8%)
No Complication 17,173 (98%) 4,174 (98%) 11,698 (99%) 1,301 (95%)
RETURNOR 510 (2.9%) 191 (4.5%) 243 (2.1%) 76 (5.6%) <0.001
ORGSPCSSI <0.001
No Complication 16,140 (92%) 3,853 (90%) 11,136 (94%) 1,151 (84%)
Organ/Space SSI 1,317 (7.5%) 421 (9.9%) 681 (5.8%) 215 (16%)
PRSEPIS
None 17,216 (99%) 4,191 (98%) 11,683 (99%) 1,342 (98%)
Sepsis 74 (0.4%) 31 (0.7%) 37 (0.3%) 6 (0.4%)
Septic Shock 9 (<0.1%) 5 (0.1%) 4 (<0.1%) 0 (0%)
SIRS 158 (0.9%) 47 (1.1%) 93 (0.8%) 18 (1.3%)
REINTUB <0.001
No Complication 17,078 (98%) 4,122 (96%) 11,662 (99%) 1,294 (95%)
Unplanned Intubation 379 (2.2%) 152 (3.6%) 155 (1.3%) 72 (5.3%)
URNINFEC 0.12
No Complication 17,110 (98%) 4,179 (98%) 11,599 (98%) 1,332 (98%)
Urinary Tract Infection 347 (2.0%) 95 (2.2%) 218 (1.8%) 34 (2.5%)
SUPINFEC <0.001
No Complication 16,851 (97%) 4,105 (96%) 11,468 (97%) 1,278 (94%)
Superficial Incisional SSI 606 (3.5%) 169 (4.0%) 349 (3.0%) 88 (6.4%)

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: Kruskal-Wallis test; chi-square test of independence; Fisher's exact test

Underweight <-
  PanTextbookOutcomes %>%
  select(PatientGroup, DOptoDis, Age, SEX, RACE_NEW, BMILabled, ASACLAS, DOpertoD, TextbookOutcomeHep, TextbookOutcomePan, TextbookOutcomeAll)
Underweight1 <- 
  Underweight %>%
  mutate(Underweight, BMILabled1 = ifelse(BMILabled == "Morbidly Obese", "Everyone", 
                                               ifelse(BMILabled == "Obese", "Everyone", 
                                                      ifelse(BMILabled == "Overweight", "Everyone", 
                                                             ifelse(BMILabled == "Normal Weight", "Everyone",
                                                                    ifelse(BMILabled == "Underweight", "Underweight", NA))))))


UnderweightPanc <- 
  subset(Underweight1, PatientGroup == "Pancreas")

UnderweightHepatic <- 
  subset(Underweight1, PatientGroup == "Liver")
Underweight1 %>%
  tbl_summary(
    by = BMILabled1,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 229 observations missing `BMILabled1` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `BMILabled1` column before passing to `tbl_summary()`.
Variable Overall, N = 44,0061 *Textbook Outcomes p-value2
Everyone, N = 43,1031 Underweight, N = 9031
PatientGroup <0.001
Liver 17,343 (41%) 17,075 (41%) 268 (30%)
Pancreas 25,352 (59%) 24,741 (59%) 611 (70%)
Unknown 1,311 1,287 24
DOptoDis 6.00 (5.00, 9.00) 6.00 (5.00, 9.00) 7.00 (5.00, 10.00) <0.001
Unknown 247 241 6
Age 0.28
0-65 23,251 (53%) 22,780 (53%) 471 (52%)
65-74 13,622 (31%) 13,357 (31%) 265 (29%)
75-84 6,525 (15%) 6,372 (15%) 153 (17%)
85+ 608 (1.4%) 594 (1.4%) 14 (1.6%)
SEX <0.001
female 21,905 (50%) 21,268 (49%) 637 (71%)
male 22,101 (50%) 21,835 (51%) 266 (29%)
RACE_NEW <0.001
Black 3,752 (10%) 3,648 (10%) 104 (13%)
Other 2,542 (6.8%) 2,440 (6.7%) 102 (13%)
White 30,898 (83%) 30,320 (83%) 578 (74%)
Unknown 6,814 6,695 119
BMILabled <0.001
Morbidly Obese 2,019 (4.6%) 2,019 (4.7%) 0 (0%)
Normal Weight 14,063 (32%) 14,063 (33%) 0 (0%)
Obese 11,988 (27%) 11,988 (28%) 0 (0%)
Overweight 15,033 (34%) 15,033 (35%) 0 (0%)
Underweight 903 (2.1%) 0 (0%) 903 (100%)
ASACLAS 0.002
1-No Disturb 437 (1.0%) 432 (1.0%) 5 (0.6%)
2-Mild Disturb 10,786 (25%) 10,604 (25%) 182 (20%)
3-Severe Disturb 29,759 (68%) 29,122 (68%) 637 (71%)
4-Life Threat 2,949 (6.7%) 2,871 (6.7%) 78 (8.6%)
Unknown 75 74 1
DOpertoD 613 (1.4%) 597 (1.4%) 16 (1.8%) 0.40
TextbookOutcomeHep 6,906 (26%) 6,809 (26%) 97 (19%) <0.001
Unknown 17,111 16,722 389
TextbookOutcomePan 9,141 (30%) 8,892 (30%) 249 (37%) <0.001
Unknown 13,938 13,711 227
TextbookOutcomeAll 16,047 (45%) 15,701 (45%) 346 (46%) 0.71
Unknown 8,283 8,138 145

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: chi-square test of independence; Wilcoxon rank-sum test

UnderweightPanc %>%
  tbl_summary(
    by = BMILabled1,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 110 observations missing `BMILabled1` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `BMILabled1` column before passing to `tbl_summary()`.
## There was an error in 'add_p()' for variable 'PatientGroup', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'TextbookOutcomeHep', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
Variable Overall, N = 25,3521 *Textbook Outcomes p-value2
Everyone, N = 24,7411 Underweight, N = 6111
PatientGroup
Pancreas 25,352 (100%) 24,741 (100%) 611 (100%)
DOptoDis 7.00 (5.00, 10.00) 7.00 (5.00, 10.00) 7.00 (6.00, 11.00) 0.027
Unknown 189 185 4
Age 0.15
0-65 11,846 (47%) 11,543 (47%) 303 (50%)
65-74 8,609 (34%) 8,428 (34%) 181 (30%)
75-84 4,465 (18%) 4,349 (18%) 116 (19%)
85+ 432 (1.7%) 421 (1.7%) 11 (1.8%)
SEX <0.001
female 12,455 (49%) 12,025 (49%) 430 (70%)
male 12,897 (51%) 12,716 (51%) 181 (30%)
RACE_NEW <0.001
Black 2,178 (9.8%) 2,099 (9.7%) 79 (14%)
Other 1,197 (5.4%) 1,138 (5.3%) 59 (11%)
White 18,778 (85%) 18,370 (85%) 408 (75%)
Unknown 3,199 3,134 65
BMILabled <0.001
Morbidly Obese 1,018 (4.0%) 1,018 (4.1%) 0 (0%)
Normal Weight 8,497 (34%) 8,497 (34%) 0 (0%)
Obese 6,512 (26%) 6,512 (26%) 0 (0%)
Overweight 8,714 (34%) 8,714 (35%) 0 (0%)
Underweight 611 (2.4%) 0 (0%) 611 (100%)
ASACLAS 0.002
1-No Disturb 173 (0.7%) 171 (0.7%) 2 (0.3%)
2-Mild Disturb 6,000 (24%) 5,881 (24%) 119 (19%)
3-Severe Disturb 17,503 (69%) 17,072 (69%) 431 (71%)
4-Life Threat 1,642 (6.5%) 1,583 (6.4%) 59 (9.7%)
Unknown 34 34 0
DOpertoD 347 (1.4%) 335 (1.4%) 12 (2.0%) 0.27
TextbookOutcomeHep
No 11,988 (100%) 11,716 (100%) 272 (100%)
Unknown 13,364 13,025 339
TextbookOutcomePan 8,736 (40%) 8,495 (40%) 241 (46%) 0.007
Unknown 3,471 3,387 84
TextbookOutcomeAll 8,736 (42%) 8,495 (42%) 241 (47%) 0.028
Unknown 4,628 4,530 98

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: Wilcoxon rank-sum test; chi-square test of independence; Fisher's exact test

UnderweightHepatic %>%
  tbl_summary(
    by = BMILabled1,
    digits = all_continuous() ~ 2,) %>%
  add_p(pvalue_fun = ~style_pvalue(.x, digits = 2))%>%
  bold_p() %>%
  add_overall() %>%
  modify_header(label ~ "**Variable**") %>%
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Textbook Outcomes*") %>%
  bold_labels() 
## 114 observations missing `BMILabled1` have been removed. To include these observations, use `forcats::fct_explicit_na()` on `BMILabled1` column before passing to `tbl_summary()`.
## There was an error in 'add_p()' for variable 'PatientGroup', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()' for variable 'TextbookOutcomePan', p-value omitted:
## Error in stats::chisq.test(data[[variable]], as.factor(data[[by]])): 'x' and 'y' must have at least 2 levels
Variable Overall, N = 17,3431 *Textbook Outcomes p-value2
Everyone, N = 17,0751 Underweight, N = 2681
PatientGroup
Liver 17,343 (100%) 17,075 (100%) 268 (100%)
DOptoDis 5.00 (4.00, 7.00) 5.00 (4.00, 7.00) 6.00 (4.00, 8.00) <0.001
Unknown 49 48 1
Age 0.43
0-65 10,666 (62%) 10,512 (62%) 154 (57%)
65-74 4,633 (27%) 4,557 (27%) 76 (28%)
75-84 1,893 (11%) 1,857 (11%) 36 (13%)
85+ 151 (0.9%) 149 (0.9%) 2 (0.7%)
SEX <0.001
female 8,704 (50%) 8,513 (50%) 191 (71%)
male 8,639 (50%) 8,562 (50%) 77 (29%)
RACE_NEW <0.001
Black 1,466 (11%) 1,442 (11%) 24 (11%)
Other 1,290 (9.3%) 1,250 (9.2%) 40 (18%)
White 11,089 (80%) 10,936 (80%) 153 (71%)
Unknown 3,498 3,447 51
BMILabled <0.001
Morbidly Obese 908 (5.2%) 908 (5.3%) 0 (0%)
Normal Weight 5,229 (30%) 5,229 (31%) 0 (0%)
Obese 5,058 (29%) 5,058 (30%) 0 (0%)
Overweight 5,880 (34%) 5,880 (34%) 0 (0%)
Underweight 268 (1.5%) 0 (0%) 268 (100%)
ASACLAS 0.37
1-No Disturb 250 (1.4%) 248 (1.5%) 2 (0.7%)
2-Mild Disturb 4,370 (25%) 4,313 (25%) 57 (21%)
3-Severe Disturb 11,429 (66%) 11,240 (66%) 189 (71%)
4-Life Threat 1,255 (7.3%) 1,236 (7.3%) 19 (7.1%)
Unknown 39 38 1
DOpertoD 256 (1.5%) 252 (1.5%) 4 (1.5%) 0.80
TextbookOutcomeHep 6,906 (47%) 6,809 (48%) 97 (41%) 0.051
Unknown 2,780 2,749 31
TextbookOutcomePan
No 7,344 (100%) 7,209 (100%) 135 (100%)
Unknown 9,999 9,866 133
TextbookOutcomeAll 6,906 (48%) 6,809 (49%) 97 (42%) 0.048
Unknown 3,093 3,057 36

1 Statistics presented: n (%); Median (IQR)

2 Statistical tests performed: Wilcoxon rank-sum test; Fisher's exact test; chi-square test of independence

TextbookOutcomeOR <- 
  PantextBookOutcomesDT %>%
  select(PRNCPTX, PatientGroup, Age, SEX, RACE_NEW, BMILabled, ASACLAS, DOpertoD, OPTIME, ELOS, READMISSION1, STEROID, DIABETES, HYPERMED, ASACLAS, ASCITES, HXCHF, DYSPNEA, SMOKE, HXCOPD, DIALYSIS, OPRENAFL, FNSTATUS2, AnyComplication, TextbookOutcomeHep, TextbookOutcomePan, TextbookOutcomeAll, PanComplications, HepComplications)
TextbookOutcomeOR <- TextbookOutcomeOR %>%
  mutate(TextbookOutcomeOR, TextbookOutcomePanOR = ifelse(TextbookOutcomePan =="Yes", "1",
                                                  ifelse(TextbookOutcomePan =="No", "0", NA)))


TextbookOutcomeOR$TextbookOutcomePanOR <- as.numeric(TextbookOutcomeOR$TextbookOutcomePanOR)


TextbookOutcomeOR <- TextbookOutcomeOR %>%
  mutate(TextbookOutcomeOR, TextbookOutcomeHepOR = ifelse(TextbookOutcomeHep =="Yes", "1",
                                                  ifelse(TextbookOutcomeHep =="No", "0", NA)))


TextbookOutcomeOR <- TextbookOutcomeOR %>%
  mutate(TextbookOutcomeOR, TextbookOutcomeAllOR = ifelse(TextbookOutcomeAll =="Yes", "1",
                                                  ifelse(TextbookOutcomeAll =="No", "0", NA)))

TextbookOutcomeOR$TextbookOutcomeHepOR <- as.numeric(TextbookOutcomeOR$TextbookOutcomeHepOR)
TextbookOutcomeOR$TextbookOutcomeAllOR <- as.numeric(TextbookOutcomeOR$TextbookOutcomeAllOR)
TextbookOutcomeOR$TextbookOutcomePanOR <- as.numeric(TextbookOutcomeOR$TextbookOutcomePanOR)
PanTextbookOutcomesSubset <- 
  subset(TextbookOutcomeOR, PatientGroup == "Pancreas")
HepTextbookOutcomesSubset <- 
  subset(TextbookOutcomeOR, PatientGroup == "Liver")

table(PanTextbookOutcomesSubset$TextbookOutcomePanOR)
## 
##     0     1 
## 13214  8759
PanTextbookOutcomesSubset$PRNCPTX <- as.factor(PanTextbookOutcomesSubset$PRNCPTX)
PanTextbookOutcomesSubset$SEX <- as.factor(PanTextbookOutcomesSubset$SEX)
PanTextbookOutcomesSubset$ASACLAS <- as.factor(PanTextbookOutcomesSubset$ASACLAS)
PanTextbookOutcomesSubset$BMILabled <- as.factor(PanTextbookOutcomesSubset$BMILabled)
PanTextbookOutcomesSubset$STEROID <- as.factor(PanTextbookOutcomesSubset$STEROID)
PanTextbookOutcomesSubset$DIABETES <- as.factor(PanTextbookOutcomesSubset$DIABETES)
PanTextbookOutcomesSubset$HYPERMED <- as.factor(PanTextbookOutcomesSubset$HYPERMED)
PanTextbookOutcomesSubset$ASCITES <- as.factor(PanTextbookOutcomesSubset$ASCITES)
PanTextbookOutcomesSubset$HXCOPD <- as.factor(PanTextbookOutcomesSubset$HXCOPD)
PanTextbookOutcomesSubset$DIALYSIS <- as.factor(PanTextbookOutcomesSubset$DIALYSIS)
PanTextbookOutcomesSubset$HXCHF <- as.factor(PanTextbookOutcomesSubset$HXCHF)
PanTextbookOutcomesSubset$Age <- as.factor(PanTextbookOutcomesSubset$Age)
PanTextbookOutcomesSubset$FNSTATUS2 <- as.factor(PanTextbookOutcomesSubset$FNSTATUS2)
PanTextbookOutcomesSubset$SMOKE <- as.factor(PanTextbookOutcomesSubset$SMOKE)
PanTextbookOutcomesSubset$PatientGroup <- as.factor(PanTextbookOutcomesSubset$PatientGroup)


PanTextbookOutcomesSubset$PRNCPTX = relevel(PanTextbookOutcomesSubset$PRNCPTX, ref="Distal Pancreatectomy")
PanTextbookOutcomesSubset$SEX = relevel(PanTextbookOutcomesSubset$SEX, ref="male")
PanTextbookOutcomesSubset$BMILabled = relevel(PanTextbookOutcomesSubset$BMILabled, ref="Overweight")
PanTextbookOutcomesSubset$ASACLAS = relevel(PanTextbookOutcomesSubset$ASACLAS, ref="4-Life Threat")
PanTextbookOutcomesSubset$DIABETES = relevel(PanTextbookOutcomesSubset$DIABETES, ref="NO")
PanTextbookOutcomesSubset$HYPERMED = relevel(PanTextbookOutcomesSubset$HYPERMED, ref="Yes")
PanTextbookOutcomesSubset$STEROID = relevel(PanTextbookOutcomesSubset$STEROID, ref="Yes")
PanTextbookOutcomesSubset$ASCITES = relevel(PanTextbookOutcomesSubset$ASCITES, ref="Yes")
PanTextbookOutcomesSubset$HXCOPD = relevel(PanTextbookOutcomesSubset$HXCOPD, ref="Yes")
PanTextbookOutcomesSubset$DIALYSIS = relevel(PanTextbookOutcomesSubset$DIALYSIS, ref="Yes")
PanTextbookOutcomesSubset$SMOKE = relevel(PanTextbookOutcomesSubset$SMOKE, ref="No")
PanTextbookOutcomesSubset$HXCHF = relevel(PanTextbookOutcomesSubset$HXCHF, ref="Yes")
PanTextbookOutcomesSubset$Age = relevel(PanTextbookOutcomesSubset$Age, ref="85+")
PanTextbookOutcomesSubset$FNSTATUS2 = relevel(PanTextbookOutcomesSubset$FNSTATUS2, ref="Totally Dependent")
UVPan <- PanTextbookOutcomesSubset %>%
  select(PRNCPTX, Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomePanOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomePanOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
###changling the referent level

PanTextbookOutcomesSubset$PRNCPTX <- as.factor(PanTextbookOutcomesSubset$PRNCPTX)
PanTextbookOutcomesSubset$SEX <- as.factor(PanTextbookOutcomesSubset$SEX)
PanTextbookOutcomesSubset$ASACLAS <- as.factor(PanTextbookOutcomesSubset$ASACLAS)
PanTextbookOutcomesSubset$BMILabled <- as.factor(PanTextbookOutcomesSubset$BMILabled)
PanTextbookOutcomesSubset$STEROID <- as.factor(PanTextbookOutcomesSubset$STEROID)
PanTextbookOutcomesSubset$DIABETES <- as.factor(PanTextbookOutcomesSubset$DIABETES)
PanTextbookOutcomesSubset$HYPERMED <- as.factor(PanTextbookOutcomesSubset$HYPERMED)
PanTextbookOutcomesSubset$ASCITES <- as.factor(PanTextbookOutcomesSubset$ASCITES)
PanTextbookOutcomesSubset$HXCOPD <- as.factor(PanTextbookOutcomesSubset$HXCOPD)
PanTextbookOutcomesSubset$DIALYSIS <- as.factor(PanTextbookOutcomesSubset$DIALYSIS)
PanTextbookOutcomesSubset$HXCHF <- as.factor(PanTextbookOutcomesSubset$HXCHF)
PanTextbookOutcomesSubset$Age <- as.factor(PanTextbookOutcomesSubset$Age)
PanTextbookOutcomesSubset$FNSTATUS2 <- as.factor(PanTextbookOutcomesSubset$FNSTATUS2)
PanTextbookOutcomesSubset$PatientGroup <- as.factor(PanTextbookOutcomesSubset$PatientGroup)


PanTextbookOutcomesSubset$PRNCPTX = relevel(PanTextbookOutcomesSubset$PRNCPTX, ref="Distal Pancreatectomy")
PanTextbookOutcomesSubset$SEX = relevel(PanTextbookOutcomesSubset$SEX, ref="male")
PanTextbookOutcomesSubset$ASACLAS = relevel(PanTextbookOutcomesSubset$ASACLAS, ref="4-Life Threat")
PanTextbookOutcomesSubset$BMILabled = relevel(PanTextbookOutcomesSubset$BMILabled, ref="Normal Weight")
PanTextbookOutcomesSubset$DIABETES = relevel(PanTextbookOutcomesSubset$DIABETES, ref="NO")
PanTextbookOutcomesSubset$HYPERMED = relevel(PanTextbookOutcomesSubset$HYPERMED, ref="Yes")
PanTextbookOutcomesSubset$STEROID = relevel(PanTextbookOutcomesSubset$STEROID, ref="Yes")
PanTextbookOutcomesSubset$ASCITES = relevel(PanTextbookOutcomesSubset$ASCITES, ref="Yes")
PanTextbookOutcomesSubset$HXCOPD = relevel(PanTextbookOutcomesSubset$HXCOPD, ref="Yes")
PanTextbookOutcomesSubset$DIALYSIS = relevel(PanTextbookOutcomesSubset$DIALYSIS, ref="Yes")
PanTextbookOutcomesSubset$HXCHF = relevel(PanTextbookOutcomesSubset$HXCHF, ref="Yes")
PanTextbookOutcomesSubset$Age = relevel(PanTextbookOutcomesSubset$Age, ref="85+")
PanTextbookOutcomesSubset$FNSTATUS2 = relevel(PanTextbookOutcomesSubset$FNSTATUS2, ref="Totally Dependent")
####Multivariant analysis serious complications
MVORPan <- 
  glm(TextbookOutcomePanOR ~ PRNCPTX + Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = PanTextbookOutcomesSubset,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTablePan <-
  tbl_regression(MVORPan, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVPan, MVORTablePan),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
PRNCPTX 21,973
Distal Pancreatectomy
Total Pancreatectomy 1.07 0.90, 1.26 0.45 1.01 0.84, 1.21 0.91
Whipple 1.03 0.97, 1.09 0.36 1.05 0.99, 1.12 0.10
Age 21,973
85+
0-65 1.48 1.19, 1.84 <0.001 1.48 1.17, 1.87 <0.001
65-74 1.40 1.13, 1.75 0.003 1.43 1.14, 1.81 0.002
75-84 1.22 0.98, 1.54 0.075 1.26 1.00, 1.60 0.055
SEX 21,973
male
female 1.21 1.15, 1.28 <0.001 1.21 1.14, 1.28 <0.001
RACE_NEW 19,104
Black
Other 0.83 0.70, 0.97 0.017 0.72 0.61, 0.84 <0.001
White 1.09 0.99, 1.20 0.082 1.09 0.98, 1.20 0.11
BMILabled 21,881
Overweight 0.87 0.81, 0.94 <0.001
Morbidly Obese 0.70 0.61, 0.81 <0.001 0.61 0.52, 0.71 <0.001
Normal Weight 1.16 1.09, 1.24 <0.001
Obese 0.85 0.80, 0.92 <0.001 0.73 0.67, 0.79 <0.001
Underweight 1.27 1.06, 1.52 0.008 1.12 0.93, 1.36 0.24
ASACLAS 21,937
4-Life Threat
1-No Disturb 2.17 1.55, 3.03 <0.001 1.93 1.29, 2.88 0.001
2-Mild Disturb 1.93 1.71, 2.19 <0.001 1.78 1.52, 2.08 <0.001
3-Severe Disturb 1.53 1.36, 1.72 <0.001 1.48 1.28, 1.71 <0.001
STEROID 21,973
Yes
No 1.28 1.09, 1.52 0.003 1.23 1.03, 1.47 0.022
ASCITES 21,973
Yes
No 1.55 0.94, 2.64 0.094 1.59 0.92, 2.84 0.10
DYSPNEA 21,973
AT REST
MODERATE EXERTION 0.94 0.43, 2.20 0.87 0.99 0.41, 2.64 >0.99
No 1.35 0.62, 3.16 0.46 1.20 0.50, 3.17 0.69
SMOKE 21,973
No
Yes 1.04 0.97, 1.12 0.25 1.03 0.95, 1.11 0.54
DIALYSIS 21,973
Yes
No 2.55 1.55, 4.41 <0.001 2.05 1.18, 3.77 0.015
DIABETES 21,973
NO
Yes 0.94 0.88, 1.00 0.047 1.08 1.01, 1.16 0.026
HYPERMED 21,973
Yes
No 1.19 1.13, 1.26 <0.001 1.04 0.98, 1.11 0.21
HXCOPD 21,973
Yes
No 1.62 1.40, 1.87 <0.001 1.47 1.25, 1.72 <0.001
HXCHF 21,973
Yes
No 2.38 1.49, 3.95 <0.001 1.59 0.96, 2.76 0.083

1 OR = Odds Ratio, CI = Confidence Interval

###Subset Distal Pancreatectomy

SubsetDistalPanc <- 
  subset(PanTextbookOutcomesSubset, PRNCPTX == "Distal Pancreatectomy")

UVPan1 <- SubsetDistalPanc %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomePanOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomePanOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
###changling the referent level

SubsetDistalPanc$PRNCPTX <- as.factor(SubsetDistalPanc$PRNCPTX)
SubsetDistalPanc$SEX <- as.factor(SubsetDistalPanc$SEX)
SubsetDistalPanc$ASACLAS <- as.factor(SubsetDistalPanc$ASACLAS)
SubsetDistalPanc$BMILabled <- as.factor(SubsetDistalPanc$BMILabled)
SubsetDistalPanc$STEROID <- as.factor(SubsetDistalPanc$STEROID)
SubsetDistalPanc$DIABETES <- as.factor(SubsetDistalPanc$DIABETES)
SubsetDistalPanc$HYPERMED <- as.factor(SubsetDistalPanc$HYPERMED)
SubsetDistalPanc$ASCITES <- as.factor(SubsetDistalPanc$ASCITES)
SubsetDistalPanc$HXCOPD <- as.factor(SubsetDistalPanc$HXCOPD)
SubsetDistalPanc$DIALYSIS <- as.factor(SubsetDistalPanc$DIALYSIS)
SubsetDistalPanc$HXCHF <- as.factor(SubsetDistalPanc$HXCHF)
SubsetDistalPanc$Age <- as.factor(SubsetDistalPanc$Age)
SubsetDistalPanc$FNSTATUS2 <- as.factor(SubsetDistalPanc$FNSTATUS2)
SubsetDistalPanc$PatientGroup <- as.factor(SubsetDistalPanc$PatientGroup)


SubsetDistalPanc$PRNCPTX = relevel(SubsetDistalPanc$PRNCPTX, ref="Distal Pancreatectomy")
SubsetDistalPanc$SEX = relevel(SubsetDistalPanc$SEX, ref="male")
SubsetDistalPanc$ASACLAS = relevel(SubsetDistalPanc$ASACLAS, ref="4-Life Threat")
SubsetDistalPanc$BMILabled = relevel(SubsetDistalPanc$BMILabled, ref="Normal Weight")
SubsetDistalPanc$DIABETES = relevel(SubsetDistalPanc$DIABETES, ref="NO")
SubsetDistalPanc$HYPERMED = relevel(SubsetDistalPanc$HYPERMED, ref="Yes")
SubsetDistalPanc$STEROID = relevel(SubsetDistalPanc$STEROID, ref="Yes")
SubsetDistalPanc$ASCITES = relevel(SubsetDistalPanc$ASCITES, ref="Yes")
SubsetDistalPanc$HXCOPD = relevel(SubsetDistalPanc$HXCOPD, ref="Yes")
SubsetDistalPanc$DIALYSIS = relevel(SubsetDistalPanc$DIALYSIS, ref="Yes")
SubsetDistalPanc$HXCHF = relevel(SubsetDistalPanc$HXCHF, ref="Yes")
SubsetDistalPanc$Age = relevel(SubsetDistalPanc$Age, ref="85+")
SubsetDistalPanc$FNSTATUS2 = relevel(SubsetDistalPanc$FNSTATUS2, ref="Totally Dependent")
####Multivariant analysis serious complications
MVORPan1 <- 
  glm(TextbookOutcomePanOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsetDistalPanc,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTablePan1 <-
  tbl_regression(MVORPan1, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVPan1, MVORTablePan1),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 7,115
85+
0-65 1.63 1.07, 2.56 0.027 1.51 0.97, 2.43 0.077
65-74 1.74 1.14, 2.74 0.013 1.72 1.10, 2.77 0.020
75-84 1.52 0.98, 2.41 0.067 1.50 0.95, 2.43 0.089
SEX 7,115
male
female 1.29 1.17, 1.42 <0.001 1.28 1.15, 1.43 <0.001
RACE_NEW 6,221
Black
Other 1.05 0.81, 1.38 0.70 0.90 0.68, 1.18 0.43
White 1.11 0.95, 1.31 0.19 1.06 0.90, 1.26 0.47
BMILabled 7,094
Normal Weight
Overweight 1.01 0.90, 1.14 0.86 1.07 0.94, 1.22 0.32
Morbidly Obese 0.66 0.52, 0.82 <0.001 0.75 0.59, 0.96 0.026
Obese 0.84 0.75, 0.95 0.007 0.89 0.78, 1.03 0.11
Underweight 1.18 0.83, 1.67 0.36 1.31 0.90, 1.92 0.16
ASACLAS 7,098
4-Life Threat
1-No Disturb 2.90 1.83, 4.63 <0.001 2.48 1.43, 4.33 0.001
2-Mild Disturb 2.41 1.91, 3.06 <0.001 2.09 1.57, 2.81 <0.001
3-Severe Disturb 1.66 1.33, 2.09 <0.001 1.56 1.19, 2.06 0.002
STEROID 7,115
Yes
No 1.20 0.93, 1.57 0.17 1.03 0.77, 1.38 0.85
ASCITES 7,115
Yes
No 3.26 1.07, 14.1 0.062 2.69 0.87, 11.8 0.12
DYSPNEA 7,115
AT REST
MODERATE EXERTION 0.86 0.22, 4.12 0.83 0.83 0.17, 5.95 0.83
No 1.33 0.35, 6.32 0.68 1.10 0.23, 7.84 0.91
SMOKE 7,115
No
Yes 0.80 0.70, 0.91 <0.001 0.85 0.73, 0.98 0.028
DIALYSIS 7,115
Yes
No 1.74 0.92, 3.52 0.10 1.68 0.81, 3.83 0.18
DIABETES 7,115
NO
Yes 0.81 0.73, 0.91 <0.001 0.94 0.82, 1.06 0.31
HYPERMED 7,115
Yes
No 1.17 1.06, 1.29 0.001 0.99 0.88, 1.11 0.84
HXCOPD 7,115
Yes
No 1.65 1.29, 2.12 <0.001 1.33 1.01, 1.77 0.043
HXCHF 7,115
Yes
No 1.76 0.88, 3.83 0.13 0.91 0.43, 2.07 0.81

1 OR = Odds Ratio, CI = Confidence Interval

###Subset Total Pancreatectomy

SubsettotalPanc <- 
  subset(PanTextbookOutcomesSubset, PRNCPTX == "Total Pancreatectomy")

UVPan2 <- SubsettotalPanc %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomePanOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomePanOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
###changling the referent level

SubsettotalPanc$PRNCPTX <- as.factor(SubsettotalPanc$PRNCPTX)
SubsettotalPanc$SEX <- as.factor(SubsettotalPanc$SEX)
SubsettotalPanc$ASACLAS <- as.factor(SubsettotalPanc$ASACLAS)
SubsettotalPanc$BMILabled <- as.factor(SubsettotalPanc$BMILabled)
SubsettotalPanc$STEROID <- as.factor(SubsettotalPanc$STEROID)
SubsettotalPanc$DIABETES <- as.factor(SubsettotalPanc$DIABETES)
SubsettotalPanc$HYPERMED <- as.factor(SubsettotalPanc$HYPERMED)
SubsettotalPanc$ASCITES <- as.factor(SubsettotalPanc$ASCITES)
SubsettotalPanc$HXCOPD <- as.factor(SubsettotalPanc$HXCOPD)
SubsettotalPanc$DIALYSIS <- as.factor(SubsettotalPanc$DIALYSIS)
SubsettotalPanc$HXCHF <- as.factor(SubsettotalPanc$HXCHF)
SubsettotalPanc$Age <- as.factor(SubsettotalPanc$Age)
SubsettotalPanc$FNSTATUS2 <- as.factor(SubsettotalPanc$FNSTATUS2)
SubsettotalPanc$PatientGroup <- as.factor(SubsettotalPanc$PatientGroup)


SubsettotalPanc$PRNCPTX = relevel(SubsettotalPanc$PRNCPTX, ref="Distal Pancreatectomy")
SubsettotalPanc$SEX = relevel(SubsettotalPanc$SEX, ref="male")
SubsettotalPanc$ASACLAS = relevel(SubsettotalPanc$ASACLAS, ref="4-Life Threat")
SubsettotalPanc$BMILabled = relevel(SubsettotalPanc$BMILabled, ref="Normal Weight")
SubsettotalPanc$DIABETES = relevel(SubsettotalPanc$DIABETES, ref="NO")
SubsettotalPanc$HYPERMED = relevel(SubsettotalPanc$HYPERMED, ref="Yes")
SubsettotalPanc$STEROID = relevel(SubsettotalPanc$STEROID, ref="Yes")
SubsettotalPanc$ASCITES = relevel(SubsettotalPanc$ASCITES, ref="Yes")
SubsettotalPanc$HXCOPD = relevel(SubsettotalPanc$HXCOPD, ref="Yes")
SubsettotalPanc$DIALYSIS = relevel(SubsettotalPanc$DIALYSIS, ref="Yes")
SubsettotalPanc$HXCHF = relevel(SubsettotalPanc$HXCHF, ref="Yes")
SubsettotalPanc$Age = relevel(SubsettotalPanc$Age, ref="85+")
SubsettotalPanc$FNSTATUS2 = relevel(SubsettotalPanc$FNSTATUS2, ref="Totally Dependent")
####Multivariant analysis serious complications
MVORPan2 <- 
  glm(TextbookOutcomePanOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsettotalPanc,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTablePan2 <-
  tbl_regression(MVORPan2, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning in regularize.values(x, y, ties, missing(ties), na.rm = na.rm):
## collapsing to unique 'x' values

## Warning in regularize.values(x, y, ties, missing(ties), na.rm = na.rm):
## collapsing to unique 'x' values
tbl_merge(
  list(UVPan2, MVORTablePan2),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 628
85+
0-65 1.12 0.27, 5.55 0.88 1.09 0.25, 5.56 0.91
65-74 1.15 0.27, 5.72 0.85 1.08 0.24, 5.59 0.92
75-84 1.31 0.30, 6.68 0.72 1.48 0.32, 7.98 0.62
SEX 628
male
female 1.08 0.78, 1.48 0.64 0.96 0.67, 1.38 0.83
RACE_NEW 535
Black
Other 0.56 0.21, 1.39 0.22 0.49 0.22, 1.29 0.15
White 0.89 0.47, 1.68 0.71 0.80 0.41, 1.57 0.50
BMILabled 625
Normal Weight
Overweight 0.78 0.53, 1.14 0.20 0.88 0.57, 1.36 0.56
Morbidly Obese 0.82 0.33, 1.97 0.66 1.03 0.38, 2.71 0.95
Obese 0.72 0.47, 1.09 0.13 0.77 0.48, 1.25 0.30
Underweight 0.22 0.05, 0.69 0.019 0.21 0.03, 0.81 0.047
ASACLAS 626
4-Life Threat
1-No Disturb 2.93 0.11, 77.3 0.46 0.00 0.99
2-Mild Disturb 3.16 1.64, 6.38 <0.001 2.98 1.25, 7.59 0.017
3-Severe Disturb 1.94 1.07, 3.70 0.035 2.04 0.93, 4.85 0.088
STEROID 628
Yes
No 1.41 0.64, 3.33 0.41 1.34 0.55, 3.64 0.54
ASCITES 628
Yes
No 1.39 0.27, 10.1 0.71 1.60 0.15, 35.8 0.71
DYSPNEA 628
MODERATE EXERTION
No 1.41 0.71, 2.97 0.34 1.65 0.73, 4.00 0.24
SMOKE 628
No
Yes 1.26 0.84, 1.90 0.26 1.25 0.77, 2.04 0.37
DIALYSIS 628
Yes
No 1,475,264 0.00, NA 0.98 1,675,257 0.00, NA 0.98
DIABETES 628
NO
Yes 0.90 0.65, 1.25 0.55 0.95 0.65, 1.40 0.81
HYPERMED 628
Yes
No 1.14 0.83, 1.56 0.43 1.01 0.68, 1.52 0.94
HXCOPD 628
Yes
No 1.04 0.42, 2.69 0.93 0.74 0.23, 2.56 0.63
HXCHF 628
Yes
No 1,475,264 0.00, NA 0.98 791,289 0.00, NA 0.99

1 OR = Odds Ratio, CI = Confidence Interval

###Whipple

SubsetWhipple <- 
  subset(PanTextbookOutcomesSubset, PRNCPTX == "Whipple")

UVPan3 <- SubsetWhipple %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomePanOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomePanOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
###changling the referent level

SubsetWhipple$PRNCPTX <- as.factor(SubsetWhipple$PRNCPTX)
SubsetWhipple$SEX <- as.factor(SubsetWhipple$SEX)
SubsetWhipple$ASACLAS <- as.factor(SubsetWhipple$ASACLAS)
SubsetWhipple$BMILabled <- as.factor(SubsetWhipple$BMILabled)
SubsetWhipple$STEROID <- as.factor(SubsetWhipple$STEROID)
SubsetWhipple$DIABETES <- as.factor(SubsetWhipple$DIABETES)
SubsetWhipple$HYPERMED <- as.factor(SubsetWhipple$HYPERMED)
SubsetWhipple$ASCITES <- as.factor(SubsetWhipple$ASCITES)
SubsetWhipple$HXCOPD <- as.factor(SubsetWhipple$HXCOPD)
SubsetWhipple$DIALYSIS <- as.factor(SubsetWhipple$DIALYSIS)
SubsetWhipple$HXCHF <- as.factor(SubsetWhipple$HXCHF)
SubsetWhipple$Age <- as.factor(SubsetWhipple$Age)
SubsetWhipple$FNSTATUS2 <- as.factor(SubsetWhipple$FNSTATUS2)
SubsetWhipple$PatientGroup <- as.factor(SubsetWhipple$PatientGroup)


SubsetWhipple$PRNCPTX = relevel(SubsetWhipple$PRNCPTX, ref="Distal Pancreatectomy")
SubsetWhipple$SEX = relevel(SubsetWhipple$SEX, ref="male")
SubsetWhipple$ASACLAS = relevel(SubsetWhipple$ASACLAS, ref="4-Life Threat")
SubsetWhipple$BMILabled = relevel(SubsetWhipple$BMILabled, ref="Normal Weight")
SubsetWhipple$DIABETES = relevel(SubsetWhipple$DIABETES, ref="NO")
SubsetWhipple$HYPERMED = relevel(SubsetWhipple$HYPERMED, ref="Yes")
SubsetWhipple$STEROID = relevel(SubsetWhipple$STEROID, ref="Yes")
SubsetWhipple$ASCITES = relevel(SubsetWhipple$ASCITES, ref="Yes")
SubsetWhipple$HXCOPD = relevel(SubsetWhipple$HXCOPD, ref="Yes")
SubsetWhipple$DIALYSIS = relevel(SubsetWhipple$DIALYSIS, ref="Yes")
SubsetWhipple$HXCHF = relevel(SubsetWhipple$HXCHF, ref="Yes")
SubsetWhipple$Age = relevel(SubsetWhipple$Age, ref="85+")
SubsetWhipple$FNSTATUS2 = relevel(SubsetWhipple$FNSTATUS2, ref="Totally Dependent")
####Multivariant analysis serious complications
MVORPan3 <- 
  glm(TextbookOutcomePanOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsetWhipple,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTablePan3 <-
  tbl_regression(MVORPan3, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVPan3, MVORTablePan3),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 14,230
85+
0-65 1.47 1.14, 1.90 0.003 1.52 1.16, 2.00 0.003
65-74 1.30 1.01, 1.69 0.045 1.35 1.03, 1.78 0.030
75-84 1.13 0.87, 1.47 0.36 1.18 0.90, 1.57 0.24
SEX 14,230
male
female 1.19 1.11, 1.27 <0.001 1.18 1.10, 1.27 <0.001
RACE_NEW 12,348
Black
Other 0.74 0.60, 0.90 0.003 0.65 0.53, 0.79 <0.001
White 1.08 0.95, 1.22 0.24 1.11 0.98, 1.27 0.11
BMILabled 14,162
Normal Weight
Overweight 0.80 0.74, 0.87 <0.001 0.79 0.72, 0.86 <0.001
Morbidly Obese 0.58 0.47, 0.71 <0.001 0.53 0.43, 0.66 <0.001
Obese 0.69 0.63, 0.75 <0.001 0.65 0.59, 0.72 <0.001
Underweight 1.13 0.91, 1.39 0.26 1.10 0.87, 1.37 0.43
ASACLAS 14,213
4-Life Threat
1-No Disturb 1.62 0.94, 2.76 0.075 1.50 0.79, 2.83 0.21
2-Mild Disturb 1.70 1.46, 1.98 <0.001 1.61 1.34, 1.96 <0.001
3-Severe Disturb 1.47 1.28, 1.69 <0.001 1.45 1.22, 1.73 <0.001
STEROID 14,230
Yes
No 1.33 1.07, 1.66 0.010 1.38 1.10, 1.75 0.007
ASCITES 14,230
Yes
No 1.25 0.69, 2.36 0.47 1.27 0.67, 2.54 0.47
DYSPNEA 14,230
AT REST
MODERATE EXERTION 0.98 0.38, 2.84 0.97 1.05 0.37, 3.43 0.93
No 1.36 0.53, 3.90 0.54 1.20 0.42, 3.90 0.74
SMOKE 14,230
No
Yes 1.17 1.07, 1.28 <0.001 1.12 1.01, 1.23 0.032
DIALYSIS 14,230
Yes
No 3.91 1.77, 10.3 0.002 2.33 1.02, 6.31 0.064
DIABETES 14,230
NO
Yes 1.01 0.93, 1.09 0.88 1.17 1.07, 1.28 <0.001
HYPERMED 14,230
Yes
No 1.21 1.13, 1.29 <0.001 1.07 0.99, 1.16 0.095
HXCOPD 14,230
Yes
No 1.63 1.36, 1.95 <0.001 1.58 1.30, 1.93 <0.001
HXCHF 14,230
Yes
No 2.80 1.51, 5.70 0.002 2.34 1.17, 5.21 0.024

1 OR = Odds Ratio, CI = Confidence Interval

###changling the referent level


HepTextbookOutcomesSubset$PRNCPTX <- as.factor(HepTextbookOutcomesSubset$PRNCPTX)
HepTextbookOutcomesSubset$SEX <- as.factor(HepTextbookOutcomesSubset$SEX)
HepTextbookOutcomesSubset$BMILabled <- as.factor(HepTextbookOutcomesSubset$BMILabled)
HepTextbookOutcomesSubset$ASACLAS <- as.factor(HepTextbookOutcomesSubset$ASACLAS)
HepTextbookOutcomesSubset$STEROID <- as.factor(HepTextbookOutcomesSubset$STEROID)
HepTextbookOutcomesSubset$DIABETES <- as.factor(HepTextbookOutcomesSubset$DIABETES)
HepTextbookOutcomesSubset$HYPERMED <- as.factor(HepTextbookOutcomesSubset$HYPERMED)
HepTextbookOutcomesSubset$ASCITES <- as.factor(HepTextbookOutcomesSubset$ASCITES)
HepTextbookOutcomesSubset$HXCOPD <- as.factor(HepTextbookOutcomesSubset$HXCOPD)
HepTextbookOutcomesSubset$DIALYSIS <- as.factor(HepTextbookOutcomesSubset$DIALYSIS)
HepTextbookOutcomesSubset$HXCHF <- as.factor(HepTextbookOutcomesSubset$HXCHF)
HepTextbookOutcomesSubset$SMOKE <- as.factor(HepTextbookOutcomesSubset$SMOKE)
HepTextbookOutcomesSubset$Age <- as.factor(HepTextbookOutcomesSubset$Age)


HepTextbookOutcomesSubset$PRNCPTX = relevel(HepTextbookOutcomesSubset$PRNCPTX, ref="Trisegmentectomy")
HepTextbookOutcomesSubset$SEX = relevel(HepTextbookOutcomesSubset$SEX, ref="male")
HepTextbookOutcomesSubset$BMILabled = relevel(HepTextbookOutcomesSubset$BMILabled, ref="Normal Weight")
HepTextbookOutcomesSubset$ASACLAS = relevel(HepTextbookOutcomesSubset$ASACLAS, ref="4-Life Threat")
HepTextbookOutcomesSubset$DIABETES = relevel(HepTextbookOutcomesSubset$DIABETES, ref="Yes")
HepTextbookOutcomesSubset$HYPERMED = relevel(HepTextbookOutcomesSubset$HYPERMED, ref="Yes")
HepTextbookOutcomesSubset$STEROID = relevel(HepTextbookOutcomesSubset$STEROID, ref="Yes")
HepTextbookOutcomesSubset$ASCITES = relevel(HepTextbookOutcomesSubset$ASCITES, ref="Yes")
HepTextbookOutcomesSubset$HXCOPD = relevel(HepTextbookOutcomesSubset$HXCOPD, ref="Yes")
HepTextbookOutcomesSubset$DIALYSIS = relevel(HepTextbookOutcomesSubset$DIALYSIS, ref="Yes")
HepTextbookOutcomesSubset$HXCHF = relevel(HepTextbookOutcomesSubset$HXCHF, ref="Yes")
HepTextbookOutcomesSubset$SMOKE = relevel(HepTextbookOutcomesSubset$SMOKE, ref="Yes")
HepTextbookOutcomesSubset$Age = relevel(HepTextbookOutcomesSubset$Age, ref="85+")
UVHep <- HepTextbookOutcomesSubset %>%
  select(PRNCPTX, Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomeHepOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomeHepOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
HepTextbookOutcomesSubset$PRNCPTX <- as.factor(HepTextbookOutcomesSubset$PRNCPTX)
HepTextbookOutcomesSubset$BMILabled <- as.factor(HepTextbookOutcomesSubset$BMILabled)
HepTextbookOutcomesSubset$ASACLAS <- as.factor(HepTextbookOutcomesSubset$ASACLAS)
HepTextbookOutcomesSubset$STEROID <- as.factor(HepTextbookOutcomesSubset$STEROID)
HepTextbookOutcomesSubset$DIABETES <- as.factor(HepTextbookOutcomesSubset$DIABETES)
HepTextbookOutcomesSubset$HYPERMED <- as.factor(HepTextbookOutcomesSubset$HYPERMED)
HepTextbookOutcomesSubset$ASCITES <- as.factor(HepTextbookOutcomesSubset$ASCITES)
HepTextbookOutcomesSubset$HXCOPD <- as.factor(HepTextbookOutcomesSubset$HXCOPD)
HepTextbookOutcomesSubset$DIALYSIS <- as.factor(HepTextbookOutcomesSubset$DIALYSIS)
HepTextbookOutcomesSubset$HXCHF <- as.factor(HepTextbookOutcomesSubset$HXCHF)
HepTextbookOutcomesSubset$SMOKE <- as.factor(HepTextbookOutcomesSubset$SMOKE)
HepTextbookOutcomesSubset$Age <- as.factor(HepTextbookOutcomesSubset$Age)


HepTextbookOutcomesSubset$PRNCPTX = relevel(HepTextbookOutcomesSubset$PRNCPTX, ref="Trisegmentectomy")
HepTextbookOutcomesSubset$BMILabled = relevel(HepTextbookOutcomesSubset$BMILabled, ref="Normal Weight")
HepTextbookOutcomesSubset$ASACLAS = relevel(HepTextbookOutcomesSubset$ASACLAS, ref="4-Life Threat")
HepTextbookOutcomesSubset$DIABETES = relevel(HepTextbookOutcomesSubset$DIABETES, ref="Yes")
HepTextbookOutcomesSubset$HYPERMED = relevel(HepTextbookOutcomesSubset$HYPERMED, ref="Yes")
HepTextbookOutcomesSubset$STEROID = relevel(HepTextbookOutcomesSubset$STEROID, ref="Yes")
HepTextbookOutcomesSubset$ASCITES = relevel(HepTextbookOutcomesSubset$ASCITES, ref="Yes")
HepTextbookOutcomesSubset$HXCOPD = relevel(HepTextbookOutcomesSubset$HXCOPD, ref="Yes")
HepTextbookOutcomesSubset$DIALYSIS = relevel(HepTextbookOutcomesSubset$DIALYSIS, ref="Yes")
HepTextbookOutcomesSubset$HXCHF = relevel(HepTextbookOutcomesSubset$HXCHF, ref="Yes")
HepTextbookOutcomesSubset$SMOKE = relevel(HepTextbookOutcomesSubset$SMOKE, ref="Yes")
HepTextbookOutcomesSubset$Age = relevel(HepTextbookOutcomesSubset$Age, ref="85+")
####Multivariant analysis serious complications
MVORHep <- 
  glm(TextbookOutcomeHepOR ~ PRNCPTX + Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = HepTextbookOutcomesSubset,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTableHep <-
  tbl_regression(MVORHep, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVHep, MVORTableHep),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
PRNCPTX 14,656
Trisegmentectomy
Lobectomy 1.30 1.14, 1.49 <0.001 1.28 1.10, 1.50 0.002
Partial Lobectomy 1.36 1.20, 1.54 <0.001 1.36 1.18, 1.57 <0.001
Age 14,656
85+
0-65 1.94 1.36, 2.82 <0.001 1.83 1.21, 2.80 0.004
65-74 1.40 0.98, 2.04 0.071 1.48 0.98, 2.27 0.066
75-84 1.09 0.75, 1.60 0.65 1.17 0.77, 1.81 0.46
SEX 14,656
male
female 1.36 1.27, 1.45 <0.001 1.27 1.18, 1.37 <0.001
RACE_NEW 11,659
Black
Other 0.96 0.82, 1.14 0.67 0.95 0.80, 1.13 0.56
White 1.11 0.99, 1.25 0.084 1.07 0.95, 1.21 0.25
BMILabled 14,563
Normal Weight
Morbidly Obese 0.96 0.82, 1.12 0.59 0.96 0.81, 1.15 0.67
Obese 1.03 0.95, 1.12 0.51 1.09 0.99, 1.21 0.089
Overweight 1.08 0.99, 1.17 0.068 1.15 1.05, 1.27 0.003
Underweight 0.79 0.60, 1.03 0.082 0.73 0.54, 0.99 0.042
ASACLAS 14,617
4-Life Threat
1-No Disturb 3.24 2.40, 4.39 <0.001 2.10 1.31, 3.43 0.002
2-Mild Disturb 2.62 2.28, 3.02 <0.001 1.84 1.52, 2.23 <0.001
3-Severe Disturb 1.76 1.55, 2.01 <0.001 1.37 1.15, 1.64 <0.001
STEROID 14,656
Yes
No 1.27 1.05, 1.54 0.013 1.17 0.95, 1.44 0.15
ASCITES 14,656
Yes
No 3.34 2.06, 5.71 <0.001 3.01 1.78, 5.37 <0.001
DYSPNEA 14,656
AT REST
MODERATE EXERTION 1.36 0.67, 2.93 0.40 1.21 0.57, 2.69 0.62
No 2.01 1.01, 4.28 0.055 1.47 0.71, 3.22 0.31
SMOKE 14,656
Yes
No 1.10 1.01, 1.20 0.038 1.03 0.93, 1.15 0.56
DIALYSIS 14,656
Yes
No 2.55 1.32, 5.31 0.008 1.75 0.85, 3.88 0.14
DIABETES 14,656
Yes
NO 1.46 1.34, 1.59 <0.001 1.23 1.11, 1.37 <0.001
HYPERMED 14,656
Yes
No 1.34 1.26, 1.43 <0.001 1.10 1.01, 1.19 0.032
HXCOPD 14,656
Yes
No 1.64 1.38, 1.96 <0.001 1.24 1.01, 1.51 0.040
HXCHF 14,656
Yes
No 2.85 1.57, 5.55 <0.001 2.01 1.04, 4.19 0.048

1 OR = Odds Ratio, CI = Confidence Interval

####Partiallobectomy

SubsetPartialLobectomy <- 
  subset(HepTextbookOutcomesSubset, PRNCPTX == "Partial Lobectomy")

UVHep1 <- HepTextbookOutcomesSubset %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomeHepOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomeHepOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
SubsetPartialLobectomy$PRNCPTX <- as.factor(SubsetPartialLobectomy$PRNCPTX)
SubsetPartialLobectomy$BMILabled <- as.factor(SubsetPartialLobectomy$BMILabled)
SubsetPartialLobectomy$ASACLAS <- as.factor(SubsetPartialLobectomy$ASACLAS)
SubsetPartialLobectomy$STEROID <- as.factor(SubsetPartialLobectomy$STEROID)
SubsetPartialLobectomy$DIABETES <- as.factor(SubsetPartialLobectomy$DIABETES)
SubsetPartialLobectomy$HYPERMED <- as.factor(SubsetPartialLobectomy$HYPERMED)
SubsetPartialLobectomy$ASCITES <- as.factor(SubsetPartialLobectomy$ASCITES)
SubsetPartialLobectomy$HXCOPD <- as.factor(SubsetPartialLobectomy$HXCOPD)
SubsetPartialLobectomy$DIALYSIS <- as.factor(SubsetPartialLobectomy$DIALYSIS)
SubsetPartialLobectomy$HXCHF <- as.factor(SubsetPartialLobectomy$HXCHF)
SubsetPartialLobectomy$SMOKE <- as.factor(SubsetPartialLobectomy$SMOKE)
SubsetPartialLobectomy$Age <- as.factor(SubsetPartialLobectomy$Age)


SubsetPartialLobectomy$PRNCPTX = relevel(SubsetPartialLobectomy$PRNCPTX, ref="Trisegmentectomy")
SubsetPartialLobectomy$BMILabled = relevel(SubsetPartialLobectomy$BMILabled, ref="Normal Weight")
SubsetPartialLobectomy$ASACLAS = relevel(SubsetPartialLobectomy$ASACLAS, ref="4-Life Threat")
SubsetPartialLobectomy$DIABETES = relevel(SubsetPartialLobectomy$DIABETES, ref="Yes")
SubsetPartialLobectomy$HYPERMED = relevel(SubsetPartialLobectomy$HYPERMED, ref="Yes")
SubsetPartialLobectomy$STEROID = relevel(SubsetPartialLobectomy$STEROID, ref="Yes")
SubsetPartialLobectomy$ASCITES = relevel(SubsetPartialLobectomy$ASCITES, ref="Yes")
SubsetPartialLobectomy$HXCOPD = relevel(SubsetPartialLobectomy$HXCOPD, ref="Yes")
SubsetPartialLobectomy$DIALYSIS = relevel(SubsetPartialLobectomy$DIALYSIS, ref="Yes")
SubsetPartialLobectomy$HXCHF = relevel(SubsetPartialLobectomy$HXCHF, ref="Yes")
SubsetPartialLobectomy$SMOKE = relevel(SubsetPartialLobectomy$SMOKE, ref="Yes")
SubsetPartialLobectomy$Age = relevel(SubsetPartialLobectomy$Age, ref="85+")
####Multivariant analysis serious complications
MVORHep1 <- 
  glm(TextbookOutcomeHepOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsetPartialLobectomy,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTableHep1 <-
  tbl_regression(MVORHep1, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVHep1, MVORTableHep1),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 14,656
85+
0-65 1.94 1.36, 2.82 <0.001 1.97 1.24, 3.18 0.005
65-74 1.40 0.98, 2.04 0.071 1.64 1.03, 2.65 0.039
75-84 1.09 0.75, 1.60 0.65 1.25 0.78, 2.05 0.36
SEX 14,656
male
female 1.36 1.27, 1.45 <0.001 1.28 1.17, 1.41 <0.001
RACE_NEW 11,659
Black
Other 0.96 0.82, 1.14 0.67 0.99 0.80, 1.22 0.89
White 1.11 0.99, 1.25 0.084 1.06 0.92, 1.23 0.40
BMILabled 14,563
Normal Weight
Morbidly Obese 0.96 0.82, 1.12 0.59 0.97 0.79, 1.18 0.75
Obese 1.03 0.95, 1.12 0.51 1.07 0.95, 1.21 0.28
Overweight 1.08 0.99, 1.17 0.068 1.11 0.99, 1.25 0.072
Underweight 0.79 0.60, 1.03 0.082 0.78 0.53, 1.14 0.20
ASACLAS 14,617
4-Life Threat
1-No Disturb 3.24 2.40, 4.39 <0.001 2.17 1.26, 3.81 0.006
2-Mild Disturb 2.62 2.28, 3.02 <0.001 2.01 1.60, 2.55 <0.001
3-Severe Disturb 1.76 1.55, 2.01 <0.001 1.39 1.12, 1.73 0.003
STEROID 14,656
Yes
No 1.27 1.05, 1.54 0.013 1.15 0.90, 1.47 0.27
ASCITES 14,656
Yes
No 3.34 2.06, 5.71 <0.001 3.80 2.02, 7.80 <0.001
DYSPNEA 14,656
AT REST
MODERATE EXERTION 1.36 0.67, 2.93 0.40 0.76 0.31, 1.86 0.53
No 2.01 1.01, 4.28 0.055 0.92 0.39, 2.23 0.85
SMOKE 14,656
Yes
No 1.10 1.01, 1.20 0.038 1.00 0.88, 1.14 0.97
DIALYSIS 14,656
Yes
No 2.55 1.32, 5.31 0.008 1.65 0.73, 4.08 0.25
DIABETES 14,656
Yes
NO 1.46 1.34, 1.59 <0.001 1.20 1.06, 1.36 0.003
HYPERMED 14,656
Yes
No 1.34 1.26, 1.43 <0.001 1.10 0.99, 1.21 0.073
HXCOPD 14,656
Yes
No 1.64 1.38, 1.96 <0.001 1.27 1.00, 1.61 0.050
HXCHF 14,656
Yes
No 2.85 1.57, 5.55 <0.001 1.58 0.77, 3.50 0.23

1 OR = Odds Ratio, CI = Confidence Interval

####Trisegmentectomy


SubsetTrisegmentectomy<- 
  subset(HepTextbookOutcomesSubset, PRNCPTX == "Trisegmentectomy")

UVHep2 <- SubsetTrisegmentectomy %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomeHepOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomeHepOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: Problem with `mutate()` input `tbl`.
## x glm.fit: fitted probabilities numerically 0 or 1 occurred
## ℹ Input `tbl` is `map2(...)`.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
SubsetTrisegmentectomy$PRNCPTX <- as.factor(SubsetTrisegmentectomy$PRNCPTX)
SubsetTrisegmentectomy$BMILabled <- as.factor(SubsetTrisegmentectomy$BMILabled)
SubsetTrisegmentectomy$ASACLAS <- as.factor(SubsetTrisegmentectomy$ASACLAS)
SubsetTrisegmentectomy$STEROID <- as.factor(SubsetTrisegmentectomy$STEROID)
SubsetTrisegmentectomy$DIABETES <- as.factor(SubsetTrisegmentectomy$DIABETES)
SubsetTrisegmentectomy$HYPERMED <- as.factor(SubsetTrisegmentectomy$HYPERMED)
SubsetTrisegmentectomy$ASCITES <- as.factor(SubsetTrisegmentectomy$ASCITES)
SubsetTrisegmentectomy$HXCOPD <- as.factor(SubsetTrisegmentectomy$HXCOPD)
SubsetTrisegmentectomy$DIALYSIS <- as.factor(SubsetTrisegmentectomy$DIALYSIS)
SubsetTrisegmentectomy$HXCHF <- as.factor(SubsetTrisegmentectomy$HXCHF)
SubsetTrisegmentectomy$SMOKE <- as.factor(SubsetTrisegmentectomy$SMOKE)
SubsetTrisegmentectomy$Age <- as.factor(SubsetTrisegmentectomy$Age)


SubsetTrisegmentectomy$PRNCPTX = relevel(SubsetTrisegmentectomy$PRNCPTX, ref="Trisegmentectomy")
SubsetTrisegmentectomy$BMILabled = relevel(SubsetTrisegmentectomy$BMILabled, ref="Normal Weight")
SubsetTrisegmentectomy$ASACLAS = relevel(SubsetTrisegmentectomy$ASACLAS, ref="4-Life Threat")
SubsetTrisegmentectomy$DIABETES = relevel(SubsetTrisegmentectomy$DIABETES, ref="Yes")
SubsetTrisegmentectomy$HYPERMED = relevel(SubsetTrisegmentectomy$HYPERMED, ref="Yes")
SubsetTrisegmentectomy$STEROID = relevel(SubsetTrisegmentectomy$STEROID, ref="Yes")
SubsetTrisegmentectomy$ASCITES = relevel(SubsetTrisegmentectomy$ASCITES, ref="Yes")
SubsetTrisegmentectomy$HXCOPD = relevel(SubsetTrisegmentectomy$HXCOPD, ref="Yes")
SubsetTrisegmentectomy$DIALYSIS = relevel(SubsetTrisegmentectomy$DIALYSIS, ref="Yes")
SubsetTrisegmentectomy$HXCHF = relevel(SubsetTrisegmentectomy$HXCHF, ref="Yes")
SubsetTrisegmentectomy$SMOKE = relevel(SubsetTrisegmentectomy$SMOKE, ref="Yes")
SubsetTrisegmentectomy$Age = relevel(SubsetTrisegmentectomy$Age, ref="85+")
####Multivariant analysis serious complications
MVORHep2 <- 
  glm(TextbookOutcomeHepOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsetTrisegmentectomy,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTableHep2 <-
  tbl_regression(MVORHep2, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
tbl_merge(
  list(UVHep2, MVORTableHep2),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 1,172
85+
0-65 632,023 0.00, NA 0.97
65-74 389,617 0.00, NA 0.97 0.71 0.51, 0.97 0.035
75-84 465,376 0.00, NA 0.97 0.87 0.52, 1.46 0.60
SEX 1,172
male
female 1.24 0.98, 1.56 0.074 1.26 0.95, 1.66 0.11
RACE_NEW 888
Black
Other 1.04 0.54, 2.01 0.90 1.17 0.71, 2.30 0.66
White 1.20 0.76, 1.92 0.44 1.16 0.72, 1.89 0.53
BMILabled 1,165
Normal Weight
Morbidly Obese 0.75 0.36, 1.51 0.44 0.62 0.23, 1.53 0.32
Obese 1.15 0.84, 1.57 0.37 1.27 0.87, 1.86 0.21
Overweight 1.30 0.98, 1.72 0.066 1.42 1.02, 1.99 0.037
Underweight 0.73 0.31, 1.61 0.46 0.66 0.26, 1.54 0.35
ASACLAS 1,169
4-Life Threat
1-No Disturb 2.26 0.51, 10.0 0.27 0.88 0.18, 2.69 0.87
2-Mild Disturb 1.95 1.24, 3.11 0.005 0.90 0.46, 1.78 0.77
3-Severe Disturb 1.51 0.99, 2.32 0.058 0.76 0.41, 1.44 0.40
STEROID 1,172
Yes
No 0.68 0.33, 1.41 0.30 0.82 0.35, 1.94 0.65
ASCITES 1,172
Yes
No 1.14 0.28, 5.60 0.85 0.54 0.07, 3.33 0.50
DYSPNEA 1,172
AT REST
MODERATE EXERTION 406,557 0.00, NA 0.97 1,257,424 0.00, NA 0.98
No 546,429 0.00, NA 0.97 1,614,950 0.00, NA 0.98
SMOKE 1,172
Yes
No 0.90 0.67, 1.22 0.50 0.86 0.59, 1.25 0.42
DIALYSIS 1,172
Yes
No 0.00 0.97 0.00 0.99
DIABETES 1,172
Yes
NO 1.43 1.03, 1.99 0.036 1.30 0.86, 1.99 0.21
HYPERMED 1,172
Yes
No 1.14 0.90, 1.45 0.26 1.03 0.76, 1.40 0.84
HXCOPD 1,172
Yes
No 1.61 0.85, 3.23 0.16 1.08 0.50, 2.44 0.84
HXCHF 1,172
Yes
No 536,356 0.00, NA 0.97 1,231,713 0.00, NA 0.98

1 OR = Odds Ratio, CI = Confidence Interval

###Lobectomy


SubsetLobectomy<- 
  subset(HepTextbookOutcomesSubset, PRNCPTX == "Lobectomy")

UVHep3 <- SubsetLobectomy %>%
  select(Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomeHepOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomeHepOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
SubsetLobectomy$PRNCPTX <- as.factor(SubsetLobectomy$PRNCPTX)
SubsetLobectomy$BMILabled <- as.factor(SubsetLobectomy$BMILabled)
SubsetLobectomy$ASACLAS <- as.factor(SubsetLobectomy$ASACLAS)
SubsetLobectomy$STEROID <- as.factor(SubsetLobectomy$STEROID)
SubsetLobectomy$DIABETES <- as.factor(SubsetLobectomy$DIABETES)
SubsetLobectomy$HYPERMED <- as.factor(SubsetLobectomy$HYPERMED)
SubsetLobectomy$ASCITES <- as.factor(SubsetLobectomy$ASCITES)
SubsetLobectomy$HXCOPD <- as.factor(SubsetLobectomy$HXCOPD)
SubsetLobectomy$DIALYSIS <- as.factor(SubsetLobectomy$DIALYSIS)
SubsetLobectomy$HXCHF <- as.factor(SubsetLobectomy$HXCHF)
SubsetLobectomy$SMOKE <- as.factor(SubsetLobectomy$SMOKE)
SubsetLobectomy$Age <- as.factor(SubsetLobectomy$Age)


SubsetLobectomy$PRNCPTX = relevel(SubsetLobectomy$PRNCPTX, ref="Trisegmentectomy")
SubsetLobectomy$BMILabled = relevel(SubsetLobectomy$BMILabled, ref="Normal Weight")
SubsetLobectomy$ASACLAS = relevel(SubsetLobectomy$ASACLAS, ref="4-Life Threat")
SubsetLobectomy$DIABETES = relevel(SubsetLobectomy$DIABETES, ref="Yes")
SubsetLobectomy$HYPERMED = relevel(SubsetLobectomy$HYPERMED, ref="Yes")
SubsetLobectomy$STEROID = relevel(SubsetLobectomy$STEROID, ref="Yes")
SubsetLobectomy$ASCITES = relevel(SubsetLobectomy$ASCITES, ref="Yes")
SubsetLobectomy$HXCOPD = relevel(SubsetLobectomy$HXCOPD, ref="Yes")
SubsetLobectomy$DIALYSIS = relevel(SubsetLobectomy$DIALYSIS, ref="Yes")
SubsetLobectomy$HXCHF = relevel(SubsetLobectomy$HXCHF, ref="Yes")
SubsetLobectomy$SMOKE = relevel(SubsetLobectomy$SMOKE, ref="Yes")
SubsetLobectomy$Age = relevel(SubsetLobectomy$Age, ref="85+")
####Multivariant analysis serious complications
MVORHep3 <- 
  glm(TextbookOutcomeHepOR ~ Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = SubsetLobectomy,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTableHep3 <-
  tbl_regression(MVORHep3, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVHep3, MVORTableHep3),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
Age 3,626
85+
0-65 1.69 0.78, 3.88 0.19 1.23 0.49, 3.25 0.66
65-74 1.21 0.55, 2.78 0.65 0.99 0.39, 2.60 0.98
75-84 0.85 0.38, 2.00 0.71 0.76 0.30, 2.05 0.58
SEX 3,626
male
female 1.32 1.16, 1.50 <0.001 1.24 1.05, 1.45 0.009
RACE_NEW 2,738
Black
Other 0.83 0.59, 1.16 0.28 0.81 0.57, 1.14 0.23
White 1.12 0.88, 1.42 0.37 1.05 0.82, 1.36 0.69
BMILabled 3,602
Normal Weight
Morbidly Obese 0.96 0.68, 1.36 0.83 1.01 0.68, 1.51 0.95
Obese 1.03 0.87, 1.22 0.73 1.11 0.90, 1.36 0.34
Overweight 1.19 1.01, 1.40 0.035 1.19 0.98, 1.45 0.079
Underweight 0.74 0.44, 1.23 0.25 0.66 0.36, 1.19 0.18
ASACLAS 3,613
4-Life Threat
1-No Disturb 3.57 2.18, 5.89 <0.001 2.92 0.76, 14.2 0.14
2-Mild Disturb 2.66 2.01, 3.55 <0.001 1.76 1.20, 2.62 0.004
3-Severe Disturb 2.07 1.59, 2.70 <0.001 1.58 1.10, 2.29 0.014
STEROID 3,626
Yes
No 1.46 0.97, 2.23 0.072 1.37 0.86, 2.22 0.18
ASCITES 3,626
Yes
No 3.59 1.14, 15.8 0.048 2.49 0.74, 11.3 0.17
DYSPNEA 3,626
AT REST
MODERATE EXERTION 3.63 0.60, 69.2 0.24 4.00 0.63, 78.1 0.21
No 5.50 0.94, 104 0.11 4.76 0.76, 91.9 0.16
SMOKE 3,626
Yes
No 1.17 0.98, 1.39 0.085 1.20 0.97, 1.48 0.10
DIALYSIS 3,626
Yes
No 8.07 1.52, 149 0.048 4.37 0.72, 83.7 0.18
DIABETES 3,626
Yes
NO 1.61 1.36, 1.92 <0.001 1.30 1.05, 1.62 0.015
HYPERMED 3,626
Yes
No 1.40 1.23, 1.60 <0.001 1.12 0.94, 1.33 0.19
HXCOPD 3,626
Yes
No 1.94 1.33, 2.89 <0.001 1.22 0.78, 1.91 0.39
HXCHF 3,626
Yes
No 4.94 1.32, 31.9 0.038 5.37 0.94, 101 0.12

1 OR = Odds Ratio, CI = Confidence Interval

###changing the referent level

TextbookOutcomeOR$PatientGroup <- as.factor(TextbookOutcomeOR$PatientGroup)
TextbookOutcomeOR$BMILabled <- as.factor(TextbookOutcomeOR$BMILabled)
TextbookOutcomeOR$ASACLAS <- as.factor(TextbookOutcomeOR$ASACLAS)
TextbookOutcomeOR$STEROID <- as.factor(TextbookOutcomeOR$STEROID)
TextbookOutcomeOR$DIABETES <- as.factor(TextbookOutcomeOR$DIABETES)
TextbookOutcomeOR$HYPERMED <- as.factor(TextbookOutcomeOR$HYPERMED)
TextbookOutcomeOR$ASCITES <- as.factor(TextbookOutcomeOR$ASCITES)
TextbookOutcomeOR$HXCOPD <- as.factor(TextbookOutcomeOR$HXCOPD)
TextbookOutcomeOR$DIALYSIS <- as.factor(TextbookOutcomeOR$DIALYSIS)
TextbookOutcomeOR$HXCHF <- as.factor(TextbookOutcomeOR$HXCHF)
TextbookOutcomeOR$SMOKE <- as.factor(TextbookOutcomeOR$SMOKE)
TextbookOutcomeOR$Age <- as.factor(TextbookOutcomeOR$Age)
TextbookOutcomeOR$SEX <- as.factor(TextbookOutcomeOR$SEX)




TextbookOutcomeOR$BMILabled = relevel(TextbookOutcomeOR$BMILabled, ref="Normal Weight")
TextbookOutcomeOR$ASACLAS = relevel(TextbookOutcomeOR$ASACLAS, ref="4-Life Threat")
TextbookOutcomeOR$DIABETES = relevel(TextbookOutcomeOR$DIABETES, ref="Yes")
TextbookOutcomeOR$SEX = relevel(TextbookOutcomeOR$SEX, ref="male")
TextbookOutcomeOR$SMOKE = relevel(TextbookOutcomeOR$SMOKE, ref="Yes")
TextbookOutcomeOR$STEROID = relevel(TextbookOutcomeOR$STEROID, ref="Yes")
TextbookOutcomeOR$ASCITES = relevel(TextbookOutcomeOR$ASCITES, ref="Yes")
TextbookOutcomeOR$HXCOPD = relevel(TextbookOutcomeOR$HXCOPD, ref="Yes")
TextbookOutcomeOR$DIALYSIS = relevel(TextbookOutcomeOR$DIALYSIS, ref="Yes")
TextbookOutcomeOR$HXCHF = relevel(TextbookOutcomeOR$HXCHF, ref="Yes")
TextbookOutcomeOR$Age = relevel(TextbookOutcomeOR$Age, ref="85+")
###Univariant, multivariant for everyone


UVAll <- TextbookOutcomeOR %>%
  select(PatientGroup, Age, SEX, RACE_NEW, BMILabled, ASACLAS, STEROID, ASCITES, DYSPNEA, SMOKE, DIALYSIS, DIABETES, HYPERMED, HXCOPD, HXCHF, TextbookOutcomeAllOR) %>%
  tbl_uvregression(
    method = glm,
    y = TextbookOutcomeAllOR,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels()
###changling the referent level

TextbookOutcomeOR$PatientGroup <- as.factor(TextbookOutcomeOR$PatientGroup)
TextbookOutcomeOR$SEX <- as.factor(TextbookOutcomeOR$SEX)
TextbookOutcomeOR$ASACLAS <- as.factor(TextbookOutcomeOR$ASACLAS)
TextbookOutcomeOR$STEROID <- as.factor(TextbookOutcomeOR$STEROID)
TextbookOutcomeOR$DIABETES <- as.factor(TextbookOutcomeOR$DIABETES)
TextbookOutcomeOR$SMOKE <- as.factor(TextbookOutcomeOR$SMOKE)
TextbookOutcomeOR$ASCITES <- as.factor(TextbookOutcomeOR$ASCITES)
TextbookOutcomeOR$HXCOPD <- as.factor(TextbookOutcomeOR$HXCOPD)
TextbookOutcomeOR$DIALYSIS <- as.factor(TextbookOutcomeOR$DIALYSIS)
TextbookOutcomeOR$HXCHF <- as.factor(TextbookOutcomeOR$HXCHF)
TextbookOutcomeOR$Age <- as.factor(TextbookOutcomeOR$Age)


TextbookOutcomeOR$SEX = relevel(TextbookOutcomeOR$SEX, ref="male")
TextbookOutcomeOR$BMILabled = relevel(TextbookOutcomeOR$BMILabled, ref="Normal Weight")
TextbookOutcomeOR$ASACLAS = relevel(TextbookOutcomeOR$ASACLAS, ref="4-Life Threat")
TextbookOutcomeOR$DIABETES = relevel(TextbookOutcomeOR$DIABETES, ref="Yes")
TextbookOutcomeOR$SMOKE = relevel(TextbookOutcomeOR$SMOKE, ref="Yes")
TextbookOutcomeOR$STEROID = relevel(TextbookOutcomeOR$STEROID, ref="Yes")
TextbookOutcomeOR$ASCITES = relevel(TextbookOutcomeOR$ASCITES, ref="Yes")
TextbookOutcomeOR$HXCOPD = relevel(TextbookOutcomeOR$HXCOPD, ref="Yes")
TextbookOutcomeOR$DIALYSIS = relevel(TextbookOutcomeOR$DIALYSIS, ref="Yes")
TextbookOutcomeOR$HXCHF = relevel(TextbookOutcomeOR$HXCHF, ref="Yes")
TextbookOutcomeOR$Age = relevel(TextbookOutcomeOR$Age, ref="85+")
####Multivariant analysis serious complications
MVORAll <- 
  glm(TextbookOutcomeAllOR ~ PatientGroup + Age + SEX + RACE_NEW + BMILabled + ASACLAS + STEROID + ASCITES + DYSPNEA + SMOKE + DIALYSIS + DIABETES + HYPERMED + HXCOPD + HXCHF, 
      data = TextbookOutcomeOR,
      family = binomial("logit"), 
      na.action =na.omit)
###continue on to merge the table sets
MVORTableAll <-
  tbl_regression(MVORAll, exponentiate = T,
                 pvalue_fun = ~style_pvalue(.x, digits = 2),
  ) %>%
  bold_p(t = 0.10) %>%
  bold_labels() %>%
  italicize_levels() 
tbl_merge(
  list(UVAll, MVORTableAll),
  tab_spanner = c("**Univariable**", "**Multivariable**")
) %>%
  bold_labels() %>%
  italicize_levels() 
Characteristic Univariable Multivariable
N OR1 95% CI1 p-value OR1 95% CI1 p-value
PatientGroup 35,154
Liver
Pancreas 0.77 0.74, 0.81 <0.001 0.78 0.74, 0.81 <0.001
Age 35,905
85+
0-65 1.76 1.47, 2.12 <0.001 1.60 1.30, 1.96 <0.001
65-74 1.42 1.18, 1.72 <0.001 1.42 1.16, 1.74 <0.001
75-84 1.19 0.98, 1.44 0.075 1.22 0.99, 1.51 0.059
SEX 35,905
male
female 1.28 1.23, 1.33 <0.001 1.23 1.17, 1.29 <0.001
RACE_NEW 30,147
Black
Other 0.93 0.83, 1.04 0.20 0.81 0.72, 0.92 <0.001
White 1.11 1.03, 1.19 0.009 1.10 1.01, 1.19 0.022
BMILabled 35,723
Normal Weight
Morbidly Obese 0.79 0.71, 0.87 <0.001 0.75 0.67, 0.84 <0.001
Obese 0.87 0.82, 0.92 <0.001 0.86 0.81, 0.92 <0.001
Overweight 0.95 0.90, 1.00 0.056 0.97 0.91, 1.02 0.26
Underweight 0.96 0.83, 1.12 0.61 0.98 0.83, 1.15 0.80
ASACLAS 35,830
4-Life Threat
1-No Disturb 2.97 2.37, 3.73 <0.001 2.11 1.54, 2.90 <0.001
2-Mild Disturb 2.33 2.13, 2.56 <0.001 1.86 1.65, 2.10 <0.001
3-Severe Disturb 1.65 1.52, 1.81 <0.001 1.45 1.30, 1.63 <0.001
STEROID 35,905
Yes
No 1.31 1.16, 1.49 <0.001 1.22 1.06, 1.40 0.004
ASCITES 35,905
Yes
No 2.45 1.73, 3.55 <0.001 2.36 1.62, 3.54 <0.001
DYSPNEA 35,905
AT REST
MODERATE EXERTION 1.20 0.71, 2.09 0.52 1.13 0.64, 2.08 0.68
No 1.79 1.07, 3.11 0.032 1.40 0.80, 2.55 0.25
SMOKE 35,905
Yes
No 1.03 0.97, 1.09 0.36 1.00 0.94, 1.07 0.91
DIALYSIS 35,905
Yes
No 2.71 1.84, 4.12 <0.001 2.06 1.33, 3.31 0.002
DIABETES 35,905
Yes
NO 1.24 1.18, 1.30 <0.001 1.02 0.96, 1.08 0.57
HYPERMED 35,905
No
Yes 0.78 0.75, 0.81 <0.001 0.93 0.88, 0.98 0.007
HXCOPD 35,905
Yes
No 1.71 1.53, 1.91 <0.001 1.40 1.24, 1.59 <0.001
HXCHF 35,905
Yes
No 2.73 1.89, 4.04 <0.001 1.76 1.17, 2.73 0.008

1 OR = Odds Ratio, CI = Confidence Interval

PanOddsPlotty <- 
  PanTextbookOutcomesSubset %>%
  select(PRNCPTX, SEX, RACE_NEW, BMILabled, STEROID, DIALYSIS, HXCOPD, HXCHF, TextbookOutcomePanOR)
PanOddsPlotty2 <- PanOddsPlotty[complete.cases(PanOddsPlotty), ] #Create a copy
head(PanOddsPlotty2, 10)
##                     PRNCPTX    SEX RACE_NEW     BMILabled STEROID DIALYSIS
## 17458               Whipple   male    White         Obese     Yes       No
## 17459               Whipple   male    White Normal Weight      No       No
## 17460               Whipple female    White         Obese      No       No
## 17461               Whipple female    White         Obese      No       No
## 17462               Whipple   male    White    Overweight      No       No
## 17463               Whipple female    Black         Obese      No       No
## 17464 Distal Pancreatectomy female    White Normal Weight     Yes       No
## 17465 Distal Pancreatectomy   male    White         Obese     Yes       No
## 17466 Distal Pancreatectomy   male    White         Obese      No       No
## 17467 Distal Pancreatectomy female    White         Obese      No       No
##       HXCOPD HXCHF TextbookOutcomePanOR
## 17458     No    No                    0
## 17459     No    No                    1
## 17460     No    No                    0
## 17461     No    No                    0
## 17462     No    No                    0
## 17463     No    No                    0
## 17464     No    No                    0
## 17465     No    No                    1
## 17466     No    No                    1
## 17467     No    No                    0
PanOddsPlotty2$TextbookOutcomePanOR <- factor(PanOddsPlotty2$TextbookOutcomePanOR)
PanOddsPlotty2$RACE_NEW <- factor(PanOddsPlotty2$RACE_NEW)


str(PanOddsPlotty2)
## 'data.frame':    19072 obs. of  9 variables:
##  $ PRNCPTX             : Factor w/ 3 levels "Distal Pancreatectomy",..: 3 3 3 3 3 3 1 1 1 1 ...
##  $ SEX                 : Factor w/ 2 levels "male","female": 1 1 2 2 1 2 2 1 1 2 ...
##  $ RACE_NEW            : Factor w/ 3 levels "Black","Other",..: 3 3 3 3 3 1 3 3 3 3 ...
##  $ BMILabled           : Factor w/ 5 levels "Normal Weight",..: 4 1 4 4 2 4 1 4 4 4 ...
##  $ STEROID             : Factor w/ 2 levels "Yes","No": 1 2 2 2 2 2 1 1 2 2 ...
##  $ DIALYSIS            : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ HXCOPD              : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ HXCHF               : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ TextbookOutcomePanOR: Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 2 2 1 ...
for(i in 1:8) {
  PanOddsPlotty2[, i] <- as.numeric(as.factor(PanOddsPlotty2[, i]))
}
###renaming variables
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'No Dialysis' = DIALYSIS)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'Female' = SEX)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'White' = RACE_NEW)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'No Steroid' = STEROID)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'No COPD' = HXCOPD)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'No CHF' = HXCHF)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'Total Pancreatectomy' = PRNCPTX)
PanOddsPlotty2 <- rename(PanOddsPlotty2, 'Underweight' = BMILabled)
glm_model <- train(TextbookOutcomePanOR ~ .,
                   data = PanOddsPlotty2,
                   method = "glm",
                   family = "binomial")

summary(glm_model)
## 
## Call:
## NULL
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.1376  -1.0364  -0.9599   1.3069   2.0774  
## 
## Coefficients:
##                              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                  -5.40283    0.81631  -6.619 3.63e-11 ***
## `\\`Total Pancreatectomy\\``  0.02087    0.01599   1.305  0.19189    
## Female                        0.20488    0.02975   6.887 5.71e-12 ***
## White                         0.07510    0.02421   3.102  0.00192 ** 
## Underweight                  -0.07883    0.01199  -6.572 4.96e-11 ***
## `\\`No Steroid\\``            0.24694    0.08968   2.753  0.00590 ** 
## `\\`No Dialysis\\``           0.88736    0.29118   3.047  0.00231 ** 
## `\\`No COPD\\``               0.47938    0.07734   6.198 5.71e-10 ***
## `\\`No CHF\\``                0.73109    0.26413   2.768  0.00564 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 25810  on 19071  degrees of freedom
## Residual deviance: 25635  on 19063  degrees of freedom
## AIC: 25653
## 
## Number of Fisher Scoring iterations: 4
## Number of Fisher Scoring iterations: 4
plotty <- OddsPlotty::odds_plot(glm_model$finalModel, 
                      title = "Pancreas Group",
                      subtitle = "Independent Associations for TO")
## Waiting for profiling to be done...
## Waiting for profiling to be done...
plot <- plotty$odds_plot

plot <- plot + ggthemes::theme_economist() + theme(legend.position = "NULL")

plot + geom_text(label=round(plotty$odds_plot$data$OR, digits = 2), hjust=0, vjust=1.8)

HepOddsPlotty <- 
  HepTextbookOutcomesSubset %>%
  select(PRNCPTX, SEX, RACE_NEW, BMILabled, STEROID, DIALYSIS, DIABETES, HXCOPD, HXCHF, TextbookOutcomeHepOR)
HepOddsPlotty2 <- HepOddsPlotty[complete.cases(HepOddsPlotty), ] #Create a copy
head(HepOddsPlotty2, 10)
##              PRNCPTX    SEX RACE_NEW     BMILabled STEROID DIALYSIS DIABETES
## 1  Partial Lobectomy   male    White    Overweight      No       No      Yes
## 2  Partial Lobectomy female    White         Obese      No       No       NO
## 3  Partial Lobectomy female    Black         Obese      No       No       NO
## 4  Partial Lobectomy female    White Normal Weight      No       No       NO
## 5  Partial Lobectomy   male    White    Overweight      No       No       NO
## 6  Partial Lobectomy   male    White    Overweight      No       No       NO
## 7  Partial Lobectomy female    White         Obese      No       No       NO
## 8  Partial Lobectomy female    White         Obese      No       No       NO
## 9  Partial Lobectomy   male    White    Overweight      No       No      Yes
## 10 Partial Lobectomy   male    White    Overweight      No       No       NO
##    HXCOPD HXCHF TextbookOutcomeHepOR
## 1      No    No                    0
## 2      No    No                    1
## 3      No    No                    1
## 4      No    No                    1
## 5      No    No                    1
## 6     Yes    No                    0
## 7      No    No                    1
## 8      No    No                    1
## 9      No    No                    0
## 10     No    No                    1
HepOddsPlotty2$TextbookOutcomeHepOR <- factor(HepOddsPlotty2$TextbookOutcomeHepOR)
HepOddsPlotty2$RACE_NEW <- factor(HepOddsPlotty2$RACE_NEW)


str(HepOddsPlotty2)
## 'data.frame':    11617 obs. of  10 variables:
##  $ PRNCPTX             : Factor w/ 3 levels "Trisegmentectomy",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ SEX                 : Factor w/ 2 levels "male","female": 1 2 2 2 1 1 2 2 1 1 ...
##  $ RACE_NEW            : Factor w/ 3 levels "Black","Other",..: 3 3 1 3 3 3 3 3 3 3 ...
##  $ BMILabled           : Factor w/ 5 levels "Normal Weight",..: 4 3 3 1 4 4 3 3 4 4 ...
##  $ STEROID             : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ DIALYSIS            : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ DIABETES            : Factor w/ 2 levels "Yes","NO": 1 2 2 2 2 2 2 2 1 2 ...
##  $ HXCOPD              : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 1 2 2 2 2 ...
##  $ HXCHF               : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ TextbookOutcomeHepOR: Factor w/ 2 levels "0","1": 1 2 2 2 2 1 2 2 1 2 ...
for(i in 1:9) {
  HepOddsPlotty2[, i] <- as.numeric(as.factor(HepOddsPlotty2[, i]))
}
###renaming variables
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'No Dialysis' = DIALYSIS)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'Female' = SEX)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'White' = RACE_NEW)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'No Steroid' = STEROID)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'No COPD' = HXCOPD)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'No CHF' = HXCHF)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'No Diabetes' = DIABETES)

HepOddsPlotty2 <- rename(HepOddsPlotty2, 'Lobectomy' = PRNCPTX)
HepOddsPlotty2 <- rename(HepOddsPlotty2, 'Obese' = BMILabled)
glm_modelhep <- train(TextbookOutcomeHepOR ~ .,
                   data = HepOddsPlotty2,
                   method = "glm",
                   family = "binomial")

summary(glm_modelhep)
## 
## Call:
## NULL
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.3185  -1.1638  -0.8909   1.1726   1.9965  
## 
## Coefficients:
##                     Estimate Std. Error z value Pr(>|z|)    
## (Intercept)         -6.49386    1.04277  -6.227 4.74e-10 ***
## Lobectomy            0.11848    0.03004   3.944 8.01e-05 ***
## Female               0.28058    0.03775   7.432 1.07e-13 ***
## White                0.04367    0.02887   1.512  0.13043    
## Obese                0.03377    0.01508   2.240  0.02512 *  
## `\\`No Steroid\\``   0.19966    0.10526   1.897  0.05786 .  
## `\\`No Dialysis\\``  0.83174    0.37348   2.227  0.02595 *  
## `\\`No Diabetes\\``  0.33922    0.04961   6.838 8.03e-12 ***
## `\\`No COPD\\``      0.43853    0.09746   4.500 6.81e-06 ***
## `\\`No CHF\\``       0.99246    0.34857   2.847  0.00441 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 16100  on 11616  degrees of freedom
## Residual deviance: 15918  on 11607  degrees of freedom
## AIC: 15938
## 
## Number of Fisher Scoring iterations: 4
plottyhep <- OddsPlotty::odds_plot(glm_modelhep$finalModel, 
                      title = "Liver Group",
                      subtitle = "Independent Associations for TO")
## Waiting for profiling to be done...
## Waiting for profiling to be done...
plothep <- plottyhep$odds_plot

plothep <- plothep + ggthemes::theme_economist() + theme(legend.position = "NULL")

plothep + geom_text(label=round(plottyhep$odds_plot$data$OR, digits = 2), hjust=0, vjust=1.8)

BothOddsPlotty <- 
  TextbookOutcomeOR %>%
  select(PatientGroup, SEX, STEROID, DIALYSIS, DIABETES, HXCOPD, HXCHF, TextbookOutcomeAllOR)
BothOddsPlotty2 <- BothOddsPlotty[complete.cases(BothOddsPlotty), ] #Create a copy
head(BothOddsPlotty2, 10)
##    PatientGroup    SEX STEROID DIALYSIS DIABETES HXCOPD HXCHF
## 1         Liver   male      No       No      Yes     No    No
## 2         Liver female      No       No       NO     No    No
## 3         Liver female      No       No       NO     No    No
## 4         Liver female      No       No       NO     No    No
## 5         Liver   male      No       No       NO     No    No
## 6         Liver   male      No       No       NO    Yes    No
## 7         Liver female      No       No       NO     No    No
## 8         Liver female      No       No       NO     No    No
## 9         Liver   male      No       No      Yes     No    No
## 10        Liver   male      No       No       NO     No    No
##    TextbookOutcomeAllOR
## 1                     0
## 2                     1
## 3                     1
## 4                     1
## 5                     1
## 6                     0
## 7                     1
## 8                     1
## 9                     0
## 10                    1
BothOddsPlotty2$TextbookOutcomeAllOR <- factor(BothOddsPlotty2$TextbookOutcomeAllOR)

str(BothOddsPlotty2)
## 'data.frame':    35154 obs. of  8 variables:
##  $ PatientGroup        : Factor w/ 2 levels "Liver","Pancreas": 1 1 1 1 1 1 1 1 1 1 ...
##  $ SEX                 : Factor w/ 2 levels "male","female": 1 2 2 2 1 1 2 2 1 1 ...
##  $ STEROID             : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ DIALYSIS            : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ DIABETES            : Factor w/ 2 levels "Yes","NO": 1 2 2 2 2 2 2 2 1 2 ...
##  $ HXCOPD              : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 1 2 2 2 2 ...
##  $ HXCHF               : Factor w/ 2 levels "Yes","No": 2 2 2 2 2 2 2 2 2 2 ...
##  $ TextbookOutcomeAllOR: Factor w/ 2 levels "0","1": 1 2 2 2 2 1 2 2 1 2 ...
for(i in 1:7) {
  BothOddsPlotty2[, i] <- as.numeric(as.factor(BothOddsPlotty2[, i]))
}
###renaming variables
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'No Dialysis' = DIALYSIS)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'Female' = SEX)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'No Steroid' = STEROID)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'No COPD' = HXCOPD)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'No CHF' = HXCHF)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'No Diabetes' = DIABETES)
BothOddsPlotty2 <- rename(BothOddsPlotty2, 'Pancreatic' = PatientGroup)
glm_modelboth <- train(TextbookOutcomeAllOR ~ .,
                   data = BothOddsPlotty2,
                   method = "glm",
                   family = "binomial")

summary(glm_modelboth)
## 
## Call:
## NULL
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.2248  -1.1220  -0.9696   1.2338   2.0334  
## 
## Coefficients:
##                     Estimate Std. Error z value Pr(>|z|)    
## (Intercept)         -5.36928    0.59904  -8.963  < 2e-16 ***
## Pancreatic          -0.24256    0.02201 -11.022  < 2e-16 ***
## Female               0.22728    0.02167  10.488  < 2e-16 ***
## `\\`No Steroid\\``   0.24218    0.06422   3.771 0.000162 ***
## `\\`No Dialysis\\``  0.90930    0.21287   4.272 1.94e-05 ***
## `\\`No Diabetes\\``  0.15174    0.02612   5.809 6.27e-09 ***
## `\\`No COPD\\``      0.48508    0.05738   8.453  < 2e-16 ***
## `\\`No CHF\\``       0.84574    0.19760   4.280 1.87e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 48336  on 35153  degrees of freedom
## Residual deviance: 47891  on 35146  degrees of freedom
## AIC: 47907
## 
## Number of Fisher Scoring iterations: 4
plottyboth <- OddsPlotty::odds_plot(glm_modelboth$finalModel, 
                      title = "Liver & Pancreatic Group",
                      subtitle = "Independent Associations for TO")
## Waiting for profiling to be done...
## Waiting for profiling to be done...
plotboth <- plottyboth$odds_plot

plotboth <- plotboth + ggthemes::theme_economist() + theme(legend.position = "NULL")

plotboth + geom_text(label=round(plottyboth$odds_plot$data$OR, digits = 2), hjust=0, vjust=1.8)