Male Resting Heart Rate
Analysis
Descriptive
Statistics
male_stats <- data.frame(
Statistic = c(
"Sample size", "Minimum", "First quartile (Q1)", "Sample median",
"Sample mean", "Third quartile (Q3)", "Maximum",
"Sample standard deviation", "Range", "Interquartile range"
),
Value = c(
length(male_heart_rate),
min(male_heart_rate),
unname(quantile(male_heart_rate, 0.25)),
median(male_heart_rate),
mean(male_heart_rate),
unname(quantile(male_heart_rate, 0.75)),
max(male_heart_rate),
sd(male_heart_rate),
diff(range(male_heart_rate)),
IQR(male_heart_rate)
)
)
male_stats$Value <- round(male_stats$Value, 2)
knitr::kable(
male_stats,
col.names = c("Statistic", "Value (BPM)"),
caption = "Descriptive Statistics for Male Resting Heart Rate"
)
Descriptive Statistics for Male Resting Heart Rate
| Sample size |
65.00 |
| Minimum |
58.00 |
| First quartile (Q1) |
70.00 |
| Sample median |
73.00 |
| Sample mean |
73.37 |
| Third quartile (Q3) |
78.00 |
| Maximum |
86.00 |
| Sample standard deviation |
5.88 |
| Range |
28.00 |
| Interquartile range |
8.00 |
Histogram
ggplot(male_data, aes(x = heart_rate)) +
geom_histogram(
binwidth = 4,
boundary = 0,
fill = "blue",
color = "black",
alpha = 0.70
) +
geom_vline(
xintercept = mean(male_heart_rate),
color = "red",
linewidth = 1,
linetype = "dashed"
) +
labs(
title = "Distribution of Male Resting Heart Rate",
subtitle = paste(
"Dashed line: sample mean =",
round(mean(male_heart_rate), 2),
"BPM"
),
x = "Male Resting Heart Rate (BPM)",
y = "Frequency"
) +
theme_minimal()

Normal Probability
Plot
ggplot(male_data, aes(sample = heart_rate)) +
stat_qq(color = "blue", size = 2) +
stat_qq_line(color = "red", linewidth = 1, linetype = "dashed") +
labs(
title = "Normal Q-Q Plot of Male Resting Heart Rate",
x = "Theoretical Normal Quantiles",
y = "Observed Male Resting Heart Rate (BPM)"
) +
theme_minimal()

Female Resting Heart
Rate Analysis
Descriptive
Statistics
female_stats <- data.frame(
Statistic = c(
"Sample size", "Minimum", "First quartile (Q1)", "Sample median",
"Sample mean", "Third quartile (Q3)", "Maximum",
"Sample standard deviation", "Range", "Interquartile range"
),
Value = c(
length(female_heart_rate),
min(female_heart_rate),
unname(quantile(female_heart_rate, 0.25)),
median(female_heart_rate),
mean(female_heart_rate),
unname(quantile(female_heart_rate, 0.75)),
max(female_heart_rate),
sd(female_heart_rate),
diff(range(female_heart_rate)),
IQR(female_heart_rate)
)
)
female_stats$Value <- round(female_stats$Value, 2)
knitr::kable(
female_stats,
col.names = c("Statistic", "Value (BPM)"),
caption = "Descriptive Statistics for Female Resting Heart Rate"
)
Descriptive Statistics for Female Resting Heart Rate
| Sample size |
65.00 |
| Minimum |
57.00 |
| First quartile (Q1) |
68.00 |
| Sample median |
76.00 |
| Sample mean |
74.15 |
| Third quartile (Q3) |
80.00 |
| Maximum |
89.00 |
| Sample standard deviation |
8.11 |
| Range |
32.00 |
| Interquartile range |
12.00 |
Histogram
ggplot(female_data, aes(x = heart_rate)) +
geom_histogram(
binwidth = 4,
boundary = 0,
fill = "pink",
color = "black",
alpha = 0.80
) +
geom_vline(
xintercept = mean(female_heart_rate),
color = "red",
linewidth = 1,
linetype = "dashed"
) +
labs(
title = "Distribution of Female Resting Heart Rate",
subtitle = paste(
"Dashed line: sample mean =",
round(mean(female_heart_rate), 2),
"BPM"
),
x = "Female Resting Heart Rate (BPM)",
y = "Frequency"
) +
theme_minimal()

Normal Probability
Plot
ggplot(female_data, aes(sample = heart_rate)) +
stat_qq(color = "deeppink", size = 2) +
stat_qq_line(color = "red", linewidth = 1, linetype = "dashed") +
labs(
title = "Normal Q-Q Plot of Female Resting Heart Rate",
x = "Theoretical Normal Quantiles",
y = "Observed Female Resting Heart Rate (BPM)"
) +
theme_minimal()

Comparison of Male and
Female Heart Rates
Side-by-Side
Boxplots
ggplot(
heart_data,
aes(x = sex_label, y = heart_rate, fill = sex_label)
) +
geom_boxplot(width = 0.55, alpha = 0.75, color = "black") +
scale_fill_manual(values = c("Male" = "blue", "Female" = "pink")) +
labs(
title = "Comparison of Male and Female Resting Heart Rates",
x = "Sex",
y = "Resting Heart Rate (BPM)"
) +
theme_minimal() +
theme(legend.position = "none")

Summary Statistics by
Sex
summary_stats <- heart_data %>%
group_by(sex_label) %>%
summarise(
N = n(),
Minimum = min(heart_rate),
Q1 = unname(quantile(heart_rate, 0.25)),
Median = median(heart_rate),
Mean = mean(heart_rate),
Q3 = unname(quantile(heart_rate, 0.75)),
Maximum = max(heart_rate),
SD = sd(heart_rate),
Range = diff(range(heart_rate)),
IQR = IQR(heart_rate),
.groups = "drop"
) %>%
mutate(across(where(is.numeric), ~ round(.x, 2)))
knitr::kable(
summary_stats,
col.names = c(
"Sex", "N", "Minimum", "Q1", "Median", "Mean", "Q3",
"Maximum", "SD", "Range", "IQR"
),
caption = "Comparison of Male and Female Resting Heart Rates"
)
Comparison of Male and Female Resting Heart Rates
| Male |
65 |
58 |
70 |
73 |
73.37 |
78 |
86 |
5.88 |
28 |
8 |
| Female |
65 |
57 |
68 |
76 |
74.15 |
80 |
89 |
8.11 |
32 |
12 |