This data set includes measurements on the resting body temperature and resting heart rate of 65 randomly sampled males and 65 randomly sampled females. The data from the file normtemp.csv can be found below. Note that the Sex column is separated into two factors, number 1 is the male identifier while number 2 is the female identifier.
sampledata<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv")
rmarkdown::paged_table(sampledata)
sampledata$Sex<-as.factor(sampledata$Sex)
sampledata$Beats<-as.numeric(sampledata$Beats)
In order to find the minimum heart rate for males, we first filter down to males by setting the “Sex” column equal to 1. The min() function is then used to find the minimum heart rate of 58 BPM.
maleid<-sampledata$Sex==1
min1<-min(sampledata[maleid,3])
cat(paste(min1, "Beats Per Minute"))
## 58 Beats Per Minute
In order to find the maximum heart rate for males, we first filter down to males by setting the “Sex” column equal to 1. The max() function is then used to find the maximum heart rate of 86 BPM.
max1<-max(sampledata[maleid,3])
cat(paste(max1, "Beats Per Minute"))
## 86 Beats Per Minute
The average heart rate for males is calculated by summing all the male heart rate values and then dividing by the sample size. This is done using the mean() function. The equation can be seen below.
\[AVG = \frac {\sum x_n} {n}\]
avg1<-round(mean(sampledata[maleid,3]),3)
cat(paste(avg1, "Beats Per Minute"))
## 73.369 Beats Per Minute
The standard deviation involves subtracting the average from the different heart rate values and squaring the result. These are all summed and then divided by the number of samples. Finally, the square root is taken to get the standard deviation value. All of this is performed through the sd() function.
stddev1<-round(sd(sampledata[maleid,3]),3)
cat(paste(stddev1, "Beats Per Minute"))
## 5.875 Beats Per Minute
When the heart rates are ordered from smallest to largest, the median value is the heart rate in the middle of the sample size. This is found using the median() function.
med1<-median(sampledata[maleid,3])
cat(paste(med1, "Beats Per Minute"))
## 73 Beats Per Minute
The quantile() function is used to identify the different percentiles of the data. For example, 25% of the values are below 70 BPM. On the other extreme, 25% of the values are above 78 BPM.
quart1<-quantile(sampledata[maleid,3],probs = seq(0.25, 0.75, 0.25))
quart1
## 25% 50% 75%
## 70 73 78
The male resting heart rates feature a classic normal distribution. Most of the data clusters around the average heart rate of 73 BPM in the 65 to 80 BPM range.
histo1<-hist(sampledata[maleid,3],col = "blue", main = "Histogram of Male Resting Heart Rates", xlab = "Beats Per Minute")
The normal probability plot further shows that the male resting heart rate closely follows a normal distribution.
norm1<-qqnorm(sampledata[maleid,3], main = "Normal Probability Plot for Male Resting Heart Rates", ylab = "Beats Per Minute", col = "blue", xlab = "Theoretical Quantiles")
ref1<-qqline(sampledata[maleid,3], col = "red")
In order to find the minimum heart rate for females, we first filter down to females by setting the “Sex” column equal to 2. The min() function is then used to find the minimum heart rate of 57 BPM.
femaleid<-sampledata$Sex==2
min2<-min(sampledata[femaleid,3])
cat(paste(min2, "Beats Per Minute"))
## 57 Beats Per Minute
In order to find the maximum heart rate for females, we first filter down to females by setting the “Sex” column equal to 2. The max() function is then used to find the maximum heart rate of 89 BPM.
max2<-max(sampledata[femaleid,3])
cat(paste(max2, "Beats Per Minute"))
## 89 Beats Per Minute
The average heart rate for females is calculated by summing all the female heart rate values and then dividing by the sample size. This is done using the mean() function. The equation can be seen below.
\[AVG = \frac {\sum x_n} {n}\]
avg2<-round(mean(sampledata[femaleid,3],),3)
cat(paste(avg2, "Beats Per Minute"))
## 74.154 Beats Per Minute
The standard deviation involves subtracting the average from the different heart rate values and squaring the result. These are all summed and then divided by the number of samples. Finally, the square root is taken to get the standard deviation value. All of this is performed through the sd() function.
stddev2<-round(sd(sampledata[femaleid,3]),3)
cat(paste(stddev2, "Beats Per Minute"))
## 8.105 Beats Per Minute
When the heart rates are ordered from smallest to largest, the median value is the heart rate in the middle of the sample size. This is found using the median() function.
med2<-median(sampledata[femaleid,3])
cat(paste(med2, "Beats Per Minute"))
## 76 Beats Per Minute
The quantile() function is used to identify the different percentiles of the data. For example, 25% of the values are below 68 BPM. On the other extreme, 25% of the values are above 80 BPM.
quart2<-quantile(sampledata[femaleid,3],probs = seq(0.25, 0.75, 0.25))
quart2
## 25% 50% 75%
## 68 76 80
The female resting heart rates differs slightly from a classic normal distribution. Most of the data clusters around the 75-80 BPM range. Meanwhile though, the average female resting heart rate sits slightly below that at 74 BPM.
histo2<-hist(sampledata[femaleid,3],col = "pink", main = "Histogram of Female Resting Heart Rates", xlab = "Beats Per Minute")
The normal probability plot further shows that the female resting heart rate slightly deviates from a classic normal distribution.
norm2<-qqnorm(sampledata[femaleid,3], main = "Normal Probability Plot for Female Resting Heart Rates", ylab = "Beats Per Minute", col = "pink", xlab = "Theoretical Quantiles")
ref2<-qqline(sampledata[femaleid,3], col = "green")
When comparing the male and female box plots, the most obvious difference is the thickness of the boxes. The 25th and 75th percentile for males is much more condensed when compared to females. Another thing to notice is that the whiskers for males are also more condensed than females. This suggests that there is a lot more variance with female heart rates compared to male heart rates.
box<-boxplot(sampledata[maleid,3], sampledata[femaleid,3], names = c("Male", "Female"), ylab = "Beats Per Minute", col = c("blue", "pink"), main = "M and F Box & Whisker Plots for Resting Heart Rate")
# Data Import
sampledata<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv")
rmarkdown::paged_table(sampledata)
sampledata$Sex<-as.factor(sampledata$Sex)
sampledata$Beats<-as.numeric(sampledata$Beats)
# Descriptive Statistics (Males)
## Minimum Heart Rate
maleid<-sampledata$Sex==1
min1<-min(sampledata[maleid,3])
cat(paste(min1, "Beats Per Minute"))
## Maximum Heart Rate
max1<-max(sampledata[maleid,3])
cat(paste(max1, "Beats Per Minute"))
## Average Heart Rate
avg1<-round(mean(sampledata[maleid,3]),3)
cat(paste(avg1, "Beats Per Minute"))
## Heart Rate Standard Deviation
stddev1<-round(sd(sampledata[maleid,3]),3)
cat(paste(stddev1, "Beats Per Minute"))
## Median Heart Rate
med1<-median(sampledata[maleid,3])
cat(paste(med1, "Beats Per Minute"))
## Quartiles
quart1<-quantile(sampledata[maleid,3],probs = seq(0.25, 0.75, 0.25))
quart1
# Data Plots (Males)
## Histogram
histo1<-hist(sampledata[maleid,3],col = "blue", main = "Histogram of Male Resting Heart Rates", xlab = "Beats Per Minute")
## Normal Probability Plot
norm1<-qqnorm(sampledata[maleid,3], main = "Normal Probability Plot for Male Resting Heart Rates", ylab = "Beats Per Minute", col = "blue", xlab = "Theoretical Quantiles")
ref1<-qqline(sampledata[maleid,3], col = "red")
# Descriptive Statistics (Females)
## Minimum Heart Rate
femaleid<-sampledata$Sex==2
min2<-min(sampledata[femaleid,3])
cat(paste(min2, "Beats Per Minute"))
## Maximum Heart Rate
max2<-max(sampledata[femaleid,3])
cat(paste(max2, "Beats Per Minute"))
## Average Heart Rate
avg2<-round(mean(sampledata[femaleid,3],),3)
cat(paste(avg2, "Beats Per Minute"))
## Heart Rate Standard Deviation
stddev2<-round(sd(sampledata[femaleid,3]),3)
cat(paste(stddev2, "Beats Per Minute"))
## Median Heart Rate
med2<-median(sampledata[femaleid,3])
cat(paste(med2, "Beats Per Minute"))
## Quartiles
quart2<-quantile(sampledata[femaleid,3],probs = seq(0.25, 0.75, 0.25))
quart2
# Data Plots (Females)
## Histogram
histo2<-hist(sampledata[femaleid,3],col = "pink", main = "Histogram of Female Resting Heart Rates", xlab = "Beats Per Minute")
## Normal Probability Plot
norm2<-qqnorm(sampledata[femaleid,3], main = "Normal Probability Plot for Female Resting Heart Rates", ylab = "Beats Per Minute", col = "pink", xlab = "Theoretical Quantiles")
ref2<-qqline(sampledata[femaleid,3], col = "green")
# Box Plot Comparison
box<-boxplot(sampledata[maleid,3], sampledata[femaleid,3], names = c("Male", "Female"), ylab = "Beats Per Minute", col = c("blue", "pink"), main = "M and F Box & Whisker Plots for Resting Heart Rate")