data <- read.csv("heart_cleveland_upload.csv")
data1 <- data[ , c(-3, -6, -7, -9, -10, -11, -12, -13)] #Deleting columns that are not relevant for my research
library(psych)
colnames(data1) <- c("Age","Sex","RestingBloodPressure","Cholesterol","MaxHeartRate","Condition")
data1$MaxHeartRate <- as.numeric(data1$MaxHeartRate)
data1$RestingBloodPressure <- as.numeric(data1$RestingBloodPressure)
data1$Cholesterol <- as.numeric(data1$Cholesterol)
data1$ConditionF <- factor(data1$Condition,
levels = c(0, 1),
labels = c("No_Disease", "Disease"))
head(data1)
## Age Sex RestingBloodPressure Cholesterol MaxHeartRate Condition ConditionF
## 1 69 1 160 234 131 0 No_Disease
## 2 69 0 140 239 151 0 No_Disease
## 3 66 0 150 226 114 0 No_Disease
## 4 65 1 138 282 174 1 Disease
## 5 64 1 110 211 144 0 No_Disease
## 6 64 1 170 227 155 0 No_Disease
summary(data1[ ,c( -2, -6 )])
## Age RestingBloodPressure Cholesterol MaxHeartRate
## Min. :29.00 Min. : 94.0 Min. :126.0 Min. : 71.0
## 1st Qu.:48.00 1st Qu.:120.0 1st Qu.:211.0 1st Qu.:133.0
## Median :56.00 Median :130.0 Median :243.0 Median :153.0
## Mean :54.54 Mean :131.7 Mean :247.4 Mean :149.6
## 3rd Qu.:61.00 3rd Qu.:140.0 3rd Qu.:276.0 3rd Qu.:166.0
## Max. :77.00 Max. :200.0 Max. :564.0 Max. :202.0
## ConditionF
## No_Disease:160
## Disease :137
##
##
##
##
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggplot(data1, aes(x = MaxHeartRate, fill = factor(ConditionF))) +
geom_histogram(position = "dodge", bins = 10) +
scale_fill_manual(values = c("coral1", "darkolivegreen"),
labels = c("Disease", "No_Disease")) +
labs(title = "Distribution of Max Heart Rate by Condition",
x = "HeartRate", y = "Frequency", fill = "Condition") +
theme_bw()
describeBy(data1$MaxHeartRate, data1$ConditionF)
##
## Descriptive statistics by group
## group: No_Disease
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 160 158.58 19.04 161 160.05 16.31 96 202 106 -0.68 0.41 1.51
## ------------------------------------------------------------
## group: Disease
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 137 139.11 22.71 142 139.78 25.2 71 195 124 -0.29 -0.3 1.94
# Shapiro-wilk test for checking normality
# For disease
shapiro.test(data1$MaxHeartRate[data1$ConditionF == "Disease"])
##
## Shapiro-Wilk normality test
##
## data: data1$MaxHeartRate[data1$ConditionF == "Disease"]
## W = 0.98967, p-value = 0.4053
#For No disease
shapiro.test(data1$MaxHeartRate[data1$ConditionF == "No_Disease"])
##
## Shapiro-Wilk normality test
##
## data: data1$MaxHeartRate[data1$ConditionF == "No_Disease"]
## W = 0.96822, p-value = 0.0009663
wilcox.test(MaxHeartRate ~ ConditionF, data = data1, exact = FALSE, subset = ConditionF %in% c("Disease", "No_Disease")) #Non-Parametric Test (Robustness Check): using a Mann-Whitney U test as a non-parametric alternative
##
## Wilcoxon rank sum test with continuity correction
##
## data: MaxHeartRate by ConditionF
## W = 16399, p-value = 1.675e-13
## alternative hypothesis: true location shift is not equal to 0
#install.packages(effectsize)
library(effectsize)
##
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
##
## phi
effectsize(wilcox.test(data1$MaxHeartRate,
mu = 142,
correct = FALSE))
## r (rank biserial) | 95% CI
## --------------------------------
## 0.39 | [0.27, 0.49]
##
## - Deviation from a difference of 142.
interpret_rank_biserial(0.39, rules = "funder2019")
## [1] "large"
## (Rules: funder2019)
Based on the sample data, we find that max heart is not the same for patients with disease and without disease. We reject null hypothesis (p<0.001). Patients with disease have on average higher max heart rate, the difference in distribution is large (𝑟 = 0.39)