library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── 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
burnout <-read_csv("student_mental_health_burnout_1M-selected-columns-3.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 1000000 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): gender
## dbl (9): age, academic_year, study_hours_per_day, exam_pressure, academic_pe...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dim(burnout)
## [1] 1000000 10
head(burnout)
## # A tibble: 6 × 10
## age gender academic_year study_hours_per_day exam_pressure
## <dbl> <chr> <dbl> <dbl> <dbl>
## 1 23 Male 2 5.60 6.49
## 2 20 Male 3 5.60 5.63
## 3 29 Male 2 2.58 6.02
## 4 27 Male 4 4.61 6.68
## 5 24 Male 4 2.19 4.01
## 6 29 Female 3 7.70 8.46
## # ℹ 5 more variables: academic_performance <dbl>, stress_level <dbl>,
## # anxiety_score <dbl>, depression_score <dbl>, sleep_hours <dbl>
tail(burnout)
## # A tibble: 6 × 10
## age gender academic_year study_hours_per_day exam_pressure
## <dbl> <chr> <dbl> <dbl> <dbl>
## 1 20 Female 4 6.28 6.78
## 2 22 Female 3 5.78 4.92
## 3 20 Male 1 3.80 4.71
## 4 24 Female 3 8.81 8.75
## 5 29 Female 4 5.92 6.68
## 6 17 Female 2 5.73 6.06
## # ℹ 5 more variables: academic_performance <dbl>, stress_level <dbl>,
## # anxiety_score <dbl>, depression_score <dbl>, sleep_hours <dbl>
str(burnout)
## spc_tbl_ [1,000,000 × 10] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ age : num [1:1000000] 23 20 29 27 24 29 21 23 26 19 ...
## $ gender : chr [1:1000000] "Male" "Male" "Male" "Male" ...
## $ academic_year : num [1:1000000] 2 3 2 4 4 3 3 2 4 3 ...
## $ study_hours_per_day : num [1:1000000] 5.6 5.6 2.58 4.61 2.19 ...
## $ exam_pressure : num [1:1000000] 6.49 5.63 6.02 6.68 4.01 ...
## $ academic_performance: num [1:1000000] 68.4 67.7 58.4 68.9 69.1 ...
## $ stress_level : num [1:1000000] 4.117 0.349 3.476 6.779 1.855 ...
## $ anxiety_score : num [1:1000000] 2.28 0 2.43 4.51 1.1 ...
## $ depression_score : num [1:1000000] 1.987 0 0.852 4.286 0 ...
## $ sleep_hours : num [1:1000000] 6.88 7.46 8.95 4.57 5.99 ...
## - attr(*, "spec")=
## .. cols(
## .. age = col_double(),
## .. gender = col_character(),
## .. academic_year = col_double(),
## .. study_hours_per_day = col_double(),
## .. exam_pressure = col_double(),
## .. academic_performance = col_double(),
## .. stress_level = col_double(),
## .. anxiety_score = col_double(),
## .. depression_score = col_double(),
## .. sleep_hours = col_double()
## .. )
## - attr(*, "problems")=<pointer: 0x7fac110fe5a0>
select(burnout,"study_hours_per_day", "sleep_hours")
## # A tibble: 1,000,000 × 2
## study_hours_per_day sleep_hours
## <dbl> <dbl>
## 1 5.60 6.88
## 2 5.60 7.46
## 3 2.58 8.95
## 4 4.61 4.57
## 5 2.19 5.99
## 6 7.70 6.57
## 7 7.01 3.66
## 8 6.95 7.36
## 9 6.54 5.16
## 10 5.29 6.28
## # ℹ 999,990 more rows
studysleep <-select(burnout,"study_hours_per_day", "sleep_hours")
dim(studysleep)
## [1] 1000000 2
summary(studysleep)
## study_hours_per_day sleep_hours
## Min. : 0.000 Min. : 3.000
## 1st Qu.: 3.651 1st Qu.: 5.491
## Median : 4.998 Median : 6.502
## Mean : 5.002 Mean : 6.502
## 3rd Qu.: 6.346 3rd Qu.: 7.515
## Max. :14.000 Max. :10.000
## NAs :1
plot(studysleep)

ggplot(studysleep, aes(x = study_hours_per_day, y = sleep_hours)) +
geom_point(alpha = 0.3) +
labs(title = "Study Hours vs. Sleep Hours",
x = "Study", y = "Sleep") +
theme_minimal()
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

plot(studysleep)

mean(studysleep$study_hours_per_day)
## [1] 5.001727
avgstudy <- mean(studysleep$study_hours_per_day)
avgsleep <- mean(studysleep$sleep_hours)
hist(studysleep$sleep_hours)

hist(studysleep$study_hours_per_day)

summary_df <- burnout %>%
group_by(study_hours_per_day, sleep_hours) %>%
summarise(
avg_studyhours = mean(study_hours_per_day),
total_count = n(),
.groups = "drop"
)
print(summary_df)
## # A tibble: 999,868 × 4
## study_hours_per_day sleep_hours avg_studyhours total_count
## <dbl> <dbl> <dbl> <int>
## 1 0 3 0 72
## 2 0 3.01 0 1
## 3 0 3.02 0 1
## 4 0 3.02 0 1
## 5 0 3.03 0 1
## 6 0 3.05 0 1
## 7 0 3.07 0 1
## 8 0 3.08 0 1
## 9 0 3.10 0 1
## 10 0 3.11 0 1
## # ℹ 999,858 more rows
stuslee <- lm(studysleep$study_hours_per_day ~ studysleep$sleep_hours, data = studysleep)
print(stuslee)
##
## Call:
## lm(formula = studysleep$study_hours_per_day ~ studysleep$sleep_hours,
## data = studysleep)
##
## Coefficients:
## (Intercept) studysleep$sleep_hours
## 5.030644 -0.004447
ggplot(summary_df, aes(x = study_hours_per_day, y = sleep_hours)) +
geom_point(alpha = 0.4) +
labs(title = "Study vs. Sleep",
x = "Study", y = "Sleep") +
theme_minimal()
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

## After running various statistical tests on the relationship between study hours and sleep, there seems to be little relationship between these two variables. -0.004447 means that there is very little linear relationship between the predictor variable and outcome variable.