This is the R command using for our final research about

RESEARCH ON BIRTHDAYS, HEIGHT, WEIGHT, AND TIME FOR DOING EXERCISE OF 21ES AND 21ECE STUDENTS

OUTLINE

For this part, we will discussing through each feature:

1/ Overview our data

2/ Birthday

3/ Height and Weight

4/ Time for doing exercise

Requirment for this code

In order to finish our project, we need to install some library

#install.packages("readxl")
#install.packages("ggplot2")
#install.packages("lubridate") 
library(readxl) #for read excel
library(ggplot2) # for plot
library(grid)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union

That’s all, so now, let’s go:

1/ Overview

First, loading data from excel file to R

setwd("C:/Work_places/SXTK/Final_Report/Descriptive_statistics")
data <- read_excel("Data_Statistic.xlsx")
data$Birthdays <- dmy(data$Birthdays)
## Warning: 2 failed to parse.
dim(data)
## [1] 60  5
head(data)
## # A tibble: 6 × 5
##   Class Birthdays  Height Weight `Time for doing exercise(minutes)`
##   <chr> <date>      <dbl>  <dbl>                              <dbl>
## 1 21ECE 2003-10-09    169   54                                   10
## 2 21ECE 2003-07-15    182   88                                   15
## 3 21ECE 2003-08-14    160   55.2                                 60
## 4 21ECE 2003-09-07    162   62.3                                 60
## 5 21ECE 2003-03-20    163   47                                   10
## 6 21ECE 2003-06-02    178   61                                   30

Our data –> contain 60 observation ( 21ES and 21ECE student) with 5 variables(Birthday, Height, Weight, Time doing exercise)

2/ Date of birth

Birthday includes date, month, and year, but we only consider the case of students with the same date of birth and month of birth

The histogram of birth month of 3 classes

# Create a new column for the month
data$Month <- month(data$Birthdays)

ggplot(data, aes(x = format(Birthdays, "%m"), fill = Class)) +
  geom_bar(position = "stack", color = "black", alpha = 0.7) +
  labs(title = "Number of Student Birthdays (Months) for 21ES and 21ECE classes",
       x = "Month",
       y = "Number") +
  scale_fill_brewer(palette = "Set3") +
  theme_minimal()

Comment : October the months which have the most frequency (12 times)

The probability with at least k (2, 3, 4…) students in 21ES and 21ECE have the same birthday

#code here

Comment

** Explain **

3/ Weight

Summary

summary(data$Height)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   155.0   165.0   170.0   170.4   175.0   183.0

Histogram for weight

#histogram of Weight
ggplot(data, aes(x = Weight, fill = Class)) +
  geom_histogram(binwidth = 5, position = "stack", color = "black", alpha = 0.5) +
  geom_density(aes(y = ..count.. * 5), fill = "transparent", color = "red") +
  labs(title = "Histogram of Weight",
       x = "Weight(kg)",
       y = "Number") +
  scale_fill_brewer(palette = "Set3")  # Lựa chọn màu sắc cho từng lớp
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

# 2 histo của 2 lớp cho weight
ggplot(data, aes(x = Weight, fill = Class)) +
  geom_histogram(binwidth = 5, position = "stack", color = "black", alpha = 0.7) +
  geom_density(aes(y = ..count.. * 5), fill = "transparent", color = "red") +
  labs(title = "Histogram of Weight",
       x = "Weight(kg)",
       y = "Number") +
  scale_fill_brewer(palette = "Set3") +  # Lựa chọn màu sắc cho từng lớp
  facet_grid(Class ~ ., scales = "free_y")   # Hiển thị theo cột "Class"

Comment

Boxplot

#boxplot for weight
ggplot(data, aes(x = Weight, y = Class)) +
  geom_boxplot(width = 0.3, fill = "slateblue", color = "black", position = position_dodge(width = 0.7)) +
  geom_point(position = position_dodge(width = 0.7), color = "red", size = 2) +
  labs(title = "Boxplot of Weight",
       x = "Weight(kg)",
       y = "Class") +
  theme_minimal()

Comment

4/ Height

Summary

summary(data$Height)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   155.0   165.0   170.0   170.4   175.0   183.0

Histogram for Height

ggplot(data, aes(x = Height, fill = Class)) +
  geom_histogram(binwidth = 5, position = "stack", color = "black", alpha = 0.7) +
  geom_density(aes(y = ..count.. * 5), fill = "transparent", color = "red") +
  labs(title = "Histogram of Height of 21ES and 21ECE classes",
       x = "Height(cm)",
       y = "Number") +
  scale_fill_brewer(palette = "Set3")  # Lựa chọn màu sắc cho từng lớp

# 2 histo của 2 lớp cho height
ggplot(data, aes(x = Height, fill = Class)) +
  geom_histogram(binwidth = 5, position = "stack", color = "black", alpha = 0.7) +
  geom_density(aes(y = ..count.. * 5), fill = "transparent", color = "red") +
  labs(title = "Histogram of Height",
       x = "Height(kcm)",
       y = "Number") +
  scale_fill_brewer(palette = "Set3") +  # Lựa chọn màu sắc cho từng lớp
  facet_grid(Class ~ ., scales = "free_y")   # Hiển thị theo cột "Class"

Comment

Boxplot

#boxplot for height
ggplot(data, aes(x = Height, y = Class)) +
  geom_boxplot(width = 0.3, fill = "slateblue", color = "black", position = position_dodge(width = 0.7)) +
  geom_point(position = position_dodge(width = 0.7), color = "red", size = 2) +
  labs(title = "Boxplot of Height",
       x = "Height(cm)",
       y = "Class") +
  theme_minimal()

Comment

Height and weight

ggplot(data, aes(x = Height, y = Weight, color = Class)) +
  geom_point(alpha = 0.7) +
  geom_point() +
  geom_smooth(method="lm")+
  labs(title = "Distribution of Height and Weight",
       x = "Height(cm)",
       y = "Weight(kg)") +
  scale_color_manual(values = c("red","blue"))
## `geom_smooth()` using formula = 'y ~ x'

Comment

5/ Time for doing exercise

Summary

summary(data$`Time for doing exercise(minutes)`)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.00   10.00   30.00   33.75   50.00  120.00

Time and weight

# scatter plot weight and time 
ggplot(data, aes(x = Weight, y = `Time for doing exercise(minutes)`, color = Class)) +
  geom_point(alpha = 0.7) +
  geom_point() +
  geom_smooth(method="lm")+
  labs(title = "Distribution of weight and time spend for exercise",
       x = "Weight(kg)",
       y = "Time for doing exercise(minuteS)") +
  scale_color_manual(values = c("red","blue"))
## `geom_smooth()` using formula = 'y ~ x'

Time and Height

# scatter plot Height and time 
ggplot(data, aes(x = Height, y = `Time for doing exercise(minutes)`, color = Class)) +
  geom_point(alpha = 0.7) +
  geom_point() +
  geom_smooth(method="lm")+
  labs(title = "Distribution of Height and time spend for exercise",
       x = "Height(cm)",
       y = "Time for doing exercise(minuteS)") +
  scale_color_manual(values = c("red","blue"))
## `geom_smooth()` using formula = 'y ~ x'

Comment

THE END