---
title: "Temperature and Heart Rate Comparison by Gender"
author: "Barry Monk"
date: "2023-09-12"
output: html_document
---

## Study

In a study, the biological gender, temperature (F), and heart rate were recorded for 553 people. There are several questions that we may ask:

What is the overall shape of the temperature data?

Is the mean temperature close to 98.6?

Is there a significant difference between temperatures for people born male and people born female? What about heart rates?

Describe differences in the shapes of distribution of heart rates: male vs. female

At what value should we consider a person's temperature to be abnormal? Is it different for males and females?

Does there appear to be a relationship between heart rate and temperature?

## Data

The data in this study is found at this link: [Temperature and Heart Rate by Gender](https://www.dropbox.com/s/q1ftto3riudivu4/temp_heartrate.csv?dl=1)

## Data Set Names

```{r}
library(readr)
library(dplyr)
TH<-read.csv("https://www.dropbox.com/s/q1ftto3riudivu4/temp_heartrate.csv?dl=1", header=T)
MTH <- filter(TH, Bio.Gender == 'male')
FTH <- filter(TH, Bio.Gender == 'female')

```

## Question: What is the overall shape of the temperature data?

```{r}
hist(TH$Body.Temp, main = "Overall Body Temperatures", xlab = "Temperature", ylab = "Frequency", col = "bisque2")
```

**Answer: Overall temperatures appear to be approximately symmetric. They also appear bell-shaped (normal). We can also take a look at a boxplot to determine shape:**

```{r}
boxplot(TH$Body.Temp, horizontal=T,col="bisque2")
```

**There is some skewness, but it doesn't appear very great. Temperatures appear more symmetric than skewed.**


## Question: Is the mean temperature close to 98.6?

```{r}
mean(TH$Body.Temp)
```

**Overall body temperature is 98.25, which is somewhat lower than 98.6.**


## Question: Is there a significant difference between temperatures for people born male and people born female? What about heart rates?

```{r}
mean(MTH$Body.Temp)
mean(FTH$Body.Temp)
```

**It appears that female body temperatures are slightly higher than male temperatures on average.**

```{r}
mean(MTH$Heart.Rate)
mean(FTH$Heart.Rate)
```

**It appears that female heart rates are higher than male heart rates.**

## Question: Describe differences in the shapes of distribution of heart rates: male vs. female

```{r}
hist(MTH$Heart.Rate, main = "Male Heart Rates", xlab = "Heart Rates", ylab = "Frequency", col= "honeydew3")
hist(FTH$Heart.Rate, main = "Female Heart Rates", xlab = "Heart Rates", ylab = "Frequency", col= "cornsilk")
```

**Looks like skewness in the female heart rates. Let's confirm with a boxplot.**

```{r}
boxplot(FTH$Heart.Rate,horizontal = T, col="salmon", pch=16, cex=1.5)
```

**Male heart rates appear mostly symmetric and bell-shaped. Female heart rates appear slightly skewed to the left.**



## Question: At what value should we consider a person's temperature to be abnormal? Is it different for males and females?

**Let's look at the overall mean and standard deviation:**
```{r}
all.mean <- mean(TH$Body.Temp)
all.mean
all.sd <- sd(TH$Body.Temp)
all.sd
```

**Let's say that anything beyond 3 standard deviations is unusual:**

```{r}
all.mean + 3*all.sd
```

**Our cut-off for what we consider to be abnormal is any temperature beyond 100.55.**

### Male Temperatures:

```{r}
M.mean <- mean(MTH$Body.Temp)
M.mean
M.sd <- sd(MTH$Body.Temp)
M.sd
```

**Let's say that anything beyond 3 standard deviations is unusual:**

```{r}
M.mean + 3*M.sd
```

**Any male temperature beyond 100.22 is considered abnormal.**

### Female Temperatures:

```{r}
F.mean <- mean(FTH$Body.Temp)
F.mean
F.sd <- sd(FTH$Body.Temp)
F.sd
```

**Let's say that anything beyond 3 standard deviations is unusual:**

```{r}
F.mean + 3*F.sd
```

**Any female temperature beyond 100.78 is considered abnormal.**

**The differences are not very great for male and female cut-off values.**


## Question: Does there appear to be a relationship between heart rate and temperature?

```{r}
plot(TH$Body.Temp, TH$Heart.Rate, pch=16, main="Body Temperature vs. Heart Rate", xlab = "Body Temperature", ylab = "Heart Rate", col="cadetblue")
```

**There may be a slight positive association between body temperature and heart rate. Let's find the correlation coefficient.**

```{r}
cor(TH$Body.Temp, TH$Heart.Rate)
```

**The positive linear association between body temperature and heart rate is somewhat weak. A correlation coefficient of 0.267 confirms this.**
