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(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 signifigant difference between means, where employees
that left at least 6 hours more
Descrptive: 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 who work longer hours
plot_ly(
hr1,
x = ~Employee_Status,
y = ~average_montly_hours,
type = 'box',
color = ~Employee_Status,
colors = c('#1e9b20', 'blue')
) %>%
layout(title = 'employees that left, on average, work more hours, at least 3% more')
Technical interpretation of t-test
The p-value helps determine if the difference in means is
statistically significant.
Here, if the p-value is below a threshold (typically 0.05), it
suggests that the difference in average monthly hours
between employees who stayed and those who left is statistically
significant.