\(~\) \(~\) \(~\) \(~\)

Project Overview

Research Question

Post-mastectomy radiation therapy (PMRT) and breast reconstruction constitute two important pillars in the treatment of patients with breast cancer. While PMRT significantly improves survival and reduces recurrence, it is associated with increased post-operative complications and decreased patient-reported outcomes following breast reconstruction. Strategies aimed at optimizing the survival benefits of PMRT and the quality of life benefits of breast reconstruction are thus a top priority for those caring for patients with breast cancer.

Proton therapy is an emerging PMRT modality that may offer such a balance…“A type of radiation treatment called proton beam radiation therapy may be safer and just as effective as traditional radiation therapy for adults with advanced cancer. That finding comes from a study that used existing patient data to compare the two types of radiation….Traditional radiation delivers x-rays, or beams of photons, to the tumor and beyond it. This can damage nearby healthy tissues and can cause significant side effects. By contrast, proton therapy delivers a beam of proton particles that stops at the tumor, so it’s less likely to damage nearby healthy tissues….In the new study, patients treated with proton therapy were much less likely to experience severe side effects than patients treated with traditional radiation therapy. There was no difference in how long the patients lived, however. The results were published December 26 in JAMA Oncology.” (“Is Proton Therapy Safer than Traditional Radiation?”, National Cancer Institute)

In this study, we set out to determine if surgical complications following breast reconstruction were reduced in patients who received proton PMRT compared to those who received traditional photon PMRT.


Note to self: Consider confounding by indication. Are women who receive proton therapy different to women who receive photon therapy in other ways than therapy type alone? What potential confounders are available in dataset to adjust for?


Methods

A retrospective chart review of consecutive patients who underwent mastectomies at a single institution was performed by the first-author. Inclusion criteria included receipt of PMRT and implant-based breast reconstruction (either staged with the use of a tissue expander [TE] or direct-to-implant [DTI]). Data collected included patient characteristics (age, BMI, diabetes, smoking), operative details (type of implant used, unilateral vs bilateral reconstruction), radiation details (type of radiation, total dose, total rounds). Outcome variables included seroma, hematoma, mastectomy skin flap necrosis (MSFN), minor infection (treated outpatient), major infection (requiring readmission or reoperation), and implant failure defined as removal of the implant. Implant failure was further stratified into any-cause and infection-specific implant failure. Patients who received both proton and photon radiation, did not complete their PMRT, had incomplete reconstruction or radiation data, or for whom follow-up time was less than … at the time of chart review were excluded from the study.

\(~\) \(~\)

\(~\) \(~\)

Analysis

Importing the Data

Data from an excel spreadsheet is read in and copied to the dataframe, df. Data type is then confirmed for all character, factor, and date variables.

# Read in the data
df <- read_excel("/Users/skebede/Downloads/dataset_cut_10.10.23.xlsx")

# Ensure that all the data types are correct
df <- df %>%
  mutate(
    # Converting character columns
    Name = as.character(Name),
    MRN = as.character(MRN),
    FIN = as.character(FIN),

    # Converting continuous columns
    Age = as.numeric(Age),
    BMI = as.numeric(BMI),
    XRT_dose = as.numeric(XRT_dose),
    XRT_rounds = as.numeric(XRT_rounds),
    
    # Converting categorical columns to factors
    DM = factor(DM),
    Smoking = factor(Smoking),
    XRT_type = factor(XRT_type),
    XRT_side = factor(XRT_side),
    Recon_type = factor(Recon_type),
    Recon_laterality = factor(Recon_laterality),
    seroma = factor(seroma),
    hematoma = factor(hematoma),
    infxn_minor = factor(infxn_minor),
    infxn_major = factor(infxn_major),
    fail_any = factor(fail_any),
    fail_infxn = factor(fail_infxn),
  
    
    # Converting date columns
    DOB = ymd(DOB),
    surg_date = ymd(surg_date),
    XRT_start = ymd(XRT_start),
    XRT_end = ymd(XRT_end)
  )

\(~\)


\(~\)

Cleaning the Data

Variable names are change for consistency and ease of. Variable labels are also created to improve readability.

# Rename variables
df <- df %>%
  rename(
    name = Name,
    age = Age,
    bmi = BMI,
    diabetes = DM,
    smoking = Smoking,
    xrt_type = XRT_type,
    xrt_side = XRT_side,
    xrt_dose = XRT_dose,
    xrt_rounds = XRT_rounds,
    xrt_start = XRT_start,
    xrt_end = XRT_end,
    recon_type = Recon_type,
    recon_laterality = Recon_laterality,
    msfn = MSFN
  )

# Add variable labels
label(df$age) <- "Age"
label(df$bmi) <- "BMI"
label(df$diabetes) <- "Diabetes"
label(df$smoking) <- "Smoking"
label(df$surg_date) <- "Date of Surgery"
label(df$xrt_type) <- "Type of Radiation"
label(df$xrt_side) <- "Radiation Side"
label(df$xrt_dose) <- "Total Dose of Radiation"
label(df$xrt_rounds) <- "Total Rounds of Radiaton"
label(df$xrt_start) <- "Radiation Start Date"
label(df$xrt_end) <- "Radiation End Date"
label(df$recon_type) <- "Type of Reconstruction"
label(df$recon_laterality) <- "Reconstruction Laterality"
label(df$seroma) <- "Seroma"
label(df$hematoma) <- "Hematoma"
label(df$msfn) <- "MSFN"
label(df$infxn_minor) <- "Minor Infection"
label(df$infxn_major) <- "Major Infection"
label(df$fail_any) <- "Any-Cause Reconstruction Failure"
label(df$fail_infxn) <- "Infection-Specific Reconstruction Failure"

\(~\)


\(~\)

Descriptive Statistics

Descriptive statistics for all patients (Table 1a) and stratified by type of radiation (Table 1b).

# All Patients
table_1a <- df %>%
  select(age, bmi, diabetes, smoking, 
         recon_type, recon_laterality, 
         xrt_side, xrt_dose, xrt_rounds, xrt_type, 
         seroma, hematoma, msfn, infxn_minor, infxn_major, fail_any, fail_infxn) %>%
  tbl_summary(type = all_dichotomous() ~ "categorical") %>%
  as_gt() %>%
  tab_header(title = md("Table 1a: Descriptive Statistics")) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden",
              table.border.bottom.style = "hidden",
              heading.title.font.size = "medium")
table_1a
Table 1a: Descriptive Statistics
Characteristic N = 811
Age 55 (49, 63)
BMI 26.9 (22.8, 29.5)
Diabetes
    No 79 (98%)
    Yes 2 (2.5%)
Smoking
    No 75 (93%)
    Yes 6 (7.4%)
Type of Reconstruction
    DTI 43 (53%)
    TE 38 (47%)
Reconstruction Laterality
    Bilateral 50 (62%)
    Unilateral 31 (38%)
Radiation Side
    Left 42 (52%)
    Right 39 (48%)
Total Dose of Radiation 60 (50, 64)
Total Rounds of Radiaton 30.0 (25.0, 32.0)
Type of Radiation
    Photon 71 (88%)
    Proton 10 (12%)
Seroma
    No 72 (89%)
    Yes 9 (11%)
Hematoma
    No 80 (99%)
    Yes 1 (1.2%)
MSFN
    No 76 (94%)
    Yes 5 (6.2%)
Minor Infection
    No 73 (90%)
    Yes 8 (9.9%)
Major Infection
    No 74 (91%)
    Yes 7 (8.6%)
Any-Cause Reconstruction Failure
    No 63 (78%)
    Yes 18 (22%)
Infection-Specific Reconstruction Failure
    No 74 (91%)
    Yes 7 (8.6%)
1 Median (IQR); n (%)
# Stratified Table
table_1b <- df %>%
  select(age, bmi, diabetes, smoking, recon_type, recon_laterality, xrt_side, xrt_dose, xrt_rounds, xrt_type, 
         seroma, hematoma, msfn, infxn_minor, infxn_major, fail_any, fail_infxn) %>%
  tbl_summary(by = xrt_type,
              type = all_dichotomous() ~ "categorical") %>%
  add_p() %>%
  bold_p() %>%
  as_gt() %>%
  tab_header(title = md("Table 1b: Stratified Descriptive Statistics")) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden",
              table.border.bottom.style = "hidden",
              heading.title.font.size = "medium")
table_1b
Table 1b: Stratified Descriptive Statistics
Characteristic Photon, N = 711 Proton, N = 101 p-value2
Age 55 (50, 63) 53 (40, 63) 0.6
BMI 27.1 (22.9, 30.1) 25.4 (23.2, 27.3) 0.4
Diabetes

>0.9
    No 69 (97%) 10 (100%)
    Yes 2 (2.8%) 0 (0%)
Smoking

>0.9
    No 65 (92%) 10 (100%)
    Yes 6 (8.5%) 0 (0%)
Type of Reconstruction

>0.9
    DTI 38 (54%) 5 (50%)
    TE 33 (46%) 5 (50%)
Reconstruction Laterality

0.7
    Bilateral 43 (61%) 7 (70%)
    Unilateral 28 (39%) 3 (30%)
Radiation Side

0.015
    Left 33 (46%) 9 (90%)
    Right 38 (54%) 1 (10%)
Total Dose of Radiation 60 (51, 64) 50 (50, 50) 0.009
Total Rounds of Radiaton 30.0 (25.0, 32.0) 25.0 (25.0, 25.0) 0.018
Seroma

0.077
    No 65 (92%) 7 (70%)
    Yes 6 (8.5%) 3 (30%)
Hematoma

>0.9
    No 70 (99%) 10 (100%)
    Yes 1 (1.4%) 0 (0%)
MSFN

>0.9
    No 66 (93%) 10 (100%)
    Yes 5 (7.0%) 0 (0%)
Minor Infection

>0.9
    No 64 (90%) 9 (90%)
    Yes 7 (9.9%) 1 (10%)
Major Infection

0.2
    No 66 (93%) 8 (80%)
    Yes 5 (7.0%) 2 (20%)
Any-Cause Reconstruction Failure

0.2
    No 57 (80%) 6 (60%)
    Yes 14 (20%) 4 (40%)
Infection-Specific Reconstruction Failure

0.2
    No 66 (93%) 8 (80%)
    Yes 5 (7.0%) 2 (20%)
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Fisher’s exact test

\(~\)


\(~\)

Data Visualization

Simple histograms to visualize distributions.

# Histogram for Continuous Variables
ggplot(df, aes(x = age)) +
  geom_histogram(bins = 30, fill = "cyan", color = "black") +
  theme_minimal() +
  labs(title = "Age Distribution", x = "Age", y = "Frequency")

ggplot(df, aes(x = bmi)) +
  geom_histogram(bins = 30, fill = "green", color = "black") +
  theme_minimal() +
  labs(title = "BMI Distribution", x = "BMI", y = "Frequency")

ggplot(df, aes(x = xrt_rounds)) +
  geom_histogram(bins = 30, fill = "yellow", color = "black") +
  theme_minimal() +
  labs(title = "Total Rounds Distribution", x = "Rounds", y = "Frequency")

ggplot(df, aes(x = xrt_dose)) +
  geom_histogram(bins = 30, fill = "orange", color = "black") +
  theme_minimal() +
  labs(title = "Total Dose Distribution", x = "Dose", y = "Frequency")

\(~\)


\(~\)

Bivariate Analyses

Perform bivariate analyses to see the unadjusted relationship between each predictor and the outcomes.

\(~\)

Chi-Square
# Define categorical variables and outcome variables
categorical_variables <- c("diabetes", "smoking", "recon_type", "recon_laterality", "xrt_side", "xrt_type")
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")

# Initialize a list to store results
results_chi <- list()

# Loop through each outcome and categorical variable
for (outcome in outcome_variables) {
  p_values_chi <- numeric(length(categorical_variables))
  
  for (i in seq_along(categorical_variables)) {
    test_result_chi <- chisq.test(table(df[[categorical_variables[i]]], df[[outcome]]))
    p_values_chi[i] <- ifelse(is.na(test_result_chi$p.value), NA, test_result_chi$p.value)
  }
  
  # Store the results for each outcome in the list
  results_chi[[outcome]] <- data.frame(Variable = categorical_variables, P_Value = p_values_chi)
}

# Combine the results into a single data frame
combined_results_chi <- bind_rows(results_chi, .id = "Outcome") %>%
  pivot_wider(names_from = Outcome, values_from = P_Value)

# Replace variable names with their labels
combined_results_chi$Variable <- sapply(combined_results_chi$Variable, function(v) {
  label(df[[v]]) %||% v})
colnames(combined_results_chi)[-1] <- sapply(colnames(combined_results_chi)[-1], function(v) {
  label(df[[v]]) %||% v})

# Create a gt table with variable labels
gt_table_chi <- gt(combined_results_chi) %>%
  tab_header(title = "P-Values for Chi-Square Tests") %>%
  cols_label(Variable = "") %>%
  fmt_number(columns = c(-Variable), decimals = 3) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden",
              table.border.bottom.style = "hidden")

# Print the gt table
gt_table_chi
P-Values for Chi-Square Tests
Seroma Hematoma MSFN Minor Infection Major Infection Any-Cause Reconstruction Failure Infection-Specific Reconstruction Failure
Diabetes 1.000 1.000 0.000 0.468 1.000 0.069 1.000
Smoking 1.000 1.000 1.000 1.000 1.000 0.234 1.000
Type of Reconstruction 0.365 1.000 0.434 0.577 0.864 1.000 0.864
Reconstruction Laterality 0.443 1.000 0.132 1.000 0.884 0.831 0.884
Radiation Side 0.555 0.970 0.402 0.793 0.491 0.533 0.491
Type of Radiation 0.136 1.000 0.869 1.000 0.445 0.299 0.445

\(~\)

T-test
# t-tests for continuous variables
continuous_variables <- c("age", "bmi", "xrt_dose", "xrt_rounds")

# Initialize a list to store results
results_ttest <- list()

# Define a minimum number of observations required per group
min_obs <- 5

# Loop through each outcome and continuous variable
for (outcome in outcome_variables) {
  p_values_ttest <- numeric(length(continuous_variables))
  
  for (i in seq_along(continuous_variables)) {
    if(all(table(df[[outcome]]) >= min_obs)) {
      test_result_ttest <- t.test(reformulate(outcome, response = continuous_variables[i]), data = df)
      p_values_ttest[i] <- test_result_ttest$p.value
    } else {
      p_values_ttest[i] <- NA  # Not enough data to perform the test
    }
  }
  
  # Store the results for each outcome in the list
  results_ttest[[outcome]] <- data.frame(Variable = continuous_variables, P_Value = p_values_ttest)
}

# Combine the results into a single data frame
combined_results_ttest <- bind_rows(results_ttest, .id = "Outcome") %>%
  pivot_wider(names_from = Outcome, values_from = P_Value)

# Replace variable names with their labels
combined_results_ttest$Variable <- sapply(combined_results_ttest$Variable, function(v) {
  label(df[[v]]) %||% v })
colnames(combined_results_ttest)[-1] <- sapply(colnames(combined_results_ttest)[-1], function(v) {
  label(df[[v]]) %||% v })

# Create a gt table with variable labels
gt_table_ttest <- gt(combined_results_ttest) %>%
  tab_header(title = "P-Values for T-Tests") %>%
  cols_label(Variable = "") %>%
  fmt_number(columns = c(-Variable), decimals = 3) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden",
              table.border.bottom.style = "hidden")
# Print the gt table
gt_table_ttest
P-Values for T-Tests
Seroma Hematoma MSFN Minor Infection Major Infection Any-Cause Reconstruction Failure Infection-Specific Reconstruction Failure
Age 0.810 NA 0.317 0.216 0.915 0.670 0.511
BMI 0.530 NA 0.103 0.846 0.277 0.386 0.745
Total Dose of Radiation 0.081 NA 0.842 0.222 0.410 0.384 0.274
Total Rounds of Radiaton 0.108 NA 0.748 0.179 0.846 0.796 0.720

\(~\)


\(~\)

Multicolinearity Assessments

Assessment of multicolinearity for each outcome variable.

# Fit a model for the outcome 'seroma'
model_seroma <- glm(seroma ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_seroma <- vif(model_seroma)

# Create a data frame with VIF values
vif_df_seroma <- data.frame(
  Variable = names(vif_values_seroma),
  VIF = vif_values_seroma,
  HighVIF =ifelse(vif_values_seroma >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_seroma$Variable <- sapply(vif_df_seroma$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_seroma <- gt(vif_df_seroma) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Seroma") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_seroma
Variance Inflation Factor (VIF) for Seroma
Coefficient VIF High Multicollinearity
Age 1.27
BMI 1.43
Diabetes 1.00
Smoking 1.65
Type of Reconstruction 1.23
Reconstruction Laterality 1.25
Radiation Side 1.45
Total Dose of Radiation 19.59 Yes
Total Rounds of Radiaton 21.16 Yes
Type of Radiation 1.71
# Fit a model for the outcome 'hematoma'
model_hematoma <- glm(hematoma ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_hematoma <- vif(model_hematoma)

# Create a data frame with VIF values
vif_df_hematoma <- data.frame(
  Variable = names(vif_values_hematoma),
  VIF = vif_values_hematoma,
  HighVIF =ifelse(vif_values_hematoma >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_hematoma$Variable <- sapply(vif_df_hematoma$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_hematoma <- gt(vif_df_hematoma) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Hematoma") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_hematoma
Variance Inflation Factor (VIF) for Hematoma
Coefficient VIF High Multicollinearity
Age 525.26 Yes
BMI 1,039.33 Yes
Diabetes 1.59
Smoking 1.10
Type of Reconstruction 51.62 Yes
Reconstruction Laterality 56.11 Yes
Radiation Side 11.14 Yes
Total Dose of Radiation 48.91 Yes
Total Rounds of Radiaton 438.21 Yes
Type of Radiation 26.65 Yes
# Fit a model for the outcome 'hematoma'
model_infxn_minor <- glm(infxn_minor ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_infxn_minor <- vif(model_infxn_minor)

# Create a data frame with VIF values
vif_df_infxn_minor <- data.frame(
  Variable = names(vif_values_infxn_minor),
  VIF = vif_values_infxn_minor,
  HighVIF =ifelse(vif_values_infxn_minor >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_infxn_minor$Variable <- sapply(vif_df_infxn_minor$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_infxn_minor <- gt(vif_df_infxn_minor) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Minor Infection") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_infxn_minor
Variance Inflation Factor (VIF) for Minor Infection
Coefficient VIF High Multicollinearity
Age 1.64
BMI 1.34
Diabetes 1.57
Smoking 1.43
Type of Reconstruction 1.29
Reconstruction Laterality 1.47
Radiation Side 1.45
Total Dose of Radiation 37.46 Yes
Total Rounds of Radiaton 38.33 Yes
Type of Radiation 1.61
# Fit a model for the outcome 'hematoma'
model_infxn_major <- glm(infxn_major ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_infxn_major <- vif(model_infxn_major)

# Create a data frame with VIF values
vif_df_infxn_major <- data.frame(
  Variable = names(vif_values_infxn_major),
  VIF = vif_values_infxn_major,
  HighVIF =ifelse(vif_values_infxn_major >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_infxn_major$Variable <- sapply(vif_df_infxn_major$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_infxn_major <- gt(vif_df_infxn_major) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Major Infection") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_infxn_major
Variance Inflation Factor (VIF) for Major Infection
Coefficient VIF High Multicollinearity
Age 1.32
BMI 1.34
Diabetes 1.00
Smoking 1.35
Type of Reconstruction 1.30
Reconstruction Laterality 1.22
Radiation Side 1.39
Total Dose of Radiation 5.76 Yes
Total Rounds of Radiaton 5.48 Yes
Type of Radiation 1.20
# Fit a model for the outcome 'hematoma'
model_fail_any <- glm(fail_any ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_fail_any<- vif(model_fail_any)

# Create a data frame with VIF values
vif_df_fail_any <- data.frame(
  Variable = names(vif_values_fail_any),
  VIF = vif_values_fail_any,
  HighVIF =ifelse(vif_values_fail_any >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_fail_any$Variable <- sapply(vif_df_fail_any$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_fail_any <- gt(vif_df_fail_any) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Any-Cause Reconstruction Failure") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_fail_any
Variance Inflation Factor (VIF) for Any-Cause Reconstruction Failure
Coefficient VIF High Multicollinearity
Age 1.20
BMI 1.35
Diabetes 1.00
Smoking 1.31
Type of Reconstruction 1.24
Reconstruction Laterality 1.21
Radiation Side 1.29
Total Dose of Radiation 4.82
Total Rounds of Radiaton 4.98
Type of Radiation 1.28
# Fit a model for the outcome 'hematoma'
model_fail_infxn <- glm(fail_infxn ~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type, data = df, family = binomial())

# Calculate VIF
vif_values_fail_infxn<- vif(model_fail_infxn)

# Create a data frame with VIF values
vif_df_fail_infxn <- data.frame(
  Variable = names(vif_values_fail_infxn),
  VIF = vif_values_fail_infxn,
  HighVIF =ifelse(vif_values_fail_infxn >= 5, "Yes", "")
)

# Replace variable names in 'Variable' column with their labels
vif_df_fail_infxn$Variable <- sapply(vif_df_fail_infxn$Variable, function(v) {
  label(df[[v]]) %||% v  # Use the label if it exists, otherwise use the variable name
})

# Create a gt table with VIF values
gt_table_fail_infxn <- gt(vif_df_fail_infxn) %>%
  tab_header(title = "Variance Inflation Factor (VIF) for Infection-Specific Reconstruction Failure") %>%
  cols_label(Variable = "Coefficient", VIF = "VIF", HighVIF = "High Multicollinearity") %>%
  fmt_number(columns = VIF, decimals = 2) %>%
  opt_align_table_header(align = "left") %>%
  tab_options(table.border.top.style = "hidden", table.border.bottom.style = "hidden")

# Print the gt table
gt_table_fail_infxn
Variance Inflation Factor (VIF) for Infection-Specific Reconstruction Failure
Coefficient VIF High Multicollinearity
Age 1.45
BMI 1.50
Diabetes 1.00
Smoking 1.69
Type of Reconstruction 1.46
Reconstruction Laterality 1.31
Radiation Side 1.50
Total Dose of Radiation 7.09 Yes
Total Rounds of Radiaton 7.19 Yes
Type of Radiation 1.28

\(~\)


\(~\)

Logistic Regression

Sample models for each outcome variable with varying number of covariates.

Model 1

Includes age, BMI, diabetes, smoking, reconstruction type, laterality, radiation side, radiation dose, radiation rounds, and radiation type

# Make new df_model dataframe where outcome variables are coded as 0 / 1 
df_model <- df
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")
for(var in outcome_variables) {
  df_model[[var]] <- ifelse(df_model[[var]] == "Yes", 1, 0)
}

# Initialize a list to store tables
tables_list1 <- list()

# Function to create a title with variable labels
create_title <- function(var) {
  label_text <- label(df[[var]])
  paste("<div style='text-align: left; font-weight: bold; color: grey'> Table 3. Multivariate Statistics for", label_text, "</div>")
}

# Loop to create models and tables
for (var in outcome_variables) {
  # Create model
  model_formula <- as.formula(paste(var, "~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_dose + xrt_rounds + xrt_type"))
  model_name <- paste("m", var, sep = "_")
  assign(model_name, glm(model_formula, data = df_model, family = binomial(link = "logit")))

  # Create table with labeled title
  table_name <- paste("table1", var, sep = "_")
  table <- tbl_regression(get(model_name), exponentiate = TRUE) %>%
    add_global_p() %>%
    modify_caption(create_title(var)) %>%
    as_gt() %>%
    gt::tab_header("Model 1")

  # Store the table in the list
  tables_list1[[table_name]] <- table
}

m1_seroma <- tables_list1$table1_seroma
m1_hematoma <- tables_list1$table1_hematoma
m1_msfn <- tables_list1$table1_msfn
m1_minor <- tables_list1$table1_infxn_minor
m1_major <- tables_list1$table1_infxn_major
m1_fail_any <- tables_list1$table1_fail_any
m1_fail_infxn <- tables_list1$table1_fail_infxn

# Print all tables
m1_seroma
Table 3. Multivariate Statistics for Seroma
Model 1
Characteristic OR1 95% CI1 p-value
Age 1.00 0.93, 1.08 >0.9
BMI 1.08 0.93, 1.23 0.3
Diabetes

0.5
    No — —
    Yes 0.00

Smoking

0.14
    No — —
    Yes 11.4 0.36, 295
Type of Reconstruction

0.2
    DTI — —
    TE 3.29 0.54, 26.7
Reconstruction Laterality

0.10
    Bilateral — —
    Unilateral 4.29 0.74, 31.8
Radiation Side

0.5
    Left — —
    Right 0.52 0.06, 3.99
Total Dose of Radiation 0.93 0.73, 1.33 0.7
Total Rounds of Radiaton 0.95 0.57, 1.28 0.8
Type of Radiation

0.075
    Photon — —
    Proton 7.58 0.81, 107
1 OR = Odds Ratio, CI = Confidence Interval
m1_hematoma 
Table 3. Multivariate Statistics for Hematoma
Model 1
Characteristic OR1 95% CI1 p-value
Age 0.00 0.00, 11,321,943,280,277,891,182,536,295,405,167,251,076,604,521,177,000,159,022,781,590,878,936,560,638,313,585,667,457,805,002,346,923,106,323,644,832,854,252,665,397,768,343,900,454,151,340,666,863,134,862,723,375,453,285,730,843,047,580,783,332,767,306,355,135,912,778,352,798,244,883,752,221,623,545,583,632,384 0.009
BMI 763,020,919,100,322,480,128 0.00, Inf 0.018
Diabetes

>0.9
    No — —
    Yes Inf 0.00, Inf
Smoking

>0.9
    No — —
    Yes 345,824,594,467,641,500,722,553,563,074,054,765,990,592,161,119,700,441,552,830,269,264,160,571,258,158,391,036,496,465,050,206,638,911,547,745,717,731,397,920,293,878,162,517,198,835,392,249,331,712 0.00, Inf
Type of Reconstruction

>0.9
    DTI — —
    TE 0.00 0.00, Inf
Reconstruction Laterality

0.026
    Bilateral — —
    Unilateral 0.00 0.00, Inf
Radiation Side

0.011
    Left — —
    Right 184,980,745,999,421,216,275,465,106,763,029,657,547,962,286,111,409,961,246,738,371,334,380,241,283,932,183,585,170,113,161,987,267,381,751,281,765,086,908,709,705,762,242,861,954,400,751,696,536,928,256 0.00, Inf
Total Dose of Radiation 18,336,506,379,421,108 0.00, Inf 0.033
Total Rounds of Radiaton 1,625,409,369,669,316,378,624 0.00, Inf 0.016
Type of Radiation

>0.9
    Photon — —
    Proton Inf 0.00, Inf
1 OR = Odds Ratio, CI = Confidence Interval
m1_msfn
Table 3. Multivariate Statistics for MSFN
Model 1
Characteristic OR1 95% CI1 p-value
Age 0.93 0.66, 1.22 0.6
BMI 1.54 1.00, 4.25 0.050
Diabetes

0.002
    No — —
    Yes 221,696,305,144,573,020,078,080 0.00, NA
Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.7
    DTI — —
    TE 0.52 0.01, 12.6
Reconstruction Laterality

0.2
    Bilateral — —
    Unilateral 51.0 0.32, 6,810,658
Radiation Side

0.008
    Left — —
    Right 0.00

Total Dose of Radiation 1.04 0.74, 2.22 0.9
Total Rounds of Radiaton 1.06 0.37, 1.98 0.9
Type of Radiation

0.7
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m1_minor 
Table 3. Multivariate Statistics for Minor Infection
Model 1
Characteristic OR1 95% CI1 p-value
Age 1.04 0.96, 1.15 0.3
BMI 0.97 0.81, 1.10 0.7
Diabetes

0.10
    No — —
    Yes 24.4 0.52, 1,389
Smoking

0.3
    No — —
    Yes 4.75 0.17, 76.1
Type of Reconstruction

0.2
    DTI — —
    TE 3.16 0.56, 26.2
Reconstruction Laterality

0.4
    Bilateral — —
    Unilateral 0.45 0.05, 2.83
Radiation Side

0.2
    Left — —
    Right 0.31 0.04, 1.97
Total Dose of Radiation 1.10 0.83, 1.72 0.6
Total Rounds of Radiaton 0.83 0.46, 1.20 0.5
Type of Radiation

>0.9
    Photon — —
    Proton 1.20 0.04, 19.7
1 OR = Odds Ratio, CI = Confidence Interval
m1_major
Table 3. Multivariate Statistics for Major Infection
Model 1
Characteristic OR1 95% CI1 p-value
Age 1.02 0.94, 1.10 0.7
BMI 0.92 0.72, 1.11 0.4
Diabetes

0.8
    No — —
    Yes 0.00

Smoking

0.4
    No — —
    Yes 3.73 0.12, 69.5
Type of Reconstruction

0.4
    DTI — —
    TE 2.32 0.36, 19.8
Reconstruction Laterality

0.4
    Bilateral — —
    Unilateral 0.41 0.04, 2.77
Radiation Side

0.2
    Left — —
    Right 0.28 0.02, 2.15
Total Dose of Radiation 0.83 0.68, 0.99 0.036
Total Rounds of Radiaton 1.20 0.97, 1.47 0.085
Type of Radiation

0.7
    Photon — —
    Proton 1.61 0.17, 12.4
1 OR = Odds Ratio, CI = Confidence Interval
m1_fail_any 
Table 3. Multivariate Statistics for Any-Cause Reconstruction Failure
Model 1
Characteristic OR1 95% CI1 p-value
Age 1.02 0.96, 1.08 0.6
BMI 1.06 0.95, 1.17 0.3
Diabetes

0.005
    No — —
    Yes 190,225,829 0.00, NA
Smoking

0.023
    No — —
    Yes 10.9 1.40, 96.4
Type of Reconstruction

0.5
    DTI — —
    TE 1.65 0.44, 6.69
Reconstruction Laterality

0.2
    Bilateral — —
    Unilateral 0.39 0.08, 1.58
Radiation Side

0.4
    Left — —
    Right 0.58 0.14, 2.31
Total Dose of Radiation 0.90 0.78, 1.03 0.12
Total Rounds of Radiaton 1.14 0.96, 1.36 0.12
Type of Radiation

0.2
    Photon — —
    Proton 3.05 0.56, 16.4
1 OR = Odds Ratio, CI = Confidence Interval
m1_fail_infxn
Table 3. Multivariate Statistics for Infection-Specific Reconstruction Failure
Model 1
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.14 0.3
BMI 1.02 0.81, 1.22 0.9
Diabetes

0.8
    No — —
    Yes 0.00

Smoking

0.2
    No — —
    Yes 10.2 0.28, 322
Type of Reconstruction

0.2
    DTI — —
    TE 3.64 0.51, 40.4
Reconstruction Laterality

0.3
    Bilateral — —
    Unilateral 0.34 0.03, 2.52
Radiation Side

0.2
    Left — —
    Right 0.21 0.02, 1.83
Total Dose of Radiation 0.79 0.63, 0.95 0.014
Total Rounds of Radiaton 1.26 1.02, 1.61 0.035
Type of Radiation

0.5
    Photon — —
    Proton 2.13 0.21, 19.0
1 OR = Odds Ratio, CI = Confidence Interval

Model 2

Includes age, BMI, diabetes, smoking, reconstruction type, laterality, radiation side, radiation type

# Make new df_model dataframe where outcome variables are coded as 0 / 1 
df_model <- df
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")
for(var in outcome_variables) {
  df_model[[var]] <- ifelse(df_model[[var]] == "Yes", 1, 0)
}

# Initialize a list to store tables
tables_list2 <- list()

# Function to create a title with variable labels
create_title <- function(var) {
  label_text <- label(df[[var]])
  paste("<div style='text-align: left; font-weight: bold; color: grey'> Table 3b. Multivariate Statistics for", label_text, "</div>")
}

# Loop to create models and tables
for (var in outcome_variables) {
  # Create model
  model_formula <- as.formula(paste(var, "~ age + bmi + diabetes + smoking + recon_type + recon_laterality + xrt_side + xrt_type"))
  model_name <- paste("m", var, sep = "_")
  assign(model_name, glm(model_formula, data = df_model, family = binomial(link = "logit")))

  # Create table with labeled title
  table_name <- paste("table2", var, sep = "_")
  table <- tbl_regression(get(model_name), exponentiate = TRUE) %>%
    add_global_p() %>%
    modify_caption(create_title(var)) %>%
    as_gt() %>%
    gt::tab_header("Model 2")

  # Store the table in the list
  tables_list2[[table_name]] <- table
}

m2_seroma <- tables_list2$table2_seroma
m2_hematoma <- tables_list2$table2_hematoma
m2_msfn <- tables_list2$table2_msfn
m2_minor <- tables_list2$table2_infxn_minor
m2_major <- tables_list2$table2_infxn_major
m2_fail_any <- tables_list2$table2_fail_any
m2_fail_infxn <- tables_list2$table2_fail_infxn

# Print all tables
m2_seroma
Table 3b. Multivariate Statistics for Seroma
Model 2
Characteristic OR1 95% CI1 p-value
Age 1.02 0.95, 1.09 0.6
BMI 1.09 0.96, 1.22 0.15
Diabetes

0.5
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 4.08 0.17, 50.2
Type of Reconstruction

0.2
    DTI — —
    TE 2.91 0.58, 19.0
Reconstruction Laterality

0.2
    Bilateral — —
    Unilateral 2.59 0.51, 14.9
Radiation Side

0.7
    Left — —
    Right 0.73 0.11, 4.47
Type of Radiation

0.052
    Photon — —
    Proton 7.08 0.98, 56.2
1 OR = Odds Ratio, CI = Confidence Interval
m2_hematoma 
Table 3b. Multivariate Statistics for Hematoma
Model 2
Characteristic OR1 95% CI1 p-value
Age 0.87 0.54, 1.10 0.3
BMI 1.06 0.62, 1.52 0.7
Diabetes

>0.9
    No — —
    Yes 14.1 0.00, Inf
Smoking

>0.9
    No — —
    Yes 0.53 0.00, Inf
Type of Reconstruction

0.3
    DTI — —
    TE 0.00 0.00, Inf
Reconstruction Laterality

0.5
    Bilateral — —
    Unilateral 0.00

Radiation Side

0.3
    Left — —
    Right 321,820,125 0.00, Inf
Type of Radiation

>0.9
    Photon — —
    Proton 0.16 0.00, Inf
1 OR = Odds Ratio, CI = Confidence Interval
m2_msfn
Table 3b. Multivariate Statistics for MSFN
Model 2
Characteristic OR1 95% CI1 p-value
Age 0.95 0.73, 1.22 0.7
BMI 1.38 0.96, 2.55 0.084
Diabetes

0.003
    No — —
    Yes 4,154,329,216,695,318,609,920 0.00, NA
Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.8
    DTI — —
    TE 0.68 0.02, 13.4
Reconstruction Laterality

0.2
    Bilateral — —
    Unilateral 16.1 0.31, 20,037
Radiation Side

0.013
    Left — —
    Right 0.00

Type of Radiation

0.6
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m2_minor 
Table 3b. Multivariate Statistics for Minor Infection
Model 2
Characteristic OR1 95% CI1 p-value
Age 1.05 0.97, 1.16 0.2
BMI 0.98 0.82, 1.11 0.8
Diabetes

0.082
    No — —
    Yes 27.9 0.62, 1,529
Smoking

0.4
    No — —
    Yes 3.62 0.14, 52.6
Type of Reconstruction

0.2
    DTI — —
    TE 3.28 0.60, 26.5
Reconstruction Laterality

0.3
    Bilateral — —
    Unilateral 0.38 0.04, 2.29
Radiation Side

0.3
    Left — —
    Right 0.34 0.04, 2.09
Type of Radiation

>0.9
    Photon — —
    Proton 0.89 0.04, 8.80
1 OR = Odds Ratio, CI = Confidence Interval
m2_major
Table 3b. Multivariate Statistics for Major Infection
Model 2
Characteristic OR1 95% CI1 p-value
Age 1.03 0.96, 1.11 0.5
BMI 0.93 0.75, 1.10 0.5
Diabetes

0.7
    No — —
    Yes 0.00

Smoking

0.5
    No — —
    Yes 2.70 0.11, 34.2
Type of Reconstruction

0.6
    DTI — —
    TE 1.63 0.30, 10.2
Reconstruction Laterality

0.4
    Bilateral — —
    Unilateral 0.42 0.05, 2.49
Radiation Side

0.3
    Left — —
    Right 0.39 0.04, 2.69
Type of Radiation

0.4
    Photon — —
    Proton 2.38 0.25, 18.0
1 OR = Odds Ratio, CI = Confidence Interval
m2_fail_any 
Table 3b. Multivariate Statistics for Any-Cause Reconstruction Failure
Model 2
Characteristic OR1 95% CI1 p-value
Age 1.02 0.96, 1.08 0.6
BMI 1.04 0.95, 1.15 0.4
Diabetes

0.006
    No — —
    Yes 148,464,318 0.00, NA
Smoking

0.027
    No — —
    Yes 9.67 1.32, 77.9
Type of Reconstruction

0.6
    DTI — —
    TE 1.42 0.41, 5.18
Reconstruction Laterality

0.2
    Bilateral — —
    Unilateral 0.40 0.09, 1.52
Radiation Side

0.5
    Left — —
    Right 0.64 0.16, 2.46
Type of Radiation

0.10
    Photon — —
    Proton 3.87 0.75, 19.8
1 OR = Odds Ratio, CI = Confidence Interval
m2_fail_infxn
Table 3b. Multivariate Statistics for Infection-Specific Reconstruction Failure
Model 2
Characteristic OR1 95% CI1 p-value
Age 1.05 0.98, 1.15 0.2
BMI 1.00 0.83, 1.14 >0.9
Diabetes

0.7
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 5.05 0.19, 75.3
Type of Reconstruction

0.5
    DTI — —
    TE 1.93 0.34, 13.1
Reconstruction Laterality

0.3
    Bilateral — —
    Unilateral 0.38 0.04, 2.44
Radiation Side

0.3
    Left — —
    Right 0.35 0.04, 2.55
Type of Radiation

0.4
    Photon — —
    Proton 2.62 0.25, 21.9
1 OR = Odds Ratio, CI = Confidence Interval

Model 3

Includes age, BMI, diabetes, smoking, reconstruction type, radiation side, and radiation type

# Make new df_model dataframe where outcome variables are coded as 0 / 1 
df_model <- df
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")
for(var in outcome_variables) {
  df_model[[var]] <- ifelse(df_model[[var]] == "Yes", 1, 0)
}

# Initialize a list to store tables
tables_list3 <- list()

# Function to create a title with variable labels
create_title <- function(var) {
  label_text <- label(df[[var]])
  paste("<div style='text-align: left; font-weight: bold; color: grey'> Table 3. Multivariate Statistics for", label_text, "</div>")
}

# Loop to create models and tables
for (var in outcome_variables) {
  # Create model
  model_formula <- as.formula(paste(var, "~ age + bmi + diabetes + smoking + recon_type + xrt_side + xrt_type"))
  model_name <- paste("m", var, sep = "_")
  assign(model_name, glm(model_formula, data = df_model, family = binomial(link = "logit")))

  # Create table with labeled title
  table_name <- paste("table3", var, sep = "_")
  table <- tbl_regression(get(model_name), exponentiate = TRUE) %>%
    add_global_p() %>%
    modify_caption(create_title(var)) %>%
    as_gt() %>%
    gt::tab_header("Model 3")

  # Store the table in the list
  tables_list3[[table_name]] <- table
}

m3_seroma <- tables_list3$table3_seroma
m3_hematoma <- tables_list3$table3_hematoma
m3_msfn <- tables_list3$table3_msfn
m3_minor <- tables_list3$table3_infxn_minor
m3_major <- tables_list3$table3_infxn_major
m3_fail_any <- tables_list3$table3_fail_any
m3_fail_infxn <- tables_list3$table3_fail_infxn

# Print all tables
m3_seroma
Table 3. Multivariate Statistics for Seroma
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.02 0.96, 1.09 0.5
BMI 1.08 0.96, 1.21 0.2
Diabetes

0.6
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 4.43 0.18, 53.8
Type of Reconstruction

0.12
    DTI — —
    TE 3.59 0.74, 23.4
Radiation Side

0.5
    Left — —
    Right 0.56 0.09, 3.06
Type of Radiation

0.067
    Photon — —
    Proton 5.95 0.88, 41.2
1 OR = Odds Ratio, CI = Confidence Interval
m3_hematoma 
Table 3. Multivariate Statistics for Hematoma
Model 3
Characteristic OR1 95% CI1 p-value
Age 0.85 0.52, 1.10 0.2
BMI 1.08 0.65, 1.56 0.6
Diabetes

>0.9
    No — —
    Yes 0.00

Smoking

>0.9
    No — —
    Yes 0.35 0.00, Inf
Type of Reconstruction

0.2
    DTI — —
    TE 0.00 0.00, Inf
Radiation Side

0.3
    Left — —
    Right 331,519,241 0.00, Inf
Type of Radiation

>0.9
    Photon — —
    Proton 0.27 0.00, Inf
1 OR = Odds Ratio, CI = Confidence Interval
m3_msfn
Table 3. Multivariate Statistics for MSFN
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.03 0.87, 1.28 0.7
BMI 1.18 0.91, 1.63 0.2
Diabetes

0.003
    No — —
    Yes 11,262,384,710,665,029,632 0.00, NA
Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.7
    DTI — —
    TE 0.62 0.02, 10.6
Radiation Side

0.013
    Left — —
    Right 0.00

Type of Radiation

0.3
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m3_minor 
Table 3. Multivariate Statistics for Minor Infection
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.13 0.3
BMI 0.99 0.83, 1.12 0.9
Diabetes

0.13
    No — —
    Yes 14.8 0.40, 612
Smoking

0.4
    No — —
    Yes 3.25 0.13, 41.3
Type of Reconstruction

0.2
    DTI — —
    TE 3.13 0.59, 24.3
Radiation Side

0.4
    Left — —
    Right 0.49 0.08, 2.56
Type of Radiation

>0.9
    Photon — —
    Proton 0.95 0.04, 9.17
1 OR = Odds Ratio, CI = Confidence Interval
m3_major
Table 3. Multivariate Statistics for Major Infection
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.02 0.95, 1.10 0.6
BMI 0.94 0.76, 1.10 0.5
Diabetes

0.7
    No — —
    Yes 0.00

Smoking

0.5
    No — —
    Yes 2.51 0.10, 29.1
Type of Reconstruction

0.6
    DTI — —
    TE 1.48 0.28, 8.72
Radiation Side

0.5
    Left — —
    Right 0.51 0.06, 3.21
Type of Radiation

0.4
    Photon — —
    Proton 2.62 0.28, 19.6
1 OR = Odds Ratio, CI = Confidence Interval
m3_fail_any 
Table 3. Multivariate Statistics for Any-Cause Reconstruction Failure
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.01 0.96, 1.07 0.7
BMI 1.05 0.96, 1.16 0.3
Diabetes

0.013
    No — —
    Yes 77,638,774 0.00, NA
Smoking

0.034
    No — —
    Yes 8.27 1.19, 60.7
Type of Reconstruction

0.7
    DTI — —
    TE 1.28 0.38, 4.41
Radiation Side

0.7
    Left — —
    Right 0.79 0.21, 2.92
Type of Radiation

0.076
    Photon — —
    Proton 4.31 0.85, 21.6
1 OR = Odds Ratio, CI = Confidence Interval
m3_fail_infxn
Table 3. Multivariate Statistics for Infection-Specific Reconstruction Failure
Model 3
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.13 0.3
BMI 1.01 0.84, 1.15 0.9
Diabetes

0.6
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 4.46 0.18, 58.6
Type of Reconstruction

0.5
    DTI — —
    TE 1.71 0.32, 10.6
Radiation Side

0.5
    Left — —
    Right 0.49 0.06, 3.16
Type of Radiation

0.3
    Photon — —
    Proton 3.02 0.31, 24.4
1 OR = Odds Ratio, CI = Confidence Interval

Model 4

Includes age, BMI, diabetes, smoking, reconstruction type, and radiation type

# Make new df_model dataframe where outcome variables are coded as 0 / 1 
df_model <- df
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")
for(var in outcome_variables) {
  df_model[[var]] <- ifelse(df_model[[var]] == "Yes", 1, 0)
}

# Initialize a list to store tables
tables_list4 <- list()

# Function to create a title with variable labels
create_title <- function(var) {
  label_text <- label(df[[var]])
  paste("<div style='text-align: left; font-weight: bold; color: grey'> Table 3b. Multivariate Statistics for", label_text, "</div>")
}

# Loop to create models and tables
for (var in outcome_variables) {
  # Create model
  model_formula <- as.formula(paste(var, "~ age + bmi + diabetes + smoking + recon_type + xrt_type"))
  model_name <- paste("m", var, sep = "_")
  assign(model_name, glm(model_formula, data = df_model, family = binomial(link = "logit")))

  # Create table with labeled title
  table_name <- paste("table4", var, sep = "_")
  table <- tbl_regression(get(model_name), exponentiate = TRUE) %>%
    add_global_p() %>%
    modify_caption(create_title(var)) %>%
    as_gt() %>%
    gt::tab_header("Multivariate Models")

  # Store the table in the list
  tables_list4[[table_name]] <- table
}

m4_seroma <- tables_list4$table4_seroma
m4_hematoma <- tables_list4$table4_hematoma
m4_msfn <- tables_list4$table4_msfn
m4_minor <- tables_list4$table4_infxn_minor
m4_major <- tables_list4$table4_infxn_major
m4_fail_any <- tables_list4$table4_fail_any
m4_fail_infxn <- tables_list4$table4_fail_infxn

# Print all tables
m4_seroma
Table 3b. Multivariate Statistics for Seroma
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.02 0.96, 1.09 0.5
BMI 1.07 0.95, 1.19 0.2
Diabetes

0.6
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 4.41 0.18, 52.7
Type of Reconstruction

0.14
    DTI — —
    TE 3.19 0.69, 19.6
Type of Radiation

0.037
    Photon — —
    Proton 7.22 1.14, 46.3
1 OR = Odds Ratio, CI = Confidence Interval
m4_hematoma 
Table 3b. Multivariate Statistics for Hematoma
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 0.86 0.58, 1.10 0.2
BMI 1.06 0.69, 1.47 0.7
Diabetes

0.9
    No — —
    Yes 0.00

Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.3
    DTI — —
    TE 0.00

Type of Radiation

0.7
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m4_msfn
Table 3b. Multivariate Statistics for MSFN
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.01 0.88, 1.16 >0.9
BMI 1.05 0.90, 1.19 0.5
Diabetes

0.007
    No — —
    Yes 4,242,160,977 0.00, NA
Smoking

0.5
    No — —
    Yes 0.00

Type of Reconstruction

0.7
    DTI — —
    TE 0.62 0.03, 7.94
Type of Radiation

0.4
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m4_minor 
Table 3b. Multivariate Statistics for Minor Infection
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.12 0.3
BMI 0.99 0.84, 1.12 >0.9
Diabetes

0.14
    No — —
    Yes 14.3 0.38, 594
Smoking

0.4
    No — —
    Yes 3.36 0.14, 41.1
Type of Reconstruction

0.2
    DTI — —
    TE 2.87 0.56, 21.6
Type of Radiation

0.8
    Photon — —
    Proton 1.34 0.06, 11.1
1 OR = Odds Ratio, CI = Confidence Interval
m4_major
Table 3b. Multivariate Statistics for Major Infection
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.02 0.95, 1.09 0.6
BMI 0.94 0.76, 1.09 0.5
Diabetes

0.6
    No — —
    Yes 0.00

Smoking

0.5
    No — —
    Yes 2.81 0.12, 31.4
Type of Reconstruction

0.7
    DTI — —
    TE 1.36 0.27, 7.72
Type of Radiation

0.2
    Photon — —
    Proton 3.49 0.42, 22.3
1 OR = Odds Ratio, CI = Confidence Interval
m4_fail_any 
Table 3b. Multivariate Statistics for Any-Cause Reconstruction Failure
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.01 0.96, 1.07 0.7
BMI 1.05 0.95, 1.15 0.3
Diabetes

0.013
    No — —
    Yes 74,666,311 0.00, NA
Smoking

0.030
    No — —
    Yes 8.62 1.25, 62.7
Type of Reconstruction

0.7
    DTI — —
    TE 1.23 0.37, 4.13
Type of Radiation

0.049
    Photon — —
    Proton 4.76 1.01, 21.7
1 OR = Odds Ratio, CI = Confidence Interval
m4_fail_infxn
Table 3b. Multivariate Statistics for Infection-Specific Reconstruction Failure
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.13 0.2
BMI 1.01 0.84, 1.13 >0.9
Diabetes

0.6
    No — —
    Yes 0.00

Smoking

0.3
    No — —
    Yes 4.76 0.19, 59.9
Type of Reconstruction

0.6
    DTI — —
    TE 1.53 0.29, 9.02
Type of Radiation

0.2
    Photon — —
    Proton 4.07 0.47, 28.4
1 OR = Odds Ratio, CI = Confidence Interval

Model 5

Includes age, BMI, smoking, reconstruction type, and radiation type

# Make new df_model dataframe where outcome variables are coded as 0 / 1 
df_model <- df
outcome_variables <- c("seroma", "hematoma", "msfn", "infxn_minor", "infxn_major", "fail_any", "fail_infxn")
for(var in outcome_variables) {
  df_model[[var]] <- ifelse(df_model[[var]] == "Yes", 1, 0)
}

# Initialize a list to store tables
tables_list5 <- list()

# Function to create a title with variable labels
create_title <- function(var) {
  label_text <- label(df[[var]])
  paste("<div style='text-align: left; font-weight: bold; color: grey'> Table 3b. Multivariate Statistics for", label_text, "</div>")
}

# Loop to create models and tables
for (var in outcome_variables) {
  # Create model
  model_formula <- as.formula(paste(var, "~ age + bmi + smoking + recon_type + xrt_type"))
  model_name <- paste("m", var, sep = "_")
  assign(model_name, glm(model_formula, data = df_model, family = binomial(link = "logit")))

  # Create table with labeled title
  table_name <- paste("table5", var, sep = "_")
  table <- tbl_regression(get(model_name), exponentiate = TRUE) %>%
    add_global_p() %>%
    modify_caption(create_title(var)) %>%
    as_gt() %>%
    gt::tab_header("Multivariate Models")

  # Store the table in the list
  tables_list5[[table_name]] <- table
}

m5_seroma <- tables_list5$table5_seroma
m5_hematoma <- tables_list5$table5_hematoma
m5_msfn <- tables_list5$table5_msfn
m5_minor <- tables_list5$table5_infxn_minor
m5_major <- tables_list5$table5_infxn_major
m5_fail_any <- tables_list5$table5_fail_any
m5_fail_infxn <- tables_list5$table5_fail_infxn

# Print all tables
m5_seroma
Table 3b. Multivariate Statistics for Seroma
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.02 0.96, 1.09 0.5
BMI 1.07 0.95, 1.19 0.2
Smoking

0.3
    No — —
    Yes 4.49 0.18, 54.3
Type of Reconstruction

0.12
    DTI — —
    TE 3.37 0.72, 20.7
Type of Radiation

0.034
    Photon — —
    Proton 7.44 1.17, 48.0
1 OR = Odds Ratio, CI = Confidence Interval
m5_hematoma 
Table 3b. Multivariate Statistics for Hematoma
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 0.86 0.58, 1.09 0.2
BMI 1.06 0.68, 1.47 0.8
Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.3
    DTI — —
    TE 0.00

Type of Radiation

0.7
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m5_msfn
Table 3b. Multivariate Statistics for MSFN
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.08 0.98, 1.22 0.14
BMI 1.04 0.93, 1.17 0.4
Smoking

0.6
    No — —
    Yes 0.00

Type of Reconstruction

0.2
    DTI — —
    TE 0.24 0.01, 1.93
Type of Radiation

0.2
    Photon — —
    Proton 0.00

1 OR = Odds Ratio, CI = Confidence Interval
m5_minor 
Table 3b. Multivariate Statistics for Minor Infection
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.05 0.98, 1.14 0.2
BMI 1.00 0.85, 1.12 >0.9
Smoking

0.4
    No — —
    Yes 3.42 0.14, 39.8
Type of Reconstruction

0.4
    DTI — —
    TE 2.00 0.44, 10.8
Type of Radiation

>0.9
    Photon — —
    Proton 1.12 0.05, 8.89
1 OR = Odds Ratio, CI = Confidence Interval
m5_major
Table 3b. Multivariate Statistics for Major Infection
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.02 0.95, 1.09 0.6
BMI 0.94 0.76, 1.09 0.5
Smoking

0.5
    No — —
    Yes 2.82 0.12, 31.7
Type of Reconstruction

0.7
    DTI — —
    TE 1.42 0.27, 8.02
Type of Radiation

0.2
    Photon — —
    Proton 3.58 0.43, 22.9
1 OR = Odds Ratio, CI = Confidence Interval
m5_fail_any 
Table 3b. Multivariate Statistics for Any-Cause Reconstruction Failure
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.03 0.98, 1.08 0.3
BMI 1.05 0.96, 1.16 0.2
Smoking

0.030
    No — —
    Yes 8.48 1.24, 61.6
Type of Reconstruction

>0.9
    DTI — —
    TE 0.97 0.31, 3.03
Type of Radiation

0.068
    Photon — —
    Proton 4.18 0.89, 19.0
1 OR = Odds Ratio, CI = Confidence Interval
m5_fail_infxn
Table 3b. Multivariate Statistics for Infection-Specific Reconstruction Failure
Multivariate Models
Characteristic OR1 95% CI1 p-value
Age 1.04 0.97, 1.12 0.3
BMI 1.01 0.84, 1.13 >0.9
Smoking

0.3
    No — —
    Yes 4.82 0.19, 61.4
Type of Reconstruction

0.6
    DTI — —
    TE 1.64 0.32, 9.59
Type of Radiation

0.2
    Photon — —
    Proton 4.26 0.49, 29.7
1 OR = Odds Ratio, CI = Confidence Interval