library(readr)
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
hr <- read_csv('https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv')
## Rows: 14999 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Department, salary
## dbl (8): satisfaction_level, last_evaluation, number_project, average_montly...
## 
## ℹ 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.

T-test One

t_test_satisfaction <- t.test(satisfaction_level ~ left, data = hr)
print("T-test for Satisfaction Level")
## [1] "T-test for Satisfaction Level"
print(t_test_satisfaction)
## 
##  Welch Two Sample t-test
## 
## data:  satisfaction_level by left
## t = 46.636, df = 5167, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  0.2171815 0.2362417
## sample estimates:
## mean in group 0 mean in group 1 
##       0.6668096       0.4400980

#technical interpretation: very significant significant

#nontechnical interpretation: There is a strong correlation between satisfaction level and the employees who left the company

ggplot(hr, aes(x = factor(left), y = satisfaction_level)) +
  geom_boxplot(fill = c("#F8766D", "#00BFC4"), alpha = 0.7) +
  stat_summary(fun = mean, geom = "point", shape = 18, color = "blue", size = 3) +
  labs(title = "Satisfaction Level by Employee Turnover Status",
       x = "Employee Left (0 = No, 1 = Yes)",
       y = "Satisfaction Level") +
  theme_minimal()

T-test Two

t_test_last_evaluation <- t.test(last_evaluation ~ left, data = hr)
  print("T-test for Last Evaluation")
## [1] "T-test for Last Evaluation"
  print(t_test_last_evaluation)
## 
##  Welch Two Sample t-test
## 
## data:  last_evaluation by left
## t = -0.72534, df = 5154.9, p-value = 0.4683
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.009772224  0.004493874
## sample estimates:
## mean in group 0 mean in group 1 
##       0.7154734       0.7181126

#technical interpretation: significant

#nontechnical interpretation: There is correlation between evaluation score and employees who left the company

 ggplot(hr, aes(x = factor(left), y = last_evaluation)) +
    geom_boxplot(fill = c("#F8766D", "#00BFC4"), alpha = 0.7) +
    stat_summary(fun = mean, geom = "point", shape = 18, color = "blue", size = 3) +
    labs(title = "Last Evaluation by Employee Turnover Status",
         x = "Employee Left (0 = No, 1 = Yes)",
         y = "Last Evaluation Score") +
    theme_minimal()

T-test Three

 t_test_number_project <- t.test(number_project ~ left, data = hr)
  print("T-test for Average Monthly Hours")
## [1] "T-test for Average Monthly Hours"
  print(t_test_number_project)
## 
##  Welch Two Sample t-test
## 
## data:  number_project by left
## t = -2.1663, df = 4236.5, p-value = 0.03034
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.131136535 -0.006540119
## sample estimates:
## mean in group 0 mean in group 1 
##        3.786664        3.855503

#technical interpretation: insignificant

#nontechnical interpretation: it is hard to say if there is direct correlation between the number of projects and employees who left

 ggplot(hr, aes(x = factor(left), y = number_project)) +
    geom_boxplot(fill = c("#F8766D", "#00BFC4"), alpha = 0.7) +
    stat_summary(fun = mean, geom = "point", shape = 18, color = "blue", size = 3) +
    labs(title = "Number of Projects by Employee Turnover Status",
         x = "Employee Left (0 = No, 1 = Yes)",
         y = "Number of Projects") +
    theme_minimal()

T-test Four

t_test_time_spent <- t.test(time_spend_company ~ left, data = hr)
  print("T-test for Time Spent at Company")
## [1] "T-test for Time Spent at Company"
  print(t_test_time_spent)
## 
##  Welch Two Sample t-test
## 
## data:  time_spend_company by left
## t = -22.631, df = 9625.6, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.5394767 -0.4534706
## sample estimates:
## mean in group 0 mean in group 1 
##        3.380032        3.876505

#technical interpretation: highly significant

#nontechnical interpretation: there is a strong correlation between number of years at the company and employees who left

 ggplot(hr, aes(x = factor(left), y = time_spend_company)) +
    geom_boxplot(fill = c("#F8766D", "#00BFC4"), alpha = 0.7) +
    stat_summary(fun = mean, geom = "point", shape = 18, color = "blue", size = 3) +
    labs(title = "Time Spent at Company by Employee Turnover Status",
         x = "Employee Left (0 = No, 1 = Yes)",
         y = "Years at Company") +
    theme_minimal()