1 Assignment on Data Reading and Writing

The CSV file was read into R from the GitHub link. Converted the data of Sex as a factor. This was shown in the following Code chunk.

data<- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv")

head(data)
##   Temp Sex Beats
## 1 96.3   1    70
## 2 96.7   1    71
## 3 96.9   1    74
## 4 97.0   1    80
## 5 97.1   1    73
## 6 97.1   1    75
str(data)
## 'data.frame':    130 obs. of  3 variables:
##  $ Temp : num  96.3 96.7 96.9 97 97.1 97.1 97.1 97.2 97.3 97.4 ...
##  $ Sex  : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Beats: int  70 71 74 80 73 75 82 64 69 70 ...
data$Sex<- as.factor(data$Sex)
str(data)
## 'data.frame':    130 obs. of  3 variables:
##  $ Temp : num  96.3 96.7 96.9 97 97.1 97.1 97.1 97.2 97.3 97.4 ...
##  $ Sex  : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Beats: int  70 71 74 80 73 75 82 64 69 70 ...

1.1 Data of Males

Performed Descriptive Stats on data of males.

  • Summary (Min, Max, Mean, Median, SD, Quartiles)
male<- data[data$Sex==1,]
summary(male$Beats)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   58.00   70.00   73.00   73.37   78.00   86.00
sd(male$Beats)
## [1] 5.875184
  • Histogram on Male Heart Beats
hist(male$Beats, main = "Male Heart Beats", xlab ="Male", col = "blue")

Comment: The histogram depicted as a bell-curve with the mean value 73.7 of male heart beats.

  • Normal Probability Plot
qqnorm(male$Beats, main="Normal Probability Plot for Male")

Comment: The normal probability plot shows that at the region -1 to 1 has the denser data.

1.2 Data of Females

Performed Descriptive Stats on data of females.

  • Summary (Min, Max, Mean, Median, SD, Quartiles)
Female<- data[data$Sex==2,]
summary(Female$Beats)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   57.00   68.00   76.00   74.15   80.00   89.00
sd(Female$Beats)
## [1] 8.105227
  • Histogram on Male Heart Beats
hist(Female$Beats, main = "Female Heart Beats", xlab ="Female", col = "pink")

Comment: The histogram of female heartbeats shows a bit different from the male one, as the mean value is bit higher with 74.15, and the standard deviation is as high as 8.73.

  • Normal Probability Plot
qqnorm(Female$Beats, main="Normal Probability Plot for Female")

Comment: Similarly we found that the normal probability of female heart beats has more variability compared to male heart beats.

1.3 Boxplot for Male and Female

boxplot(male$Beats,Female$Beats, names =  c("Male","Female"), main= "Male and 
        Female Heartbeats", ylab = "Heart Beats")

Comment: The boxplot shows the comparison between the male and female heartbeats. It can be observed that the male data has smaller quartile region compared to female data. Mean of male is closer to 1st quartile whereas in female data the mean value is more close to 3rd quartile. The minimum value of heart beats for both male and female are similar.

2 Complete R Code

data<- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/normtemp.csv")

data
str(data)
data$Sex<- as.factor(data$Sex)
str(data)


#Male Calculation
male<- data[data$Sex==1,]

summary(male$Beats)
sd(male$Beats)
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#58.00   70.00   73.00   73.37   78.00   86.00 
# sd(male$Beats)
#5.875184

hist(male$Beats, main = "Male Heart Beats", xlab ="Male", col = "blue")
qqnorm(male$Beats, main="Normal Probability Plot for Male")

#Female Calculation
Female<- data[data$Sex==2,]

summary(Female$Beats)
sd(Female$Beats)


hist(Female$Beats, main = "Female Heart Beats", xlab ="Female", col = "pink")
qqnorm(Female$Beats, main="Normal Probability Plot for Female")

#Boxplot for male and female

boxplot(male$Beats,Female$Beats, names =  c("Male","Female"), main= "Male and 
        Female Heartbeats", ylab = "Heart Beats")