library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'readr' was built under R version 4.3.3
## Warning: package 'purrr' was built under R version 4.3.1
## Warning: package 'dplyr' was built under R version 4.3.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library (readxl)
## Warning: package 'readxl' was built under R version 4.3.3
library (ggplot2)
library (DescTools)
## Warning: package 'DescTools' was built under R version 4.3.3
library(epitools)
## Warning: package 'epitools' was built under R version 4.3.1
library(caret)
## Warning: package 'caret' was built under R version 4.3.3
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 4.3.1
##
## Attaching package: 'caret'
##
## The following objects are masked from 'package:DescTools':
##
## MAE, RMSE
##
## The following object is masked from 'package:purrr':
##
## lift
library(DT)
## Warning: package 'DT' was built under R version 4.3.3
Dữ liệu sử dụng trong bài nghiên cứu được lấy từ tác giả Kane Rudolph trên trang web kaggle.com.
Dữ liệu được thu thập bằng cách khảo sát sinh viên Hoa Kỳ đang theo học ở các cấp học khác nhau như trung học, đại học và thạc sĩ. Tổng cộng có 352 sinh viên được đưa vào nghiên cứu. Dữ liệu được thu thập từ các sinh viên bằng phương pháp câu hỏi với sự đồng ý có hiểu biết.
Data <- read_excel("C:/Users/Dell/Downloads/Data (2).xlsx")
str (Data)
## tibble [352 × 14] (S3: tbl_df/tbl/data.frame)
## $ Gender : chr [1:352] "Male" "Male" "Female" "Female" ...
## $ Age : num [1:352] 22 22 17 18 19 26 23 21 21 22 ...
## $ Education : chr [1:352] "College - Bachelor's" "College - Bachelor's" "High School" "High School" ...
## $ Pleasureinthings : num [1:352] 3 2 2 3 1 1 2 3 3 3 ...
## $ Feelingdown : num [1:352] 2 1 2 1 2 2 2 3 1 4 ...
## $ Littleenergy : num [1:352] 4 1 2 3 3 4 3 3 3 2 ...
## $ Feelingbadyourself: num [1:352] 3 1 1 1 1 1 1 3 2 3 ...
## $ Hurtingyourself : num [1:352] 2 1 1 2 1 1 1 3 1 2 ...
## $ Job : chr [1:352] "Yes" "Yes" "No" "No" ...
## $ Accommodation : chr [1:352] "Home (with parents)" "Private rented accommodation" "Home (with parents)" "Home (with parents)" ...
## $ Selfstudy : chr [1:352] "2 - 4 hours" "1 - 2 hours" "1 - 2 hours" "1 - 2 hours" ...
## $ Media : chr [1:352] "More than 4 Hours" "1 - 2 Hours" "More than 4 Hours" "2 - 4 Hours" ...
## $ GPA : num [1:352] 2.3 2.7 2.97 2.74 3.37 3.33 2.75 3.25 3.97 2.75 ...
## $ Depression : chr [1:352] "Yes" "Yes" "No" "No" ...
Bộ dữ liệu gồm có 14 biến. Trong đó có 7 biến định tính và 7 biến định lượng:
Biến Gender - Giới tính của sinh viên, gồm 2 giá trị Male (Nam) hoặc Female (Nữ).
Biến Age - Tuổi của sinh viên.
Accommodation - Nơi ở hiện tại của sinh viên, gồm 2 giá trị: Home with parents (Tại nhà với gia đình) và Private rented accommodation (Phòng trọ tư nhân).
Biến EducationL Trình độ học vấn hiện tại, gồm 3 giá trị - High School (Trung học phổ thông), College - Bachelor’s (Đại học) và Master (Thạc sĩ).
Biến Selfstudy - Số giờ tự học mỗi ngày, gồm 3 giá trị: 1 - 2 hours (từ 1 đến 2 tiếng), 2 - 4 hours (từ 2 đến 4 tiếng) và More than 4 hours (hơn 4 tiếng).
Biến Job - hiện tại có đi làm hay không, gồm 2 giá trị: Yes hoặc No
Biến Media - số giờ dành cho phương tiện truyền thông mỗi ngày, gồm 3 giá trị: 1 - 2 hours (từ 1 đến 2 tiếng), 2 - 4 hours (từ 2 đến 4 tiếng) và More than 4 hours (hơn 4 tiếng).
Biến Pleasureinthings - Ít hứng thú hoặc niềm vui trong công việc, gồm 4 mức độ: 1 (Chưa bao giờ), 2(Thi thoảng), 3 (Thường xuyên), 4 (Luôn luôn).
Biến Littleenergy - Cảm thấy mệt mỏi hoặc có ít năng lượng, gồm 4 mức độ tương tự như biến Pleasureinthings.
Biến Feelingbadyourself - Cảm thấy tồi tệ về bản thân hoặc rằng bạn là một kẻ thất bại hoặc đã không làm bản thân hoặc gia đình thất vọng, gồm 4 mức độ tương tự như biến Pleasureinthings.
Biến Feelingdown - Cảm thấy thất vọng, chán nản, hoặc vô vọng, gồm 4 mức độ tương tự như biến Pleasureinthings.
Biến Hurtingyourself - Suy nghĩ rằng bạn nên chết đi hoặc làm tổn thương chính mình theo một cách nào đó, gồm 4 mức độ tương tự như biến Pleasureinthings.
Biến GPA - Điểm số tích luỹ hiện tại tính theo thang điểm 4.
Biến Depression - Sinh viên có biểu hiện trầm cảm hay không, gồm 2 giá trị: Yes hoặc No.
dnt <- Data[,c("Gender","Accommodation","Education","Selfstudy","Job","Media","Depression")]
Gender - Giới tính
table(Data$Gender)
##
## Female Male
## 313 39
prop.table(table(Data$Gender))
##
## Female Male
## 0.8892045 0.1107955
Trong tổng số 352 học sinh sinh viên tham gia khảo sát thì có đến 313 sinh viên nữ (chiếm gần 89%) và 39 sinh viên nam (chiếm 11%).
ggplot(Data,aes(Gender))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Gender")
Education - Trình độ học vấn
table(Data$Education)
##
## College - Bachelor's High School Master
## 204 124 24
prop.table(table(Data$Education))
##
## College - Bachelor's High School Master
## 0.57954545 0.35227273 0.06818182
Kết quả khảo sát 352 học sinh sinh viên cho thấy :
Có 204 sinh viên đang theo học đại học (college - Bachelor’s) chiếm tỉ lệ 58%
Có 124 học sinh đang học trung học phổ thông (High School) chiếm tỉ lệ 35%
Có 24 sinh viên đang theo học thạc sĩ (Master) chiếm tỉ lệ 7%
ggplot(Data,aes(Education))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Education")
Job - Công việc hiện tại
table(Data$Job)
##
## No Yes
## 119 233
prop.table(table(Data$Job))
##
## No Yes
## 0.3380682 0.6619318
Trong tổng số những người được khảo sát (352 người) thì có đến 66% người có việc làm bao gồm cả công việc full-tim và part-time (tương đương với 233 học sinh sinh viên) và có khoảng 34% (tương đương với 119 học sinh sinh viên) không đi làm.
ggplot(Data,aes(Job))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Job")
Accommodation - Nơi ở hiện tại
table(Data$Accommodation)
##
## Home (with parents) Private rented accommodation
## 155 197
prop.table(table(Data$Accommodation))
##
## Home (with parents) Private rented accommodation
## 0.4403409 0.5596591
Theo kết quả của bảng khảo sát 352 học sinh sinh viên thì có :
155 học sinh sinh viên sống chung với gia đình chiếm 44%
197 học sinh sinh viên ở tại các phòng trọ tư nhân chiếm 56%
Đa số học sinh sinh viên có xu hướng ở các phòng trọ tư nhân hơn là sống chung với gia đình
ggplot(Data,aes(Accommodation))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Accommodation")
Selfstudy - Thời gian tự học mỗi ngày
table(Data$Selfstudy)
##
## 1 - 2 hours 2 - 4 hours More than 4 hours
## 201 99 52
prop.table(table(Data$Selfstudy))
##
## 1 - 2 hours 2 - 4 hours More than 4 hours
## 0.5710227 0.2812500 0.1477273
Theo kết quả khảo sát cho thấy đa số học sinh sinh viên (khoảng 57%) dành thời gian từ 1-2 tiếng để học mỗi ngày ( tương đương với 200 học sinh sinh viên), có khoảng 28% (tương đương với 99 học sinh sinh viên) dành thời gian từ 2-4 tiếng để học mỗi ngày và có khoảng 15% (tương đương với 53 học sinh sinh viên) dành nhiều hơn 4 tiếng để học trong một ngày.
ggplot(Data,aes(Selfstudy))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Selfstudy")
Media - Thời gian dành cho phương tiện truyền thông
table(Data$Media)
##
## 1 - 2 Hours 2 - 4 Hours More than 4 Hours Not Applicable
## 38 112 197 5
prop.table(table(Data$Media))
##
## 1 - 2 Hours 2 - 4 Hours More than 4 Hours Not Applicable
## 0.10795455 0.31818182 0.55965909 0.01420455
ggplot(Data, aes(x = "", fill = Media)) +
geom_bar(color = "blue", width = 1, stat = "count") +
coord_polar("y", start = 0) +
ylab("Number of Students") +
xlab("Media")
Depression - Trầm cảm
table(Data$Depression)
##
## No Yes
## 206 146
prop.table(table(Data$Depression))
##
## No Yes
## 0.5852273 0.4147727
ggplot(Data,aes(Depression))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Depression")
mac <-data.frame(Data$Age, Data$Pleasureinthings, Data$Feelingdown, Data$Littleenergy, Data$Feelingbadyourself, Data$Hurtingyourself, Data$GPA)
summary(mac)
## Data.Age Data.Pleasureinthings Data.Feelingdown Data.Littleenergy
## Min. :17.00 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:19.00 1st Qu.:2.000 1st Qu.:1.000 1st Qu.:2.000
## Median :22.00 Median :2.000 Median :2.000 Median :3.000
## Mean :21.97 Mean :2.389 Mean :2.236 Mean :2.852
## 3rd Qu.:24.00 3rd Qu.:3.000 3rd Qu.:3.000 3rd Qu.:4.000
## Max. :28.00 Max. :4.000 Max. :4.000 Max. :4.000
## Data.Feelingbadyourself Data.Hurtingyourself Data.GPA
## Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:2.300
## Median :2.000 Median :1.000 Median :3.350
## Mean :2.432 Mean :1.577 Mean :3.009
## 3rd Qu.:3.000 3rd Qu.:2.000 3rd Qu.:3.350
## Max. :4.000 Max. :4.000 Max. :4.000
dnl <- Data[,c("Age","Pleasureinthings","Littleenergy","Feelingbadyourself","Feelingdown","Hurtingyourself","GPA")]
Age - Tuổi
summary(Data$Age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 17.00 19.00 22.00 21.97 24.00 28.00
sd(Data$Age)
## [1] 3.21924
table(Data$Age)
##
## 17 18 19 20 21 22 23 24 25 26 27 28
## 32 23 46 31 26 44 34 40 14 18 26 18
prop.table(table(Data$Age))
##
## 17 18 19 20 21 22 23
## 0.09090909 0.06534091 0.13068182 0.08806818 0.07386364 0.12500000 0.09659091
## 24 25 26 27 28
## 0.11363636 0.03977273 0.05113636 0.07386364 0.05113636
ggplot(Data,aes(Age))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Age")
Pleasureinthings - Mức độ cảm thấy ít hứng thú với việc mình làm
summary(Data$Pleasureinthings)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.000 2.000 2.389 3.000 4.000
table(Data$Pleasureinthings)
##
## 1 2 3 4
## 55 147 108 42
prop.table(table(Data$Pleasureinthings))
##
## 1 2 3 4
## 0.1562500 0.4176136 0.3068182 0.1193182
ggplot(Data,aes(Pleasureinthings))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Pleasureinthings")
Feelingdown - Mức độ cảm thấy chán nản, thất vọng
summary(Data$Feelingdown)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 1.000 2.000 2.236 3.000 4.000
table(Data$Feelingdown)
##
## 1 2 3 4
## 100 120 81 51
prop.table(table(Data$Feelingdown))
##
## 1 2 3 4
## 0.2840909 0.3409091 0.2301136 0.1448864
ggplot(Data,aes(Feelingdown))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Feelingdown")
Littleenergy - Mức độ cảm thấy mệt mỏi hoặc có ít năng lượng
summary(Data$Littleenergy)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.000 3.000 2.852 4.000 4.000
table(Data$Littleenergy)
##
## 1 2 3 4
## 36 99 98 119
prop.table(table(Data$Littleenergy))
##
## 1 2 3 4
## 0.1022727 0.2812500 0.2784091 0.3380682
ggplot(Data,aes(Littleenergy))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Littleenergy")
Feelingbadyourself - Mức độ cảm thấy tồi tệ về bản thân
summary(Data$Feelingbadyourself)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 1.000 2.000 2.432 3.000 4.000
table(Data$Feelingbadyourself)
##
## 1 2 3 4
## 93 92 89 78
prop.table(table(Data$Feelingbadyourself))
##
## 1 2 3 4
## 0.2642045 0.2613636 0.2528409 0.2215909
ggplot(Data,aes(Feelingbadyourself))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Feelingbadyourself")
Hurtingyourself - Mức độ suy nghĩ đến cái chết hoặc tự làm tổn thương mình
summary(Data$Hurtingyourself)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 1.000 1.000 1.577 2.000 4.000
prop.table(table(Data$Hurtingyourself))
##
## 1 2 3 4
## 0.65625000 0.18465909 0.08522727 0.07386364
ggplot(Data,aes(Hurtingyourself))+
geom_bar(color = "blue", fill = "skyblue")+
geom_text(aes(label = scales :: percent(after_stat(count/sum(count)))), stat= 'count', color = 'black', vjust = -.5)+
ylab("Number of Students")+ xlab("Hurtingyourself")
GPA - Điểm số tích luỹ hiện tại tính theo thang điểm 4
summary(Data$GPA)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.300 3.350 3.009 3.350 4.000
sd(Data$GPA)
## [1] 0.760909
table(Data$GPA)
##
## 1 1.3 2 2.2 2.25 2.3 2.32 2.4 2.47 2.5 2.7 2.73 2.74 2.75 2.78 2.83
## 2 21 1 1 2 91 1 1 1 1 1 1 1 10 1 1
## 2.85 2.87 2.97 2.98 3.05 3.1 3.15 3.2 3.23 3.24 3.25 3.27 3.33 3.35 3.37 3.41
## 1 1 5 1 1 1 1 1 1 1 6 2 1 112 2 1
## 3.42 3.5 3.54 3.7 3.73 3.75 3.76 3.84 3.89 3.93 3.97 3.98 4
## 1 1 1 2 1 4 2 1 1 1 1 1 60
prop.table(table(Data$GPA))
##
## 1 1.3 2 2.2 2.25 2.3
## 0.005681818 0.059659091 0.002840909 0.002840909 0.005681818 0.258522727
## 2.32 2.4 2.47 2.5 2.7 2.73
## 0.002840909 0.002840909 0.002840909 0.002840909 0.002840909 0.002840909
## 2.74 2.75 2.78 2.83 2.85 2.87
## 0.002840909 0.028409091 0.002840909 0.002840909 0.002840909 0.002840909
## 2.97 2.98 3.05 3.1 3.15 3.2
## 0.014204545 0.002840909 0.002840909 0.002840909 0.002840909 0.002840909
## 3.23 3.24 3.25 3.27 3.33 3.35
## 0.002840909 0.002840909 0.017045455 0.005681818 0.002840909 0.318181818
## 3.37 3.41 3.42 3.5 3.54 3.7
## 0.005681818 0.002840909 0.002840909 0.002840909 0.002840909 0.005681818
## 3.73 3.75 3.76 3.84 3.89 3.93
## 0.002840909 0.011363636 0.005681818 0.002840909 0.002840909 0.002840909
## 3.97 3.98 4
## 0.002840909 0.002840909 0.170454545
hist(Data$GPA)