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.
hr1 <- hr %>%
  mutate(Employee_Status = ifelse(left == 0, 'stayed', 'left'))

#T-Test 1

t.test(hr1$average_montly_hours ~ hr1$Employee_Status)
## 
##  Welch Two Sample t-test
## 
## data:  hr1$average_montly_hours by hr1$Employee_Status
## t = 7.5323, df = 4875.1, p-value = 5.907e-14
## alternative hypothesis: true difference in means between group left and group stayed is not equal to 0
## 95 percent confidence interval:
##   6.183384 10.534631
## sample estimates:
##   mean in group left mean in group stayed 
##             207.4192             199.0602

The employees that left on average work a greater number of hours than those who stayed.

Employees are less likely to stay at a company if they are forced to work more hours.

plot_ly(hr1 ,
        x= ~Employee_Status ,
        y= ~average_montly_hours ,
        type = 'box' ,
        color = ~Employee_Status ,
        colors= c('green', 'purple')
        )%>%
  layout(title = 'employees that left, on average, work more hours than those who stayed ')

#T-Test 2

t.test(hr1\(satisfaction_level ~ hr1\)Employee_Status)

Employees that left, on average, displayed a lower satisfaction level than those who stayed.

Employees who receive less satisfaction from their work are more likely to leave.

plot_ly(hr1 ,
        x= ~Employee_Status ,
        y= ~satisfaction_level ,
        type = 'box' ,
        color = ~Employee_Status ,
        colors= c('green', 'purple')
)%>%
  layout(title = 'employees that left, on average, displayed a lower satisfaction level than those who stayed ')

#T-Test 3

t.test(hr1$number_project ~ hr1$Employee_Status)
## 
##  Welch Two Sample t-test
## 
## data:  hr1$number_project by hr1$Employee_Status
## t = 2.1663, df = 4236.5, p-value = 0.03034
## alternative hypothesis: true difference in means between group left and group stayed is not equal to 0
## 95 percent confidence interval:
##  0.006540119 0.131136535
## sample estimates:
##   mean in group left mean in group stayed 
##             3.855503             3.786664

Employees that left, on average, work on a greater number of projects than those who stayed.

Employees are more likely to leave if they are assignes a larger number of projects to work on.

plot_ly(hr1 ,
        x= ~Employee_Status ,
        y= ~number_project ,
        type = 'box' ,
        color = ~Employee_Status ,
        colors= c('green', 'purple')
)%>%
  layout(title = 'employees that left, on average, work on a greater number of projects than those who stayed')

#T-Test 4

t.test(hr1\(time_spend_company ~ hr1\)Employee_Status)

Employees that left, on average, experienced higher time spend company than those who statyed

The more time spent overseeing workers the more likely they are to leave.

plot_ly(hr1 ,
        x= ~Employee_Status ,
        y= ~time_spend_company ,
        type = 'box' ,
        color = ~Employee_Status ,
        colors= c('green', 'purple')
)%>%
  layout(title = 'employees that left, on average, expirienced higher time spend company than those who statyed')