Project 1 Stress Echocardiography

Author

Charlene Stephia

##Stress Echocardiography

https://images.search.yahoo.com/yhs/search?p=stress+echocardiogram+images&fr=yhs-reb-ext_onelaunch&type=0_1023_102_1075_108_231010&hspart=reb&hsimp=yhs-ext_onelaunch&imgurl=https%3A%2F%2Fwindsorheart.org%2Fwp-content%2Fuploads%2F2021%2F07%2FStress-Echocardiogram.jpg#id=0&iurl=https%3A%2F%2Fwww.heartwest.com.au%2Fwp-content%2Fuploads%2F2016%2F12%2FStress-Echo.jpg&action=click

https://www.ahajournals.org/doi/10.1161/CIR.0000000000001063

https://www.frontiersin.org/journals/cardiovascular-medicine/articles/10.3389/fcvm.2024.1407374/full ##Introduction

##Background Research on Stress Echocardiography Practice

Stress Echocardiography has gained widespread acceptance globally, with its clinical utilization increasing annully. The procedure involves the use of echocardiography, which ia a type of ultrasound imaging to assess thr heart’s structure and function during periods of stress, such as physical exercise or the administration of pharmacological agents. This allows doctors to detect abnormalities that might not be apparent during rest. This diagnostic modality offers a comprehensive array of systematic diagnostical information, ranging from etiology to pathophysiological mechanisms, there by enhancing the clinical understanding and diagnostic capabilities of non-invasive imaging.The dataset contains 558 observations and 32 variables.The following are the way my dataset variables are distributed and how I will proceed and analyse in this assignment.

##Quantitative Variables:

age (Age of the patient)

bhr (Baseline heart rate)

pkhr (Peak heart rate)

basebp (Baseline blood pressure) dp (Double product, a measure of cardiac workload)

dobdose (Dobutamine dose used in the stress test)

sbp (Systolic blood pressure)

##Categorical Variables:

gender (Male/Female)

chestpain (Presence of chest pain)

ecg (Electrocardiogram result - normal/equivocal/etc.)

posSE (Positive stress echocardiography result)

hxofCig (Smoking history - smoker/non-smoker) In this project, I will analyse the following steps; 1.Linear Regression:A model of pkhr (Peak Heart Rate) as the dependent variable and bhr, and dobdose as independent variables to see how baseline heart rate affect peak heart rate during stress. 2.Data Visualization: A boxplot comparing sbp(sytolic blood pressure)accross hxoflig(smoking history) A heatmap showing correlations between current numerical variables A scatter plot showing the relationship between dose and peak heart rate

This analysis explores the relationship between,age, baseline heart rate, and dobutamine dose on peak heart rate of both non-smokers,smokers, and current smokers using the Stress Echocardiography dataset. We will perform data cleaning, conduct a linear regression analysis, and visualize key relationships.

##Lading libraries

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.4.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

##Loading dataset

Stress_Echocardiography_Data_2_ <- read.csv("C:/Users/mafok/OneDrive/Desktop/Data 110/Stress Echocardiography Data (2).csv")

##Checking for missing values

sum(is.na(data))
Warning in is.na(data): is.na() applied to non-(list or vector) of type
'closure'
[1] 0

##unamed columns

if("Unnamed: 0" %in% names(df)) {
  Stress_Echocardiography_Data_2_ %>% select(-`Unnamed: 0`)
}

##Linear regression: Predict peak heart rate from dose and baseline heart rate

model <- lm(pkhr ~ dose + bhr, data = Stress_Echocardiography_Data_2_)
summary(model)

Call:
lm(formula = pkhr ~ dose + bhr, data = Stress_Echocardiography_Data_2_)

Residuals:
    Min      1Q  Median      3Q     Max 
-56.924 -13.898   0.202  13.393  59.489 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 63.61479    5.65108  11.257   <2e-16 ***
dose         0.02772    0.10206   0.272    0.786    
bhr          0.74379    0.05386  13.810   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 19.49 on 555 degrees of freedom
Multiple R-squared:  0.2571,    Adjusted R-squared:  0.2545 
F-statistic: 96.06 on 2 and 555 DF,  p-value: < 2.2e-16

The coefficient is small and the p-value (0.786) is very high, meaning dose does not significantly affect the dependent variable.

par(mfrow = c(2, 2))
plot(model)

BHR (0.74379): This number is much bigger and has a very small p-value (p < 0.001), meaning higher BHR leads to a higher predicted outcome.

##Adding color to the model

par(mfrow = c(2, 2), col.main = "orange", col.lab = "darkblue", col.axis = "pink")
plot(model)

##Visualization with custum colors and theme

ggplot(Stress_Echocardiography_Data_2_, aes(x = dose, y = pkhr, color = hxofCig)) +
  geom_point(size = 3, alpha = 0.7) +
  facet_wrap(~ hxofCig) +
  labs(
    title = "Peak Heart Rate vs Dose by Smoking History",
    x = "Stress Agent Dose (mg)",
    y = "Peak Heart Rate (bpm)",
    caption = "Source: Elhendy et al., American Heart Journal, 2002"
  ) +
  scale_color_manual(values = c("#F8866D", "#00BA68", "#619CFF")) +
  theme_minimal() +
  theme(legend.title = element_blank())

##Explaining the visualization from this graph we can observe the following trends; Non-smokers: In the plot for non-smokers, you can see that the peak heart rate tends to increase as the stress agent dose increases. This suggests that non-smokers may have a clear response to the dose in terms of their peak heart rate.

Former Smokers: For former smokers, the relationship between dose and peak heart rate is a bit more scattered, but there does seem to be a slight increase in peak heart rate as the dose increases, though it’s not as strong or consistent as with non-smokers.

Current Smokers: The current smokers’ plot is the most scattered and less consistent. There’s no obvious upward or downward trend in peak heart rate as the dose increases. The heart rates for current smokers seem to vary more widely across doses, which could suggest that smoking history may influence how their heart rate responds to the stress agent.

##Select numeric variables only for correlation ananlysis

numeric_vars <- Stress_Echocardiography_Data_2_ %>%
  select(bhr, basebp, pkhr, sbp, dose, maxhr)

##Compute correlationmatrix

cor_matrix <- cor(numeric_vars)

##Convert correlation matrix to long format for ggplot heatmap

cor_df <- as.data.frame(as.table(cor_matrix))

##Plot Heatmap showing corrolation btw current numerical variables

ggplot(cor_df, aes(Var1, Var2, fill = Freq)) +
  geom_tile(color = "black") +
  scale_fill_gradient2(
    low = "#4542b4", high = "#d73045", mid = "purple",
    midpoint = 0, limit = c(-1, 1),
    name = "Correlation"
  ) +
  labs(
    title = "Correlation Heatmap of Numeric Variables",
    x = "Variable",
    y = "Variable",
    caption = "Source: Elhendy et al., American Heart Journal, 2002"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 55, vjust = 1, hjust = 1),
    legend.position = "left"
  )

##Explaining the graph The purple squares show no correlation between the variables, while the blue indicates a negative correlation among the variables. Finally the red squares indicate a strong positive correlation among the variables.

##source

part of the code was made through the help of chat gpt ggplot(cor_df, aes(Var1, Var2, fill = Freq)) axis.text.x = element_text ChatGPT4.0 Question was “How to initialize a ggplot using correlation different value btw numeric variables” date 3/30/2025 Q2 “How to customize appearence on my heatmap for better redability” https://chatgpt.com/c/67e9a5c2-42dc-8010-a2b5-ad8b32f0a862

##Create a scatter plot to show the relationship between dose and peak heart rate

ggplot(Stress_Echocardiography_Data_2_, aes(x = dose, y = pkhr, color = hxofCig)) +
  geom_point(size = 3, alpha = 0.8) +
  labs(
    title = "Peak Heart Rate vs. Stress Agent Dose by Smoking History",
    x = "Stress Agent Dose (mg)",
    y = "Peak Heart Rate (bpm)",
    color = "Smoking Status",
    caption = "Source: Elhendy et al., American Heart Journal, 2002"
  ) +
  scale_color_manual(values = c("#E41A4C", "#354EB8", "#6DAF4C")) +  # custom colors
  theme_minimal() +
  theme(
    legend.position = "bottom",
    plot.title = element_text(size = 16, face = "bold"),
    axis.title = element_text(size = 13)
  )

Explaining the visualization

From the graph, we can observe the following trends:

There doesn’t appear to be a strong trend between the stress agent dose and peak heart rate across the different smoking groups. The points are scattered, indicating that other factors might be influencing the peak heart rate rather than just the dose.

However, we do notice some differences between the smoking groups. For example, former smokers seem to have a slightly higher peak heart rate at lower doses compared to non-smokers or current smokers. This might suggest that smoking history could affect how individuals respond to the stress agent, but further analysis is needed to confirm this.

The spread of points across all groups suggests variability in the response to the stress agent, and more investigation might be required to identify any underlying patterns or factors that influence peak heart rate.

                      References

Heidenreich, Paul A., et al. “2002 AHA/ACC/HFSA Guideline for the Management of Heart Failure: A Report of the American College of Cardiology/American Heart Association Joint Committee on Clinical Practice Guidelines.” Circulation, vol. 145, no. 18, Apr. 2002, https://doi.org/10.1161/cir.0000000000001063.

Yin, Lixue. “Editorial: Stress Echocardiography in Cardiovascular Diseases.” Frontiers in Cardiovascular Medicine, vol. 11, May 2024, https://doi.org/10.3389/fcvm.2024.1407374. Accessed 27 Oct. 2024.