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
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
There is a significant difference between means, where employees
that left work at least 6 hours more.
Descriptive: Employees that left, on average, work more hours, at
least 3% more.
Prescriptive: To reduce employee attrition, average monthly hours
can be reduced by 3%, for those that work longer hours.
plot_ly(hr1 ,
x = ~Employee_Status ,
y = ~average_montly_hours ,
type = 'box' ,
color = ~Employee_Status ,
colors = c('#159430' , 'blue')
)%>%
layout(title = 'Employees that left, on average, work more hours, at least 3% more')
T-Test 2
t.test(hr1$satisfaction_level ~ hr1$Employee_Status)
##
## Welch Two Sample t-test
##
## data: hr1$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
The p-value is extremely small, therefore the difference between
means of satisfaction level by employee status is significant.
Descriptive: Employees that left, on average, are less satisfied, at
least 0.21% less.
Prescriptive: Low satisfaction appears to be associated with a
higher likelihood of leaving the company.
plot_ly(hr1 ,
x = ~Employee_Status ,
y = ~satisfaction_level ,
type = 'box' ,
color = ~Employee_Status ,
colors = c('#159430' , 'blue')
)%>%
layout(title = 'Dissatisfied employees are more likely to leave the company')
T-Test 3
t.test(hr1$last_evaluation ~ hr1$Employee_Status)
##
## Welch Two Sample t-test
##
## data: hr1$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
The p-value is large, meaning there is no statistically significant
difference between means of last evaluation scores by employee
status.
Descriptive: The average evaluation scores of employees who left the
company and those who stayed are very similar.
Prescriptive: Employee evaluation scores do not appear to be linked
with the decision to stay or leave the company.
plot_ly(hr1 ,
x = ~Employee_Status ,
y = ~last_evaluation ,
type = 'box' ,
color = ~Employee_Status ,
colors = c('#159430' , 'blue')
)%>%
layout(title = 'Evaluation scores do not appear to be linked with employee status')
T-Test 4
t.test(hr1$time_spend_company ~ hr1$Employee_Status)
##
## Welch Two Sample t-test
##
## data: hr1$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
The p-value is extremely low meaning the difference between means of
time spent at company by employee status is significant.
Descriptive: On average, employees who left the company had spent
about 0.5 years (or 6 months) more at the company than those who
stayed.
Prescriptive: Longer time spent at the company appears to be
associated with a higher likelihood of leaving the company.
plot_ly(hr1 ,
x = ~Employee_Status ,
y = ~time_spend_company ,
type = 'box' ,
color = ~Employee_Status ,
colors = c('#159430' , 'blue')
)%>%
layout(title = 'Longer time spent at company appears to show higher chance of leaving')