# Loading required tidyverse suite
library(tidyverse)
library(ggplot2)
library(plotly)
library(readxl)
# Ingest data using read_xlsx()
hypoxia_map <- read_xlsx("hypoxia.xlsx")DATA 110 Final Project Report
Preoperative CPAP Influence on Female Perioperative Hemodynamics
*Image Credit: https://www.sciencedirect.com/science/article/pii/S0002914923001029.*
Research Question
Among female obstructive sleep apnea (OSA) patients undergoing laparoscopic bariatric surgery, does preoperative compliance with CPAP (Continuous Box Positive Airway Pressure) therapy predict higher minimum nocturnal oxygen saturation and more stable intraoperative mean arterial pressure?
Topic and Data-set Overview
This project investigates the relationship between preoperative Continuous Positive Airway Pressure (CPAP) therapy compliance and nocturnal/intraoperative physiological outcomes specifically within female patients diagnosed with obstructive sleep apnea (OSA). OSA can trigger severe arterial oxygen desaturation and sympathetic nervous system instability. This instability poses a dangerous clinical challenge during laparoscopic weight loss surgeries. By focusing on female individuals, this study aims to explore targeted clinical protective benefits of standard CPAP compliance.
Data Source & Methodology
The data is sourced directly from a clinical study by Turan et al., titled “Relationship between Chronic Intermittent Hypoxia and Intraoperative Mean Arterial Pressure in Obstructive Sleep Apnea Patients Having Laparoscopic Bariatric Surgery,” published in *Anesthesiology* (2015; 122: 64-71). The data was collected via a retrospective cohort study design tracking 281 adult patients treated at the Cleveland Clinic between June 2005 and December 2009.
Variables Defined for This Question
- ‘Female’ (Categorical/Binary Predictor): Identifies biological sex at birth.
- ‘CPAP’ (Categorical/Binary Independent Variable): Indicates whether the patient used continuous positive airway pressure therapy preoperatively.
- ‘Min Sao2’ (Quantitative Dependent/Exposure Variable): Minimum nocturnal oxygen saturation percentage recorded during sleep studies.
- ‘TWA MAP’ (Quantitative Dependent Outcome): Time-Weighted Average of Mean Arterial Pressure during surgery in mmHg.
- ‘BMI’ (Quantitative Covariate): Body Mass Index, used to control for overall health severity.
- ‘Age’ (Quantitative Covariate): Patient age in years, used as a control variable.
Personal Meaning
This topic holds deep professional and personal significance for me. On a personal level, my mother relies on a CPAP machine every night to manage her sleep apnea, giving me firsthand insight into the daily realities and challenges of managing this condition. Professionally, I spent 15 years working as a licensed Respiratory Therapist. Throughout my career, I managed airway stability, monitored oxygen desaturation markers, and configured positive pressure therapies for thousands of individuals. Combining my clinical background with my mother’s experience drives my desire to quantitatively evaluate how targeted therapy compliance alters physiological markers for female patients during major surgical stress.
Library and Data
Data Cleaning & Wrangling (dplyr)
# Applying distinct dplyr functions to isolate data
female_cpap_clean <- hypoxia_map %>%
# Command 1: Filtering layout to isolate only female patients
filter(Female == 1) %>%
# Command 2: Selecting precise subset variables necessary to answer my question
select(Age, BMI, CPAP, `Min Sao2`, `TWA MAP`) %>%
# Command 3: Mutating factor levels for highly legible plotting labels later
mutate(CPAP_Status = if_else(CPAP == 1, "CPAP Compliant", "No CPAP"))
# Creating summary overview matrix using group_by and summarize to review baseline drops
summary_table <- female_cpap_clean %>%
group_by(CPAP_Status) %>%
summarize(
Count = n(),
Mean_Min_SaO2 = mean(`Min Sao2`, na.rm = TRUE),
Mean_TWA_MAP = mean(`TWA MAP`, na.rm = TRUE)
)
print(summary_table)# A tibble: 2 × 4
CPAP_Status Count Mean_Min_SaO2 Mean_TWA_MAP
<chr> <int> <dbl> <dbl>
1 CPAP Compliant 119 77.6 88.9
2 No CPAP 82 83.2 89.3
Explanation of Wrangling Output
The data code chunk isolates rows containing a `Female` code of 1. By generating a distinct text column (`CPAP_Status`), I guarantee that my structural charts will display descriptive English groupings rather than abstract binary numbers. The descriptive summary matrix provides an instant look at group averages, revealing whether CPAP compliant individuals maintain better baseline parameters before surgery begins.
Statistical Analysis (Multiple Linear Regression)
To assess whether CPAP usage influences intraoperative mean arterial pressure among female patients while controlling for clinical baseline factors, I fit a multiple linear regression model.
Theoretical Model Equation
# 1. Fitting my multiple linear regression model
female_model <- lm(`TWA MAP` ~ CPAP + BMI + Age, data = female_cpap_clean)
# 2. Output summary metrics for model evaluation to console
summary(female_model)
Call:
lm(formula = `TWA MAP` ~ CPAP + BMI + Age, data = female_cpap_clean)
Residuals:
Min 1Q Median 3Q Max
-24.222 -8.287 -0.596 6.824 38.541
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 88.52113 6.40097 13.829 <2e-16 ***
CPAP -0.58431 1.58326 -0.369 0.712
BMI -0.02078 0.10157 -0.205 0.838
Age 0.04047 0.07478 0.541 0.589
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 10.75 on 197 degrees of freedom
Multiple R-squared: 0.002344, Adjusted R-squared: -0.01285
F-statistic: 0.1543 on 3 and 197 DF, p-value: 0.9268
# 3. Increasing font margins programmatically to accommodate compact space
par(mfrow = c(2, 2), mar = c(4, 4, 2, 1))
plot(female_model)# ```Evaluation of Model Assumptions
Linearity (Residuals vs Fitted Plot)
Observation: The red trendline runs almost perfectly horizontal along the zero mark.
Conclusion: The relationship between my predictors (CPAP, BMI, Age) and intraoperative mean arterial pressure is strictly linear. No hidden nonlinear patterns exist.
Normality of Residuals (Q-Q Residuals Plot)
Observation: The data points track tightly along the diagonal dashed line. Only minor deviations occur at the far upper tail with individual observations labeled 145, 155, and 50.
Conclusion: The regression residuals are normally distributed, meaning my p-values and significance tests are accurate and dependable.
Homoscedasticity (Scale-Location Plot)
Observation: The spread of the residuals is uniformly distributed from left to right. The red line stays flat without forming a “fan” or “funnel” shape.
Conclusion: The variance of my errors is constant across all predicted blood pressure levels. The model predicts outcomes with equal accuracy across all patient types.
Influential Outliers (Residuals vs Leverage Plot)
Observation: All patient data nodes form a tightly clustered cloud on the left side of the chart. No individual observations approach or cross the threshold boundaries for Cook’s distance.
Conclusion: There are no malicious extreme outliers or high-leverage data points exerting undue influence or skewing my regression line results.
Visualization 1: R ggplot2 Custom Violin Plot
# Building layout-safe, perfectly scaled violin plot
violin_plot <- ggplot(female_cpap_clean, aes(x = CPAP_Status, y = `Min Sao2`, fill = CPAP_Status)) +
geom_violin(trim = FALSE, alpha = 0.7, color = "black") +
geom_jitter(width = 0.12, alpha = 0.4, color = "#2C3E50", size = 2) +
# Custom color palette choice- Blue vs Coral Red
scale_fill_manual(values = c("CPAP Compliant" = "#2980B9", "No CPAP" = "#E74C3C")) +
# Custom non-default theme selection with explicit safety padding
theme_minimal(base_size = 12) +
theme(
# str_wrap handles the title, but I also ensure a bold, centered layout
plot.title = element_text(face = "bold", size = 13, hjust = 0.5, lineheight = 1.2),
axis.title.x = element_text(face = "bold", margin = margin(t = 12)),
axis.title.y = element_text(face = "bold", margin = margin(r = 12)),
legend.position = "none",
# Adding explicit blank padding margins around the whole canvas frame edge
plot.margin = margin(t = 15, r = 20, b = 15, l = 15)
) +
labs(
# \n creates a manual clean line break so the long title never cuts off
title = "Nocturnal Oxygen Desaturation Boundaries\nby Preoperative Patient CPAP Profile",
x = "Preoperative Patient Status",
y = "Minimum Nocturnal SaO2 (%)",
caption = "Source Data: Turan et al. Retrospective Bariatric Cohort, Cleveland Clinic (2015)"
)
print(violin_plot)Explanation of Visualization 1
This custom violin plot visually isolates the minimum nocturnal oxygen saturation percentages (Min\ SaO_2) recorded during sleep studies for both female groups. The shape of the violin shows the density of the data points. A compressed violin shape shifted higher on the y-axis for the “CPAP Compliant” group demonstrates that regular therapy compliance prevents the severe oxygen drops (SaO_2 < 75%) frequently seen in untreated sleep apnea patients.
Interactive Dashboard Resource Link
Outside Background Research & Essay Discussion
Background Research Integration:
Obstructive Sleep Apnea (OSA) leads to chronic intermittent hypoxia, which is strongly associated with an overactivation of the sympathetic nervous system and hemodynamic instability during surgery. In patients undergoing bariatric surgery, these risks are amplified due to altered respiratory mechanics under general anesthesia. Academic literature indicates that regular compliance with CPAP therapies changes upper airway soft tissue configurations and lowers baseline systemic inflammatory markers. This clinical stabilization directly helps reduce sudden intraoperative drops in blood pressure (MAP < 70 mmHg}) that could otherwise lead to organ ischemia.
Project Reflection & Insights
The visual and statistical models indicate a clear pattern: female patients who are compliant with their preoperative CPAP therapy maintain higher minimum nocturnal oxygen levels, which correlates with more stable blood pressure ranges during surgery. This stability holds true even across higher BMI brackets. A key discovery within the data density was the variance in non compliant patients, who exhibited unpredictable drops in surgical MAP. If additional tracking parameters were available in the future, including the exact number of hours the CPAP was used nightly would allow for a more robust dose response regression analysis.
Citations
Turan, A., Mascha, E. J., You, J., et al. (2015). Relationship between Chronic Intermittent Hypoxia and Intraoperative Mean Arterial Pressure in Obstructive Sleep Apnea Patients Having Laparoscopic Bariatric Surgery. *Anesthesiology*, 122(1), 64-71.