This report captures work done for the 2nd flipped assignment, studying male and female resting heart rates. R code along with the results are provided. It was a pleasure for Team 4 to complete this assignment.
# setup Libraries
library(knitr)
# read in file
d<- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv",
sep=",", na.strings = c("","."))
# clean up first col name and as.factor for sex
names(d)[1] <- "Temp"
d$Sex<- as.factor(d$Sex)
# setup data frame
dataTable<- data.frame(matrix(NA,2,6))
rownames(dataTable)<- c('Male','Female')
colnames(dataTable)<- c('min','max','mean','sd','median','quantile')
The following is a summary of the descriptive statistics of resting heart rates for both males and females.
# males = 1, females = 2
# Male
dataTable$min[1] <- min(d$Beats[d$Sex == 1])
dataTable$max[1] <- max(d$Beats[d$Sex == 1])
dataTable$mean[1] <- mean(d$Beats[d$Sex == 1])
dataTable$sd[1] <- sd(d$Beats[d$Sex == 1])
dataTable$median[1] <- median(d$Beats[d$Sex == 1])
dataTable$quantile[1] <- list(as.vector(quantile(d$Beats[d$Sex == 1])))
# Female
dataTable$min[2] <- min(d$Beats[d$Sex == 2])
dataTable$max[2] <- max(d$Beats[d$Sex == 2])
dataTable$mean[2] <- mean(d$Beats[d$Sex == 2])
dataTable$sd[2] <- sd(d$Beats[d$Sex == 2])
dataTable$median[2] <- median(d$Beats[d$Sex == 2])
dataTable$quantile[2] <- list(as.vector(quantile(d$Beats[d$Sex == 2])))
## format Table
# Mean and SD to 2 decimal places
dataTable$mean <- as.numeric(format(round(dataTable$mean,2), nsmall = 2))
dataTable$sd <- as.numeric(format(round(dataTable$sd,2), nsmall = 2))
kable(dataTable,caption = "Statistical Table of Male and Female")
| min | max | mean | sd | median | quantile | |
|---|---|---|---|---|---|---|
| Male | 58 | 86 | 73.37 | 5.88 | 73 | 58, 70, 73, 78, 86 |
| Female | 57 | 89 | 74.15 | 8.11 | 76 | 57, 68, 76, 80, 89 |
With a sample size of 65 for each sex, the average resting heart rate of males is about 1% lower than that of females. The resting heart rate of males has a slightly smaller range (58 BPM - 86 BPM) than that of females (57 BPM - 89 BPM). The resting heart rate standard deviation of males is about 38% lower than that of females. The male resting heart rates are pretty well centralized around the mean of 73 BPM. The females resting heart rates are not represented in the same manner as their frequencies are more spread out across the data series.
## plots
# Male
hist(d$Beats[d$Sex == 1],
main = "Histogram for Males",
xlab = "Resting Heart Rate (BPM)",
col = "Blue")
The male resting heart rate follows a normal distribution with the most probable resting heart rate being between 70 BPM and 75 BPM.
qqnorm(d$Beats[d$Sex == 1],
main = "Normal Probability for Males",
pch = 21,
cex = 1,
col = "black",
bg = "Blue",
lwd = 1)
qqline(d$Beats[d$Sex == 1])
The normal probability plot for males shows that the resting heart rates follow the model with a high residual in quantiles -2 to 1. The highest 2-3 resting heart rates have a lower residual.
# Females
hist(d$Beats[d$Sex == 2],
main = "Histogram for Males",
xlab = "Resting Heart Rate (BPM)",
col = "Pink")
The female resting heart rate somewhat follows a normal distribution. Their most probable resting heart rate is between 75 BPM and 80 BPM.
qqnorm(d$Beats[d$Sex == 2],
main = "Normal Probability for Females",
pch = 21,
cex = 1,
col = "black",
bg = "Pink",
lwd = 1)
qqline(d$Beats[d$Sex == 2])
The normal probability plot for females shows that the resting heart rates also generally follow the model with a high residual, but several of the higher resting heart rates do not follow the model. There is also an outlier with one of the lowest resting heart rates.
# Side-by-side Box plots
boxplot(d$Beats[d$Sex == 1],d$Beats[d$Sex == 2],
main = "Resting Heart Rate Between Male & Female",
ylab = "Resting Heart Rate (BPM)",
names = c("Male","Female"),
col = c("blue","pink"))
The side-by-side box plot shows that the Female median value for resting heart rate is greater than that of Males. It is also clear that the Female distribution is wider than that of Males.
# setup Libraries
library(knitr)
# read in file
d<- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv",
sep=",", na.strings = c("","."))
# clean up first col name and as.factor for sex
names(d)[1] <- "Temp"
d$Sex<- as.factor(d$Sex)
# setup data frame
dataTable<- data.frame(matrix(NA,2,6))
rownames(dataTable)<- c('Male','Female')
colnames(dataTable)<- c('min','max','mean','sd','median','quantile')
# males = 1, females = 2
# Male
dataTable$min[1] <- min(d$Beats[d$Sex == 1])
dataTable$max[1] <- max(d$Beats[d$Sex == 1])
dataTable$mean[1] <- mean(d$Beats[d$Sex == 1])
dataTable$sd[1] <- sd(d$Beats[d$Sex == 1])
dataTable$median[1] <- median(d$Beats[d$Sex == 1])
dataTable$quantile[1] <- list(as.vector(quantile(d$Beats[d$Sex == 1])))
# Female
dataTable$min[2] <- min(d$Beats[d$Sex == 2])
dataTable$max[2] <- max(d$Beats[d$Sex == 2])
dataTable$mean[2] <- mean(d$Beats[d$Sex == 2])
dataTable$sd[2] <- sd(d$Beats[d$Sex == 2])
dataTable$median[2] <- median(d$Beats[d$Sex == 2])
dataTable$quantile[2] <- list(as.vector(quantile(d$Beats[d$Sex == 2])))
## format Table
# Mean and SD to 2 decimal places
dataTable$mean <- as.numeric(format(round(dataTable$mean,2), nsmall = 2))
dataTable$sd <- as.numeric(format(round(dataTable$sd,2), nsmall = 2))
kable(dataTable,caption = "Statistical Table of Male and Female")
## plots
# Male
hist(d$Beats[d$Sex == 1],
main = "Histogram for Males",
xlab = "Resting Heart Rate (BPM)",
col = "Blue")
qqnorm(d$Beats[d$Sex == 1],
main = "Normal Probability for Males",
pch = 21,
cex = 1,
col = "black",
bg = "Blue",
lwd = 1)
qqline(d$Beats[d$Sex == 1])
# Females
hist(d$Beats[d$Sex == 2],
main = "Histogram for Males",
xlab = "Resting Heart Rate (BPM)",
col = "Pink")
qqnorm(d$Beats[d$Sex == 2],
main = "Normal Probability for Females",
pch = 21,
cex = 1,
col = "black",
bg = "Pink",
lwd = 1)
qqline(d$Beats[d$Sex == 2])
# Side-by-side Box plots
boxplot(d$Beats[d$Sex == 1],d$Beats[d$Sex == 2],
main = "Resting Heart Rate Between Male & Female",
ylab = "Resting Heart Rate (BPM)",
names = c("Male","Female"),
col = c("blue","pink"))
from: https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv
kable(d,caption = "Resting Heart Rate Data")
| Temp | Sex | Beats |
|---|---|---|
| 96.3 | 1 | 70 |
| 96.7 | 1 | 71 |
| 96.9 | 1 | 74 |
| 97.0 | 1 | 80 |
| 97.1 | 1 | 73 |
| 97.1 | 1 | 75 |
| 97.1 | 1 | 82 |
| 97.2 | 1 | 64 |
| 97.3 | 1 | 69 |
| 97.4 | 1 | 70 |
| 97.4 | 1 | 68 |
| 97.4 | 1 | 72 |
| 97.4 | 1 | 78 |
| 97.5 | 1 | 70 |
| 97.5 | 1 | 75 |
| 97.6 | 1 | 74 |
| 97.6 | 1 | 69 |
| 97.6 | 1 | 73 |
| 97.7 | 1 | 77 |
| 97.8 | 1 | 58 |
| 97.8 | 1 | 73 |
| 97.8 | 1 | 65 |
| 97.8 | 1 | 74 |
| 97.9 | 1 | 76 |
| 97.9 | 1 | 72 |
| 98.0 | 1 | 78 |
| 98.0 | 1 | 71 |
| 98.0 | 1 | 74 |
| 98.0 | 1 | 67 |
| 98.0 | 1 | 64 |
| 98.0 | 1 | 78 |
| 98.1 | 1 | 73 |
| 98.1 | 1 | 67 |
| 98.2 | 1 | 66 |
| 98.2 | 1 | 64 |
| 98.2 | 1 | 71 |
| 98.2 | 1 | 72 |
| 98.3 | 1 | 86 |
| 98.3 | 1 | 72 |
| 98.4 | 1 | 68 |
| 98.4 | 1 | 70 |
| 98.4 | 1 | 82 |
| 98.4 | 1 | 84 |
| 98.5 | 1 | 68 |
| 98.5 | 1 | 71 |
| 98.6 | 1 | 77 |
| 98.6 | 1 | 78 |
| 98.6 | 1 | 83 |
| 98.6 | 1 | 66 |
| 98.6 | 1 | 70 |
| 98.6 | 1 | 82 |
| 98.7 | 1 | 73 |
| 98.7 | 1 | 78 |
| 98.8 | 1 | 78 |
| 98.8 | 1 | 81 |
| 98.8 | 1 | 78 |
| 98.9 | 1 | 80 |
| 99.0 | 1 | 75 |
| 99.0 | 1 | 79 |
| 99.0 | 1 | 81 |
| 99.1 | 1 | 71 |
| 99.2 | 1 | 83 |
| 99.3 | 1 | 63 |
| 99.4 | 1 | 70 |
| 99.5 | 1 | 75 |
| 96.4 | 2 | 69 |
| 96.7 | 2 | 62 |
| 96.8 | 2 | 75 |
| 97.2 | 2 | 66 |
| 97.2 | 2 | 68 |
| 97.4 | 2 | 57 |
| 97.6 | 2 | 61 |
| 97.7 | 2 | 84 |
| 97.7 | 2 | 61 |
| 97.8 | 2 | 77 |
| 97.8 | 2 | 62 |
| 97.8 | 2 | 71 |
| 97.9 | 2 | 68 |
| 97.9 | 2 | 69 |
| 97.9 | 2 | 79 |
| 98.0 | 2 | 76 |
| 98.0 | 2 | 87 |
| 98.0 | 2 | 78 |
| 98.0 | 2 | 73 |
| 98.0 | 2 | 89 |
| 98.1 | 2 | 81 |
| 98.2 | 2 | 73 |
| 98.2 | 2 | 64 |
| 98.2 | 2 | 65 |
| 98.2 | 2 | 73 |
| 98.2 | 2 | 69 |
| 98.2 | 2 | 57 |
| 98.3 | 2 | 79 |
| 98.3 | 2 | 78 |
| 98.3 | 2 | 80 |
| 98.4 | 2 | 79 |
| 98.4 | 2 | 81 |
| 98.4 | 2 | 73 |
| 98.4 | 2 | 74 |
| 98.4 | 2 | 84 |
| 98.5 | 2 | 83 |
| 98.6 | 2 | 82 |
| 98.6 | 2 | 85 |
| 98.6 | 2 | 86 |
| 98.6 | 2 | 77 |
| 98.7 | 2 | 72 |
| 98.7 | 2 | 79 |
| 98.7 | 2 | 59 |
| 98.7 | 2 | 64 |
| 98.7 | 2 | 65 |
| 98.7 | 2 | 82 |
| 98.8 | 2 | 64 |
| 98.8 | 2 | 70 |
| 98.8 | 2 | 83 |
| 98.8 | 2 | 89 |
| 98.8 | 2 | 69 |
| 98.8 | 2 | 73 |
| 98.8 | 2 | 84 |
| 98.9 | 2 | 76 |
| 99.0 | 2 | 79 |
| 99.0 | 2 | 81 |
| 99.1 | 2 | 80 |
| 99.1 | 2 | 74 |
| 99.2 | 2 | 77 |
| 99.2 | 2 | 66 |
| 99.3 | 2 | 68 |
| 99.4 | 2 | 77 |
| 99.9 | 2 | 79 |
| 100.0 | 2 | 78 |
| 100.8 | 2 | 77 |