R Markdown

Load the packages

library(readr)
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
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

Load the hr dataset

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.

Mutate hr dataset to include Employee Status

hr1 <- hr %>%
  mutate(Employee_Status = ifelse(left == 0 , 'Stayed' , 'Left'))

1. Employee Satisfaction Level vs Employee Status

t.test(hr$satisfaction_level ~ hr1$Employee_Status) 
## 
##  Welch Two Sample t-test
## 
## data:  hr$satisfaction_level by hr1$Employee_Status
## t = -46.636, df = 5167, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
##  -0.2362417 -0.2171815
## sample estimates:
##   mean in group Left mean in group Stayed 
##            0.4400980            0.6668096

Results interpretation: There is a significant difference between means, where employees that stayed are at least 50% more satisfied than employees who left.

Descriptive interpretation: Employees that stay, on average, are at least 50% more satisfied.

plot_ly(hr1 ,  
        x = ~Employee_Status ,
        y = ~satisfaction_level ,
        type = 'box' , 
        color = ~Employee_Status ,
        colors = c('purple' , 'blue')
) %>% 
  layout(title = 'employees that stayed, on average, are at least 50% more satisfied') 

2. Time Spent at the Company vs Employee Status

t.test(hr$time_spend_company ~ hr1$Employee_Status) 
## 
##  Welch Two Sample t-test
## 
## data:  hr$time_spend_company by hr1$Employee_Status
## t = 22.631, df = 9625.6, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
##  0.4534706 0.5394767
## sample estimates:
##   mean in group Left mean in group Stayed 
##             3.876505             3.380032

Results interpretation: There is a significant difference between means, where employees that have left would spend, on average, 13% more hours at the company.

Descriptive interpretation: employees that leave spend, on average, 13% more hours at the company

plot_ly(hr1,  
        x = ~Employee_Status,
        y = ~time_spend_company,
        type = 'box' , 
        color = ~Employee_Status ,
        colors = c('orange' , 'blue')
) %>% 
  layout(title = 'employees that left, on average, spent 13% more hours at company') 

3. Last Evaluation vs Employee Status

t.test(hr$last_evaluation ~ hr1$Employee_Status)
## 
##  Welch Two Sample t-test
## 
## data:  hr$last_evaluation by hr1$Employee_Status
## t = 0.72534, df = 5154.9, p-value = 0.4683
## alternative hypothesis: true difference in means between group Left and group Stayed is not equal to 0
## 95 percent confidence interval:
##  -0.004493874  0.009772224
## sample estimates:
##   mean in group Left mean in group Stayed 
##            0.7181126            0.7154734

Results interpretation: There is no significant difference between means.

Descriptive interpretation: employees that stay and leave, on average, scored similarly on their last evaluation.

plot_ly(hr1 , 
        x = ~Employee_Status ,
        y = ~last_evaluation ,
        type = 'box' , 
        color = ~Employee_Status ,
        colors = c('red' , 'blue')
) %>% 
  layout(title = 'employees that stay and leave, on average, scored similarly on their last evaluation')

4. Number of Employee Projects vs Employee Status

t.test(hr$number_project ~ hr1$Employee_Status)
## 
##  Welch Two Sample t-test
## 
## data:  hr$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

Results interpretation: There is a significant difference between means, where employees that stayed have about 3% more projects than employees who left.

Descriptive interpretation: employees that stay, on average, are at least 50% more satisfied.

plot_ly(hr1 , 
        x = ~Employee_Status ,
        y = ~number_project ,
        type = 'box' , 
        color = ~Employee_Status ,
        colors = c('pink' , 'blue')
) %>% 
  layout(title = 'employees that leave, on average, have 3% more projects')